@@ -90,6 +90,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
90
90
@inject ( SelectBoardsDialog )
91
91
protected readonly selectBoardsDialog : SelectBoardsDialog ;
92
92
93
+ protected boardsToolbarItem : BoardsToolBarItem | null ;
94
+
93
95
@postConstruct ( )
94
96
protected async init ( ) : Promise < void > {
95
97
// This is a hack. Otherwise, the backend services won't bind.
@@ -124,15 +126,10 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
124
126
registry . registerItem ( {
125
127
id : ConnectedBoards . TOOLBAR_ID ,
126
128
render : ( ) => < BoardsToolBarItem
129
+ ref = { ref => this . boardsToolbarItem = ref }
127
130
contextMenuRenderer = { this . contextMenuRenderer }
128
- onNoBoardsInstalled = { this . onNoBoardsInstalled . bind ( this ) }
129
- onUnknownBoard = { this . onUnknownBoard . bind ( this ) } /> ,
130
- // render: () => <ConnectedBoards
131
- // boardsService={this.boardService}
132
- // boardsNotificationService={this.boardsNotificationService}
133
- // quickPickService={this.quickPickService}
134
- // onNoBoardsInstalled={this.onNoBoardsInstalled.bind(this)}
135
- // onUnknownBoard={this.onUnknownBoard.bind(this)} />,
131
+ boardsNotificationService = { this . boardsNotificationService }
132
+ boardService = { this . boardService } /> ,
136
133
isVisible : widget => this . isArduinoToolbar ( widget )
137
134
} )
138
135
}
@@ -230,31 +227,37 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
230
227
} ) ;
231
228
registry . registerCommand ( ArduinoCommands . SELECT_BOARD , {
232
229
isEnabled : ( ) => true ,
233
- execute : ( board : Board ) => {
234
- this . boardService . selectBoard ( board ) . then ( ( ) => {
235
- return this . boardService . getSelectBoard ( ) ;
236
- } ) . then ( board => {
237
- console . log ( "and the selected board is" , board ) ;
238
- } )
230
+ execute : async ( board : Board ) => {
231
+ this . selectBoard ( board ) ;
239
232
}
240
233
} )
241
234
registry . registerCommand ( ArduinoCommands . OPEN_BOARDS_DIALOG , {
242
235
isEnabled : ( ) => true ,
243
236
execute : async ( ) => {
244
237
const boardAndPort = await this . selectBoardsDialog . open ( ) ;
245
- if ( boardAndPort && boardAndPort . board ) {
238
+ if ( boardAndPort && boardAndPort . board ) {
246
239
const selectedBoard = {
247
240
fqbn : boardAndPort . board . fqbn ,
248
241
name : boardAndPort . board . name ,
249
242
port : boardAndPort . port
250
243
}
251
- this . boardService . selectBoard ( selectedBoard ) ;
252
-
244
+ this . selectBoard ( selectedBoard ) ;
253
245
}
254
246
}
255
247
} )
256
248
}
257
249
250
+ protected async selectBoard ( board : Board ) {
251
+ const attached = await this . boardService . getAttachedBoards ( ) ;
252
+ if ( attached . boards . length ) {
253
+ board = attached . boards . find ( b => b . name === board . name && b . fqbn === board . fqbn ) || board ;
254
+ }
255
+ await this . boardService . selectBoard ( board )
256
+ if ( this . boardsToolbarItem ) {
257
+ this . boardsToolbarItem . setSelectedBoard ( board ) ;
258
+ }
259
+ }
260
+
258
261
protected async openSketchFilesInNewWindow ( uri : string ) {
259
262
const location = new URL ( window . location . href ) ;
260
263
location . searchParams . set ( 'sketch' , uri ) ;
@@ -309,24 +312,24 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
309
312
return widget ;
310
313
}
311
314
312
- private async onNoBoardsInstalled ( ) {
313
- const action = await this . messageService . info ( "You have no boards installed. Use the boards mangager to install one." , "Open Boards Manager" ) ;
314
- if ( ! action ) {
315
- return ;
316
- }
315
+ // private async onNoBoardsInstalled() {
316
+ // const action = await this.messageService.info("You have no boards installed. Use the boards mangager to install one.", "Open Boards Manager");
317
+ // if (!action) {
318
+ // return;
319
+ // }
317
320
318
- this . boardsListWidgetFrontendContribution . openView ( { reveal : true } ) ;
319
- }
321
+ // this.boardsListWidgetFrontendContribution.openView({ reveal: true });
322
+ // }
320
323
321
- private async onUnknownBoard ( ) {
322
- const action = await this . messageService . warn ( "There's a board connected for which you need to install software." +
323
- " If this were not a PoC we would offer you the right package now." , "Open Boards Manager" ) ;
324
- if ( ! action ) {
325
- return ;
326
- }
324
+ // private async onUnknownBoard() {
325
+ // const action = await this.messageService.warn("There's a board connected for which you need to install software." +
326
+ // " If this were not a PoC we would offer you the right package now.", "Open Boards Manager");
327
+ // if (!action) {
328
+ // return;
329
+ // }
327
330
328
- this . boardsListWidgetFrontendContribution . openView ( { reveal : true } ) ;
329
- }
331
+ // this.boardsListWidgetFrontendContribution.openView({ reveal: true });
332
+ // }
330
333
331
334
private isArduinoToolbar ( maybeToolbarWidget : any ) : boolean {
332
335
if ( maybeToolbarWidget instanceof ArduinoToolbar ) {
0 commit comments