@@ -44,8 +44,8 @@ import {
44
44
isBoardListHistory ,
45
45
SelectBoardsConfigActionParams ,
46
46
} from '../../common/protocol/board-list' ;
47
- import { Defined } from '../../common/types' ;
48
- import {
47
+ import type { Defined } from '../../common/types' ;
48
+ import type {
49
49
StartupTask ,
50
50
StartupTaskProvider ,
51
51
} from '../../electron-common/startup-task' ;
@@ -200,48 +200,6 @@ export class BoardsServiceProvider
200
200
this . boardListDumper ?. dispose ( ) ;
201
201
}
202
202
203
- private async maybeUpdateSelectedBoard ( platformDidInstallEvent : {
204
- item : BoardsPackage ;
205
- } ) : Promise < void > {
206
- const { selectedBoard } = this . _boardsConfig ;
207
- if (
208
- selectedBoard &&
209
- ! selectedBoard . fqbn &&
210
- BoardWithPackage . is ( selectedBoard )
211
- ) {
212
- const selectedBoardPlatformId = serializePlatformIdentifier (
213
- selectedBoard . packageId
214
- ) ;
215
- if ( selectedBoardPlatformId === platformDidInstallEvent . item . id ) {
216
- const installedSelectedBoard = platformDidInstallEvent . item . boards . find (
217
- ( board ) => board . name === selectedBoard . name
218
- ) ;
219
- // if the board can be found by its name after the install event select it. otherwise unselect it
220
- // historical hint: https://github.com/arduino/arduino-ide/blob/144df893d0dafec64a26565cf912a98f32572da9/arduino-ide-extension/src/browser/boards/boards-service-provider.ts#L289-L320
221
- this . updateBoard ( installedSelectedBoard ) ;
222
- if ( ! installedSelectedBoard ) {
223
- const yes = nls . localize ( 'vscode/extensionsUtils/yes' , 'Yes' ) ;
224
- const answer = await this . messageService . warn (
225
- nls . localize (
226
- 'arduino/board/couldNotFindPreviouslySelected' ,
227
- "Could not find previously selected board '{0}' in installed platform '{1}'. Please manually reselect the board you want to use. Do you want to reselect it now?" ,
228
- selectedBoard . name ,
229
- platformDidInstallEvent . item . name
230
- ) ,
231
- nls . localize ( 'arduino/board/reselectLater' , 'Reselect later' ) ,
232
- yes
233
- ) ;
234
- if ( answer === yes ) {
235
- this . onBoardsConfigEdit ( {
236
- query : selectedBoard . name ,
237
- portToSelect : this . _boardsConfig . selectedPort ,
238
- } ) ;
239
- }
240
- }
241
- }
242
- }
243
- }
244
-
245
203
registerCommands ( registry : CommandRegistry ) : void {
246
204
registry . registerCommand ( USE_INHERITED_CONFIG , {
247
205
execute : (
@@ -285,6 +243,48 @@ export class BoardsServiceProvider
285
243
] ;
286
244
}
287
245
246
+ private async maybeUpdateSelectedBoard ( platformDidInstallEvent : {
247
+ item : BoardsPackage ;
248
+ } ) : Promise < void > {
249
+ const { selectedBoard } = this . _boardsConfig ;
250
+ if (
251
+ selectedBoard &&
252
+ ! selectedBoard . fqbn &&
253
+ BoardWithPackage . is ( selectedBoard )
254
+ ) {
255
+ const selectedBoardPlatformId = serializePlatformIdentifier (
256
+ selectedBoard . packageId
257
+ ) ;
258
+ if ( selectedBoardPlatformId === platformDidInstallEvent . item . id ) {
259
+ const installedSelectedBoard = platformDidInstallEvent . item . boards . find (
260
+ ( board ) => board . name === selectedBoard . name
261
+ ) ;
262
+ // if the board can be found by its name after the install event select it. otherwise unselect it
263
+ // historical hint: https://github.com/arduino/arduino-ide/blob/144df893d0dafec64a26565cf912a98f32572da9/arduino-ide-extension/src/browser/boards/boards-service-provider.ts#L289-L320
264
+ this . updateBoard ( installedSelectedBoard ) ;
265
+ if ( ! installedSelectedBoard ) {
266
+ const yes = nls . localize ( 'vscode/extensionsUtils/yes' , 'Yes' ) ;
267
+ const answer = await this . messageService . warn (
268
+ nls . localize (
269
+ 'arduino/board/couldNotFindPreviouslySelected' ,
270
+ "Could not find previously selected board '{0}' in installed platform '{1}'. Please manually reselect the board you want to use. Do you want to reselect it now?" ,
271
+ selectedBoard . name ,
272
+ platformDidInstallEvent . item . name
273
+ ) ,
274
+ nls . localize ( 'arduino/board/reselectLater' , 'Reselect later' ) ,
275
+ yes
276
+ ) ;
277
+ if ( answer === yes ) {
278
+ this . onBoardsConfigEdit ( {
279
+ query : selectedBoard . name ,
280
+ portToSelect : this . _boardsConfig . selectedPort ,
281
+ } ) ;
282
+ }
283
+ }
284
+ }
285
+ }
286
+ }
287
+
288
288
private refreshBoardList ( params ?: RefreshBoardListParams ) : void {
289
289
if ( params ?. detectedPorts ) {
290
290
this . _detectedPorts = params . detectedPorts ;
@@ -344,16 +344,30 @@ export class BoardsServiceProvider
344
344
reason
345
345
) ;
346
346
} else if ( selectedBoard ) {
347
- this . updateBoard ( selectedBoard ) ;
347
+ this . updateConfig ( selectedBoard ) ;
348
348
} else if ( selectedPort ) {
349
- this . updatePort ( selectedPort ) ;
349
+ this . updateConfig ( selectedPort ) ;
350
350
}
351
351
}
352
352
353
353
updateConfig (
354
354
boardsConfig : Defined < BoardsConfig > ,
355
355
reason ?: UpdateBoardsConfigReason
356
+ ) : boolean ;
357
+ updateConfig ( selectedBoard : BoardIdentifier ) : boolean ;
358
+ updateConfig ( selectedPort : PortIdentifier ) : boolean ;
359
+ updateConfig (
360
+ arg : Defined < BoardsConfig > | BoardIdentifier | PortIdentifier ,
361
+ reason ?: UpdateBoardsConfigReason
356
362
) : boolean {
363
+ if ( isBoardIdentifier ( arg ) ) {
364
+ return this . updateBoard ( arg ) ;
365
+ }
366
+ if ( isPortIdentifier ( arg ) ) {
367
+ return this . updatePort ( arg ) ;
368
+ }
369
+
370
+ const boardsConfig = arg ;
357
371
const selectedBoard = boardsConfig . selectedBoard ;
358
372
const previousSelectedBoard = this . _boardsConfig . selectedBoard ;
359
373
const selectedPort = boardsConfig . selectedPort ;
@@ -400,7 +414,9 @@ export class BoardsServiceProvider
400
414
return true ;
401
415
}
402
416
403
- updateBoard ( selectedBoard : BoardIdentifier | undefined ) : boolean {
417
+ // `undefined` is special case when a non installed board is selected (no FQBN), the platform is installed,
418
+ // but there is no way to determine the FQBN from the previous partial data, and IDE2 unsets the board.
419
+ private updateBoard ( selectedBoard : BoardIdentifier | undefined ) : boolean {
404
420
const previousSelectedBoard = this . _boardsConfig . selectedBoard ;
405
421
if ( boardIdentifierEquals ( previousSelectedBoard , selectedBoard ) ) {
406
422
// NOOP if they're the same
@@ -416,7 +432,7 @@ export class BoardsServiceProvider
416
432
return true ;
417
433
}
418
434
419
- updatePort ( selectedPort : PortIdentifier | undefined ) : boolean {
435
+ private updatePort ( selectedPort : PortIdentifier ) : boolean {
420
436
const selectedBoard = this . _boardsConfig . selectedBoard ;
421
437
const previousSelectedPort = this . _boardsConfig . selectedPort ;
422
438
if ( selectedPort && selectedBoard ) {
0 commit comments