@@ -11,12 +11,7 @@ import { Emitter } from '@theia/core/lib/common/event';
11
11
import { ILogger } from '@theia/core/lib/common/logger' ;
12
12
import { nls } from '@theia/core/lib/common/nls' ;
13
13
import 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' ;
20
15
import {
21
16
OutputChannel ,
22
17
OutputChannelManager ,
@@ -159,7 +154,7 @@ export class BoardsServiceProvider
159
154
160
155
private _boardsConfig = emptyBoardsConfig ( ) ;
161
156
private _detectedPorts : DetectedPorts = { } ;
162
- private _boardList : BoardListUI ;
157
+ private _boardList = this . createBoardListUI ( createBoardList ( { } ) ) ;
163
158
private _boardListHistory : Mutable < BoardListHistory > = { } ;
164
159
165
160
private readonly boardsConfigDidChangeEmitter =
@@ -172,12 +167,6 @@ export class BoardsServiceProvider
172
167
*/
173
168
readonly onBoardListDidChange = this . boardListDidChangeEmitter . event ;
174
169
175
- @postConstruct ( )
176
- protected init ( ) : void {
177
- const boardList = createBoardList ( this . _detectedPorts , this . _boardsConfig ) ;
178
- this . _boardList = this . createBoardListUI ( boardList ) ;
179
- }
180
-
181
170
onStart ( ) : void {
182
171
this . notificationCenter . onDetectedPortsDidChange ( ( { detectedPorts } ) =>
183
172
this . refreshBoardList ( { detectedPorts } )
@@ -207,13 +196,15 @@ export class BoardsServiceProvider
207
196
208
197
registerCommands ( registry : CommandRegistry ) : void {
209
198
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
+ } ,
217
208
} ) ;
218
209
if ( this . boardListDumper ) {
219
210
registry . registerCommand ( DUMP_BOARD_LIST , {
@@ -241,7 +232,7 @@ export class BoardsServiceProvider
241
232
return [
242
233
{
243
234
command : USE_INHERITED_CONFIG . id ,
244
- args : [ this . _boardsConfig ] ,
235
+ args : [ this . _boardsConfig , this . _boardListHistory ] ,
245
236
} ,
246
237
] ;
247
238
}
@@ -283,19 +274,19 @@ export class BoardsServiceProvider
283
274
BoardsConfig | undefined
284
275
> ( 'arduino-open-boards-dialog' , params ) ;
285
276
if ( boardsConfig ) {
286
- this . update (
287
- boardsConfig . selectedBoard ,
288
- boardsConfig . selectedPort ,
289
- 'dialog'
290
- ) ;
277
+ this . update ( { boardsConfig } , 'dialog' ) ;
291
278
}
292
279
}
293
280
294
281
private update (
295
- selectedBoard : BoardIdentifier | undefined ,
296
- selectedPort : PortIdentifier | undefined ,
282
+ params : RefreshBoardListParams ,
297
283
reason ?: UpdateBoardsConfigReason
298
284
) : void {
285
+ const { boardsConfig } = params ;
286
+ if ( ! boardsConfig ) {
287
+ return ;
288
+ }
289
+ const { selectedBoard, selectedPort } = boardsConfig ;
299
290
if ( selectedBoard && selectedPort ) {
300
291
this . updateConfig (
301
292
{
@@ -441,6 +432,7 @@ export class BoardsServiceProvider
441
432
442
433
private async saveState ( ) : Promise < void > {
443
434
const { selectedBoard, selectedPort } = this . boardsConfig ;
435
+ debugger ;
444
436
await Promise . all ( [
445
437
this . setData (
446
438
selectedBoardStorageKey ,
@@ -470,7 +462,7 @@ export class BoardsServiceProvider
470
462
}
471
463
472
464
private async restoreState ( ) : Promise <
473
- Readonly < BoardsConfig > & { boardListHistory : BoardListHistory }
465
+ Readonly < BoardsConfig > & { boardListHistory : BoardListHistory | undefined }
474
466
> {
475
467
const [ maybeSelectedBoard , maybeSelectedPort , maybeBoardHistory ] =
476
468
await Promise . all ( [
@@ -480,8 +472,11 @@ export class BoardsServiceProvider
480
472
] ) ;
481
473
const selectedBoard = this . tryParse ( maybeSelectedBoard , isBoardIdentifier ) ;
482
474
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 ;
485
480
return { selectedBoard, selectedPort, boardListHistory } ;
486
481
}
487
482
0 commit comments