@@ -11,12 +11,7 @@ import { Emitter } from '@theia/core/lib/common/event';
1111import { ILogger } from '@theia/core/lib/common/logger' ;
1212import { nls } from '@theia/core/lib/common/nls' ;
1313import type { Mutable } from '@theia/core/lib/common/types' ;
14- import {
15- inject ,
16- injectable ,
17- optional ,
18- postConstruct ,
19- } from '@theia/core/shared/inversify' ;
14+ import { inject , injectable , optional } from '@theia/core/shared/inversify' ;
2015import {
2116 OutputChannel ,
2217 OutputChannelManager ,
@@ -159,7 +154,7 @@ export class BoardsServiceProvider
159154
160155 private _boardsConfig = emptyBoardsConfig ( ) ;
161156 private _detectedPorts : DetectedPorts = { } ;
162- private _boardList : BoardListUI ;
157+ private _boardList = this . createBoardListUI ( createBoardList ( { } ) ) ;
163158 private _boardListHistory : Mutable < BoardListHistory > = { } ;
164159
165160 private readonly boardsConfigDidChangeEmitter =
@@ -172,12 +167,6 @@ export class BoardsServiceProvider
172167 */
173168 readonly onBoardListDidChange = this . boardListDidChangeEmitter . event ;
174169
175- @postConstruct ( )
176- protected init ( ) : void {
177- const boardList = createBoardList ( this . _detectedPorts , this . _boardsConfig ) ;
178- this . _boardList = this . createBoardListUI ( boardList ) ;
179- }
180-
181170 onStart ( ) : void {
182171 this . notificationCenter . onDetectedPortsDidChange ( ( { detectedPorts } ) =>
183172 this . refreshBoardList ( { detectedPorts } )
@@ -207,13 +196,15 @@ export class BoardsServiceProvider
207196
208197 registerCommands ( registry : CommandRegistry ) : void {
209198 registry . registerCommand ( USE_INHERITED_CONFIG , {
210- execute : ( boardsConfig : BoardsConfig ) =>
211- // TODO: inherit board config if stored per sketch?
212- this . update (
213- boardsConfig . selectedBoard ,
214- boardsConfig . selectedPort ,
215- 'inherit'
216- ) ,
199+ execute : (
200+ boardsConfig : BoardsConfig ,
201+ boardListHistory : BoardListHistory
202+ ) => {
203+ if ( boardListHistory ) {
204+ this . _boardListHistory = boardListHistory ;
205+ }
206+ this . update ( { boardsConfig } , 'inherit' ) ;
207+ } ,
217208 } ) ;
218209 if ( this . boardListDumper ) {
219210 registry . registerCommand ( DUMP_BOARD_LIST , {
@@ -241,7 +232,7 @@ export class BoardsServiceProvider
241232 return [
242233 {
243234 command : USE_INHERITED_CONFIG . id ,
244- args : [ this . _boardsConfig ] ,
235+ args : [ this . _boardsConfig , this . _boardListHistory ] ,
245236 } ,
246237 ] ;
247238 }
@@ -283,19 +274,19 @@ export class BoardsServiceProvider
283274 BoardsConfig | undefined
284275 > ( 'arduino-open-boards-dialog' , params ) ;
285276 if ( boardsConfig ) {
286- this . update (
287- boardsConfig . selectedBoard ,
288- boardsConfig . selectedPort ,
289- 'dialog'
290- ) ;
277+ this . update ( { boardsConfig } , 'dialog' ) ;
291278 }
292279 }
293280
294281 private update (
295- selectedBoard : BoardIdentifier | undefined ,
296- selectedPort : PortIdentifier | undefined ,
282+ params : RefreshBoardListParams ,
297283 reason ?: UpdateBoardsConfigReason
298284 ) : void {
285+ const { boardsConfig } = params ;
286+ if ( ! boardsConfig ) {
287+ return ;
288+ }
289+ const { selectedBoard, selectedPort } = boardsConfig ;
299290 if ( selectedBoard && selectedPort ) {
300291 this . updateConfig (
301292 {
@@ -441,6 +432,7 @@ export class BoardsServiceProvider
441432
442433 private async saveState ( ) : Promise < void > {
443434 const { selectedBoard, selectedPort } = this . boardsConfig ;
435+ debugger ;
444436 await Promise . all ( [
445437 this . setData (
446438 selectedBoardStorageKey ,
@@ -470,7 +462,7 @@ export class BoardsServiceProvider
470462 }
471463
472464 private async restoreState ( ) : Promise <
473- Readonly < BoardsConfig > & { boardListHistory : BoardListHistory }
465+ Readonly < BoardsConfig > & { boardListHistory : BoardListHistory | undefined }
474466 > {
475467 const [ maybeSelectedBoard , maybeSelectedPort , maybeBoardHistory ] =
476468 await Promise . all ( [
@@ -480,8 +472,11 @@ export class BoardsServiceProvider
480472 ] ) ;
481473 const selectedBoard = this . tryParse ( maybeSelectedBoard , isBoardIdentifier ) ;
482474 const selectedPort = this . tryParse ( maybeSelectedPort , isPortIdentifier ) ;
483- const boardListHistory =
484- this . tryParse ( maybeBoardHistory , isBoardListHistory ) ?? { } ;
475+ const boardListHistory = this . tryParse (
476+ maybeBoardHistory ,
477+ isBoardListHistory
478+ ) ;
479+ debugger ;
485480 return { selectedBoard, selectedPort, boardListHistory } ;
486481 }
487482
0 commit comments