1
1
import { injectable , inject , named } from 'inversify' ;
2
2
import { ILogger } from '@theia/core/lib/common/logger' ;
3
3
import { deepClone } from '@theia/core/lib/common/objects' ;
4
- import { MaybePromise } from '@theia/core/lib/common/types' ;
5
4
import { Event , Emitter } from '@theia/core/lib/common/event' ;
6
5
import {
7
6
FrontendApplicationContribution ,
@@ -11,7 +10,6 @@ import { notEmpty } from '../../common/utils';
11
10
import {
12
11
BoardsService ,
13
12
ConfigOption ,
14
- Installable ,
15
13
BoardDetails ,
16
14
Programmer ,
17
15
} from '../../common/protocol' ;
@@ -36,16 +34,12 @@ export class BoardsDataStore implements FrontendApplicationContribution {
36
34
37
35
onStart ( ) : void {
38
36
this . notificationCenter . onPlatformInstalled ( async ( { item } ) => {
39
- const { installedVersion : version } = item ;
40
- if ( ! version ) {
41
- return ;
42
- }
43
37
let shouldFireChanged = false ;
44
38
for ( const fqbn of item . boards
45
39
. map ( ( { fqbn } ) => fqbn )
46
40
. filter ( notEmpty )
47
41
. filter ( ( fqbn ) => ! ! fqbn ) ) {
48
- const key = this . getStorageKey ( fqbn , version ) ;
42
+ const key = this . getStorageKey ( fqbn ) ;
49
43
let data = await this . storageService . getData <
50
44
ConfigOption [ ] | undefined
51
45
> ( key ) ;
@@ -72,33 +66,20 @@ export class BoardsDataStore implements FrontendApplicationContribution {
72
66
73
67
async appendConfigToFqbn (
74
68
fqbn : string | undefined ,
75
- boardsPackageVersion : MaybePromise <
76
- Installable . Version | undefined
77
- > = this . getBoardsPackageVersion ( fqbn )
78
69
) : Promise < string | undefined > {
79
70
if ( ! fqbn ) {
80
71
return undefined ;
81
72
}
82
-
83
- const { configOptions } = await this . getData ( fqbn , boardsPackageVersion ) ;
73
+ const { configOptions } = await this . getData ( fqbn ) ;
84
74
return ConfigOption . decorate ( fqbn , configOptions ) ;
85
75
}
86
76
87
- async getData (
88
- fqbn : string | undefined ,
89
- boardsPackageVersion : MaybePromise <
90
- Installable . Version | undefined
91
- > = this . getBoardsPackageVersion ( fqbn )
92
- ) : Promise < BoardsDataStore . Data > {
77
+ async getData ( fqbn : string | undefined ) : Promise < BoardsDataStore . Data > {
93
78
if ( ! fqbn ) {
94
79
return BoardsDataStore . Data . EMPTY ;
95
80
}
96
81
97
- const version = await boardsPackageVersion ;
98
- if ( ! version ) {
99
- return BoardsDataStore . Data . EMPTY ;
100
- }
101
- const key = this . getStorageKey ( fqbn , version ) ;
82
+ const key = this . getStorageKey ( fqbn ) ;
102
83
let data = await this . storageService . getData <
103
84
BoardsDataStore . Data | undefined
104
85
> ( key , undefined ) ;
@@ -124,25 +105,16 @@ export class BoardsDataStore implements FrontendApplicationContribution {
124
105
fqbn,
125
106
selectedProgrammer,
126
107
} : { fqbn : string ; selectedProgrammer : Programmer } ,
127
- boardsPackageVersion : MaybePromise <
128
- Installable . Version | undefined
129
- > = this . getBoardsPackageVersion ( fqbn )
130
108
) : Promise < boolean > {
131
- const data = deepClone ( await this . getData ( fqbn , boardsPackageVersion ) ) ;
109
+ const data = deepClone ( await this . getData ( fqbn ) ) ;
132
110
const { programmers } = data ;
133
111
if ( ! programmers . find ( ( p ) => Programmer . equals ( selectedProgrammer , p ) ) ) {
134
112
return false ;
135
113
}
136
114
137
- const version = await boardsPackageVersion ;
138
- if ( ! version ) {
139
- return false ;
140
- }
141
-
142
115
await this . setData ( {
143
116
fqbn,
144
117
data : { ...data , selectedProgrammer } ,
145
- version,
146
118
} ) ;
147
119
this . fireChanged ( ) ;
148
120
return true ;
@@ -153,12 +125,9 @@ export class BoardsDataStore implements FrontendApplicationContribution {
153
125
fqbn,
154
126
option,
155
127
selectedValue,
156
- } : { fqbn : string ; option : string ; selectedValue : string } ,
157
- boardsPackageVersion : MaybePromise <
158
- Installable . Version | undefined
159
- > = this . getBoardsPackageVersion ( fqbn )
128
+ } : { fqbn : string ; option : string ; selectedValue : string }
160
129
) : Promise < boolean > {
161
- const data = deepClone ( await this . getData ( fqbn , boardsPackageVersion ) ) ;
130
+ const data = deepClone ( await this . getData ( fqbn ) ) ;
162
131
const { configOptions } = data ;
163
132
const configOption = configOptions . find ( ( c ) => c . option === option ) ;
164
133
if ( ! configOption ) {
@@ -176,31 +145,24 @@ export class BoardsDataStore implements FrontendApplicationContribution {
176
145
if ( ! updated ) {
177
146
return false ;
178
147
}
179
- const version = await boardsPackageVersion ;
180
- if ( ! version ) {
181
- return false ;
182
- }
183
-
184
- await this . setData ( { fqbn, data, version } ) ;
148
+ await this . setData ( { fqbn, data } ) ;
185
149
this . fireChanged ( ) ;
186
150
return true ;
187
151
}
188
152
189
153
protected async setData ( {
190
154
fqbn,
191
155
data,
192
- version,
193
156
} : {
194
157
fqbn : string ;
195
158
data : BoardsDataStore . Data ;
196
- version : Installable . Version ;
197
159
} ) : Promise < void > {
198
- const key = this . getStorageKey ( fqbn , version ) ;
160
+ const key = this . getStorageKey ( fqbn ) ;
199
161
return this . storageService . setData ( key , data ) ;
200
162
}
201
163
202
- protected getStorageKey ( fqbn : string , version : Installable . Version ) : string {
203
- return `.arduinoIDE-configOptions-${ version } - ${ fqbn } ` ;
164
+ protected getStorageKey ( fqbn : string ) : string {
165
+ return `.arduinoIDE-configOptions-${ fqbn } ` ;
204
166
}
205
167
206
168
protected async getBoardDetailsSafe (
@@ -231,21 +193,6 @@ export class BoardsDataStore implements FrontendApplicationContribution {
231
193
protected fireChanged ( ) : void {
232
194
this . onChangedEmitter . fire ( ) ;
233
195
}
234
-
235
- protected async getBoardsPackageVersion (
236
- fqbn : string | undefined
237
- ) : Promise < Installable . Version | undefined > {
238
- if ( ! fqbn ) {
239
- return undefined ;
240
- }
241
- const boardsPackage = await this . boardsService . getContainerBoardPackage ( {
242
- fqbn,
243
- } ) ;
244
- if ( ! boardsPackage ) {
245
- return undefined ;
246
- }
247
- return boardsPackage . installedVersion ;
248
- }
249
196
}
250
197
251
198
export namespace BoardsDataStore {
0 commit comments