@@ -4,12 +4,15 @@ import { DisposableCollection } from '@theia/core/lib/common/disposable';
4
4
import { Emitter , Event } from '@theia/core/lib/common/event' ;
5
5
import { ILogger } from '@theia/core/lib/common/logger' ;
6
6
import { deepClone } from '@theia/core/lib/common/objects' ;
7
+ import type { Mutable } from '@theia/core/lib/common/types' ;
7
8
import { inject , injectable , named } from '@theia/core/shared/inversify' ;
8
9
import {
9
10
BoardDetails ,
10
11
BoardsService ,
11
12
ConfigOption ,
13
+ ConfigValue ,
12
14
Programmer ,
15
+ isProgrammer ,
13
16
} from '../../common/protocol' ;
14
17
import { notEmpty } from '../../common/utils' ;
15
18
import { NotificationCenter } from '../notification-center' ;
@@ -43,7 +46,7 @@ export class BoardsDataStore implements FrontendApplicationContribution {
43
46
const key = this . getStorageKey ( fqbn ) ;
44
47
let data = await this . storageService . getData < ConfigOption [ ] > ( key ) ;
45
48
if ( ! data || ! data . length ) {
46
- const details = await this . getBoardDetailsSafe ( fqbn ) ;
49
+ const details = await this . loadBoardDetails ( fqbn ) ;
47
50
if ( details ) {
48
51
data = details . configOptions ;
49
52
if ( data . length ) {
@@ -91,14 +94,15 @@ export class BoardsDataStore implements FrontendApplicationContribution {
91
94
return data ;
92
95
}
93
96
94
- const boardDetails = await this . getBoardDetailsSafe ( fqbn ) ;
97
+ const boardDetails = await this . loadBoardDetails ( fqbn ) ;
95
98
if ( ! boardDetails ) {
96
99
return BoardsDataStore . Data . EMPTY ;
97
100
}
98
101
99
102
data = {
100
103
configOptions : boardDetails . configOptions ,
101
104
programmers : boardDetails . programmers ,
105
+ selectedProgrammer : boardDetails . programmers . find ( ( p ) => p . default ) ,
102
106
} ;
103
107
await this . storageService . setData ( key , data ) ;
104
108
return data ;
@@ -142,11 +146,12 @@ export class BoardsDataStore implements FrontendApplicationContribution {
142
146
}
143
147
let updated = false ;
144
148
for ( const value of configOption . values ) {
145
- if ( value . value === selectedValue ) {
146
- ( value as any ) . selected = true ;
149
+ const mutable : Mutable < ConfigValue > = value ;
150
+ if ( mutable . value === selectedValue ) {
151
+ mutable . selected = true ;
147
152
updated = true ;
148
153
} else {
149
- ( value as any ) . selected = false ;
154
+ mutable . selected = false ;
150
155
}
151
156
}
152
157
if ( ! updated ) {
@@ -172,9 +177,7 @@ export class BoardsDataStore implements FrontendApplicationContribution {
172
177
return `.arduinoIDE-configOptions-${ fqbn } ` ;
173
178
}
174
179
175
- protected async getBoardDetailsSafe (
176
- fqbn : string
177
- ) : Promise < BoardDetails | undefined > {
180
+ async loadBoardDetails ( fqbn : string ) : Promise < BoardDetails | undefined > {
178
181
try {
179
182
const details = this . boardsService . getBoardDetails ( { fqbn } ) ;
180
183
return details ;
@@ -213,14 +216,23 @@ export namespace BoardsDataStore {
213
216
configOptions : [ ] ,
214
217
programmers : [ ] ,
215
218
} ;
216
- export function is ( arg : any ) : arg is Data {
219
+ export function is ( arg : unknown ) : arg is Data {
217
220
return (
218
- ! ! arg &&
219
- 'configOptions' in arg &&
220
- Array . isArray ( arg [ 'configOptions' ] ) &&
221
- 'programmers' in arg &&
222
- Array . isArray ( arg [ 'programmers' ] )
221
+ typeof arg === 'object' &&
222
+ arg !== null &&
223
+ Array . isArray ( ( < Data > arg ) . configOptions ) &&
224
+ Array . isArray ( ( < Data > arg ) . programmers ) &&
225
+ ( ( < Data > arg ) . selectedProgrammer === undefined ||
226
+ isProgrammer ( ( < Data > arg ) . selectedProgrammer ) )
223
227
) ;
224
228
}
225
229
}
226
230
}
231
+
232
+ export function isEmptyData ( data : BoardsDataStore . Data ) : boolean {
233
+ return (
234
+ Boolean ( ! data . configOptions . length ) &&
235
+ Boolean ( ! data . programmers . length ) &&
236
+ Boolean ( ! data . selectedProgrammer )
237
+ ) ;
238
+ }
0 commit comments