feat: upload using programmer by default if board requires it

This commit is contained in:
Giacomo Cusinato 2024-09-06 01:53:34 +02:00
parent 2de8bd1717
commit a5bf56ffa6
3 changed files with 48 additions and 3 deletions

View File

@ -127,6 +127,7 @@ export class UploadSketch extends CoreServiceContribution {
usingProgrammer, usingProgrammer,
verifyOptions verifyOptions
); );
if (!uploadOptions) { if (!uploadOptions) {
return; return;
} }
@ -137,11 +138,37 @@ export class UploadSketch extends CoreServiceContribution {
const uploadResponse = await this.doWithProgress({ const uploadResponse = await this.doWithProgress({
progressText: nls.localize('arduino/sketch/uploading', 'Uploading...'), progressText: nls.localize('arduino/sketch/uploading', 'Uploading...'),
task: (progressId, coreService, token) => task: async (progressId, coreService, token) => {
coreService.upload({ ...uploadOptions, progressId }, token), try {
return await coreService.upload(
{ ...uploadOptions, progressId },
token
);
} catch (err) {
if (err.code === 4005) {
const uploadWithProgrammerOptions = await this.uploadOptions(
true,
verifyOptions
);
if (uploadWithProgrammerOptions) {
return coreService.upload(
{ ...uploadWithProgrammerOptions, progressId },
token
);
}
} else {
throw err;
}
}
},
keepOutput: true, keepOutput: true,
cancelable: true, cancelable: true,
}); });
if (!uploadResponse) {
return;
}
// the port update is NOOP if nothing has changed // the port update is NOOP if nothing has changed
this.boardsServiceProvider.updateConfig(uploadResponse.portAfterUpload); this.boardsServiceProvider.updateConfig(uploadResponse.portAfterUpload);

View File

@ -71,6 +71,7 @@ export namespace CoreError {
Upload: 4002, Upload: 4002,
UploadUsingProgrammer: 4003, UploadUsingProgrammer: 4003,
BurnBootloader: 4004, BurnBootloader: 4004,
UploadRequiresProgrammer: 4005,
}; };
export const VerifyFailed = declareCoreError(Codes.Verify); export const VerifyFailed = declareCoreError(Codes.Verify);
export const UploadFailed = declareCoreError(Codes.Upload); export const UploadFailed = declareCoreError(Codes.Upload);
@ -78,6 +79,10 @@ export namespace CoreError {
Codes.UploadUsingProgrammer Codes.UploadUsingProgrammer
); );
export const BurnBootloaderFailed = declareCoreError(Codes.BurnBootloader); export const BurnBootloaderFailed = declareCoreError(Codes.BurnBootloader);
export const UploadRequiresProgrammer = declareCoreError(
Codes.UploadRequiresProgrammer
);
export function is( export function is(
error: unknown error: unknown
): error is ApplicationError<number, ErrorLocation[]> { ): error is ApplicationError<number, ErrorLocation[]> {

View File

@ -1,4 +1,4 @@
import type { ClientReadableStream } from '@grpc/grpc-js'; import { type ClientReadableStream } from '@grpc/grpc-js';
import { ApplicationError } from '@theia/core/lib/common/application-error'; import { ApplicationError } from '@theia/core/lib/common/application-error';
import type { CancellationToken } from '@theia/core/lib/common/cancellation'; import type { CancellationToken } from '@theia/core/lib/common/cancellation';
import { CommandService } from '@theia/core/lib/common/command'; import { CommandService } from '@theia/core/lib/common/command';
@ -41,6 +41,7 @@ import { Port as RpcPort } from './cli-protocol/cc/arduino/cli/commands/v1/port_
import { import {
BurnBootloaderRequest, BurnBootloaderRequest,
BurnBootloaderResponse, BurnBootloaderResponse,
ProgrammerIsRequiredForUploadError,
UploadRequest, UploadRequest,
UploadResponse, UploadResponse,
UploadUsingProgrammerRequest, UploadUsingProgrammerRequest,
@ -295,12 +296,24 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
reject(UserAbortApplicationError()); reject(UserAbortApplicationError());
return; return;
} }
if (
ServiceError.isInstanceOf(
error,
ProgrammerIsRequiredForUploadError
)
) {
reject(CoreError.UploadRequiresProgrammer());
return;
}
const message = nls.localize( const message = nls.localize(
'arduino/upload/error', 'arduino/upload/error',
'{0} error: {1}', '{0} error: {1}',
firstToUpperCase(task), firstToUpperCase(task),
error.details error.details
); );
this.sendResponse(error.details, OutputMessage.Severity.Error); this.sendResponse(error.details, OutputMessage.Severity.Error);
reject( reject(
errorCtor( errorCtor(