Skip to content

Commit a5bf56f

Browse files
feat: upload using programmer by default if board requires it
1 parent 2de8bd1 commit a5bf56f

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

arduino-ide-extension/src/browser/contributions/upload-sketch.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export class UploadSketch extends CoreServiceContribution {
127127
usingProgrammer,
128128
verifyOptions
129129
);
130+
130131
if (!uploadOptions) {
131132
return;
132133
}
@@ -137,11 +138,37 @@ export class UploadSketch extends CoreServiceContribution {
137138

138139
const uploadResponse = await this.doWithProgress({
139140
progressText: nls.localize('arduino/sketch/uploading', 'Uploading...'),
140-
task: (progressId, coreService, token) =>
141-
coreService.upload({ ...uploadOptions, progressId }, token),
141+
task: async (progressId, coreService, token) => {
142+
try {
143+
return await coreService.upload(
144+
{ ...uploadOptions, progressId },
145+
token
146+
);
147+
} catch (err) {
148+
if (err.code === 4005) {
149+
const uploadWithProgrammerOptions = await this.uploadOptions(
150+
true,
151+
verifyOptions
152+
);
153+
if (uploadWithProgrammerOptions) {
154+
return coreService.upload(
155+
{ ...uploadWithProgrammerOptions, progressId },
156+
token
157+
);
158+
}
159+
} else {
160+
throw err;
161+
}
162+
}
163+
},
142164
keepOutput: true,
143165
cancelable: true,
144166
});
167+
168+
if (!uploadResponse) {
169+
return;
170+
}
171+
145172
// the port update is NOOP if nothing has changed
146173
this.boardsServiceProvider.updateConfig(uploadResponse.portAfterUpload);
147174

arduino-ide-extension/src/common/protocol/core-service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,18 @@ export namespace CoreError {
7171
Upload: 4002,
7272
UploadUsingProgrammer: 4003,
7373
BurnBootloader: 4004,
74+
UploadRequiresProgrammer: 4005,
7475
};
7576
export const VerifyFailed = declareCoreError(Codes.Verify);
7677
export const UploadFailed = declareCoreError(Codes.Upload);
7778
export const UploadUsingProgrammerFailed = declareCoreError(
7879
Codes.UploadUsingProgrammer
7980
);
8081
export const BurnBootloaderFailed = declareCoreError(Codes.BurnBootloader);
82+
export const UploadRequiresProgrammer = declareCoreError(
83+
Codes.UploadRequiresProgrammer
84+
);
85+
8186
export function is(
8287
error: unknown
8388
): error is ApplicationError<number, ErrorLocation[]> {

arduino-ide-extension/src/node/core-service-impl.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ClientReadableStream } from '@grpc/grpc-js';
1+
import { type ClientReadableStream } from '@grpc/grpc-js';
22
import { ApplicationError } from '@theia/core/lib/common/application-error';
33
import type { CancellationToken } from '@theia/core/lib/common/cancellation';
44
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_
4141
import {
4242
BurnBootloaderRequest,
4343
BurnBootloaderResponse,
44+
ProgrammerIsRequiredForUploadError,
4445
UploadRequest,
4546
UploadResponse,
4647
UploadUsingProgrammerRequest,
@@ -295,12 +296,24 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
295296
reject(UserAbortApplicationError());
296297
return;
297298
}
299+
300+
if (
301+
ServiceError.isInstanceOf(
302+
error,
303+
ProgrammerIsRequiredForUploadError
304+
)
305+
) {
306+
reject(CoreError.UploadRequiresProgrammer());
307+
return;
308+
}
309+
298310
const message = nls.localize(
299311
'arduino/upload/error',
300312
'{0} error: {1}',
301313
firstToUpperCase(task),
302314
error.details
303315
);
316+
304317
this.sendResponse(error.details, OutputMessage.Severity.Error);
305318
reject(
306319
errorCtor(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy