Skip to content

Commit

Permalink
feat: upload using programmer by default if board requires it
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocusinato committed Sep 9, 2024
1 parent beabb80 commit 3f325e0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
31 changes: 29 additions & 2 deletions arduino-ide-extension/src/browser/contributions/upload-sketch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class UploadSketch extends CoreServiceContribution {
usingProgrammer,
verifyOptions
);

if (!uploadOptions) {
return;
}
Expand All @@ -137,11 +138,37 @@ export class UploadSketch extends CoreServiceContribution {

const uploadResponse = await this.doWithProgress({
progressText: nls.localize('arduino/sketch/uploading', 'Uploading...'),
task: (progressId, coreService, token) =>
coreService.upload({ ...uploadOptions, progressId }, token),
task: async (progressId, coreService, 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,
cancelable: true,
});

if (!uploadResponse) {
return;
}

// the port update is NOOP if nothing has changed
this.boardsServiceProvider.updateConfig(uploadResponse.portAfterUpload);

Expand Down
5 changes: 5 additions & 0 deletions arduino-ide-extension/src/common/protocol/core-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ export namespace CoreError {
Upload: 4002,
UploadUsingProgrammer: 4003,
BurnBootloader: 4004,
UploadRequiresProgrammer: 4005,
};
export const VerifyFailed = declareCoreError(Codes.Verify);
export const UploadFailed = declareCoreError(Codes.Upload);
export const UploadUsingProgrammerFailed = declareCoreError(
Codes.UploadUsingProgrammer
);
export const BurnBootloaderFailed = declareCoreError(Codes.BurnBootloader);
export const UploadRequiresProgrammer = declareCoreError(
Codes.UploadRequiresProgrammer
);

export function is(
error: unknown
): error is ApplicationError<number, ErrorLocation[]> {
Expand Down
15 changes: 14 additions & 1 deletion arduino-ide-extension/src/node/core-service-impl.ts
Original file line number Diff line number Diff line change
@@ -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 type { CancellationToken } from '@theia/core/lib/common/cancellation';
import { CommandService } from '@theia/core/lib/common/command';
Expand Down Expand Up @@ -41,6 +41,7 @@ import { Port as RpcPort } from './cli-protocol/cc/arduino/cli/commands/v1/port_
import {
BurnBootloaderRequest,
BurnBootloaderResponse,
ProgrammerIsRequiredForUploadError,
UploadRequest,
UploadResponse,
UploadUsingProgrammerRequest,
Expand Down Expand Up @@ -295,12 +296,24 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
reject(UserAbortApplicationError());
return;
}

if (
ServiceError.isInstanceOf(
error,
ProgrammerIsRequiredForUploadError
)
) {
reject(CoreError.UploadRequiresProgrammer());
return;
}

const message = nls.localize(
'arduino/upload/error',
'{0} error: {1}',
firstToUpperCase(task),
error.details
);

this.sendResponse(error.details, OutputMessage.Severity.Error);
reject(
errorCtor(
Expand Down

0 comments on commit 3f325e0

Please sign in to comment.