@@ -25,6 +25,7 @@ export class UploadSketch extends CoreServiceContribution {
25
25
private readonly userFieldsDialog : UserFieldsDialog ;
26
26
27
27
private boardRequiresUserFields = false ;
28
+ private userFieldsSet = false ;
28
29
private readonly cachedUserFields : Map < string , BoardUserField [ ] > = new Map ( ) ;
29
30
private readonly menuActionsDisposables = new DisposableCollection ( ) ;
30
31
@@ -61,20 +62,22 @@ export class UploadSketch extends CoreServiceContribution {
61
62
registry . registerCommand ( UploadSketch . Commands . UPLOAD_SKETCH , {
62
63
execute : async ( ) => {
63
64
const key = this . selectedFqbnAddress ( ) ;
65
+ /*
66
+ If the board requires to be configured with user fields, we want
67
+ to show the user fields dialog, but if they weren't already
68
+ filled in or if they were filled in, but the previous upload failed.
69
+ */
64
70
if (
65
71
this . boardRequiresUserFields &&
66
72
key &&
67
- ! this . cachedUserFields . has ( key )
73
+ ( ! this . cachedUserFields . has ( key ) || ! this . userFieldsSet )
68
74
) {
69
- // Deep clone the array of board fields to avoid editing the cached ones
70
- this . userFieldsDialog . value = (
71
- await this . boardsServiceProvider . selectedBoardUserFields ( )
72
- ) . map ( ( f ) => ( { ...f } ) ) ;
73
- const result = await this . userFieldsDialog . open ( ) ;
74
- if ( ! result ) {
75
+ const userFieldsFilledIn = Boolean (
76
+ await this . showUserFieldsDialog ( key )
77
+ ) ;
78
+ if ( ! userFieldsFilledIn ) {
75
79
return ;
76
80
}
77
- this . cachedUserFields . set ( key , result ) ;
78
81
}
79
82
this . uploadSketch ( ) ;
80
83
} ,
@@ -86,18 +89,12 @@ export class UploadSketch extends CoreServiceContribution {
86
89
if ( ! key ) {
87
90
return ;
88
91
}
89
-
90
- const cached = this . cachedUserFields . get ( key ) ;
91
- // Deep clone the array of board fields to avoid editing the cached ones
92
- this . userFieldsDialog . value = (
93
- cached ?? ( await this . boardsServiceProvider . selectedBoardUserFields ( ) )
94
- ) . map ( ( f ) => ( { ...f } ) ) ;
95
-
96
- const result = await this . userFieldsDialog . open ( ) ;
97
- if ( ! result ) {
92
+ const userFieldsFilledIn = Boolean (
93
+ await this . showUserFieldsDialog ( key )
94
+ ) ;
95
+ if ( ! userFieldsFilledIn ) {
98
96
return ;
99
97
}
100
- this . cachedUserFields . set ( key , result ) ;
101
98
this . uploadSketch ( ) ;
102
99
} ,
103
100
isEnabled : ( ) => ! this . uploadInProgress && this . boardRequiresUserFields ,
@@ -215,19 +212,20 @@ export class UploadSketch extends CoreServiceContribution {
215
212
return ;
216
213
}
217
214
218
- // TODO: This does not belong here.
219
- // IDE2 should not do any preliminary checks but let the CLI fail and then toast a user consumable error message.
220
- if (
221
- uploadOptions . userFields . length === 0 &&
222
- this . boardRequiresUserFields
223
- ) {
224
- this . messageService . error (
225
- nls . localize (
226
- 'arduino/sketch/userFieldsNotFoundError' ,
227
- "Can't find user fields for connected board"
228
- )
229
- ) ;
230
- return ;
215
+ if ( this . boardRequiresUserFields ) {
216
+ // TODO: This does not belong here.
217
+ // IDE2 should not do any preliminary checks but let the CLI fail and then toast a user consumable error message.
218
+ if ( uploadOptions . userFields . length === 0 ) {
219
+ this . messageService . error (
220
+ nls . localize (
221
+ 'arduino/sketch/userFieldsNotFoundError' ,
222
+ "Can't find user fields for connected board"
223
+ )
224
+ ) ;
225
+ this . userFieldsSet = false ;
226
+ return ;
227
+ }
228
+ this . userFieldsSet = true ;
231
229
}
232
230
233
231
await this . doWithProgress ( {
@@ -242,6 +240,13 @@ export class UploadSketch extends CoreServiceContribution {
242
240
{ timeout : 3000 }
243
241
) ;
244
242
} catch ( e ) {
243
+ if (
244
+ this . boardRequiresUserFields &&
245
+ typeof e . message === 'string' &&
246
+ e . message . startsWith ( 'Upload error:' )
247
+ ) {
248
+ this . userFieldsSet = false ;
249
+ }
245
250
this . handleError ( e ) ;
246
251
} finally {
247
252
this . uploadInProgress = false ;
@@ -317,6 +322,23 @@ export class UploadSketch extends CoreServiceContribution {
317
322
const [ vendor , arch , id ] = fqbn . split ( ':' ) ;
318
323
return `${ vendor } :${ arch } :${ id } ` ;
319
324
}
325
+
326
+ private async showUserFieldsDialog (
327
+ key : string
328
+ ) : Promise < BoardUserField [ ] | undefined > {
329
+ const cached = this . cachedUserFields . get ( key ) ;
330
+ // Deep clone the array of board fields to avoid editing the cached ones
331
+ this . userFieldsDialog . value = (
332
+ cached ?? ( await this . boardsServiceProvider . selectedBoardUserFields ( ) )
333
+ ) . map ( ( f ) => ( { ...f } ) ) ;
334
+ const result = await this . userFieldsDialog . open ( ) ;
335
+ if ( ! result ) {
336
+ return ;
337
+ }
338
+ this . userFieldsSet = true ;
339
+ this . cachedUserFields . set ( key , result ) ;
340
+ return result ;
341
+ }
320
342
}
321
343
322
344
export namespace UploadSketch {
0 commit comments