@@ -16,7 +16,7 @@ import {
16
16
} from '../common/protocol' ;
17
17
import { spawnCommand } from './exec-util' ;
18
18
import { ArduinoDaemonImpl } from './arduino-daemon-impl' ;
19
- import { DefaultCliConfig , CLI_CONFIG } from './cli-config' ;
19
+ import { DefaultCliConfig , CLI_CONFIG , CliConfig } from './cli-config' ;
20
20
import { Deferred } from '@theia/core/lib/common/promise-util' ;
21
21
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables' ;
22
22
import { deepClone , nls } from '@theia/core' ;
@@ -180,17 +180,13 @@ export class ConfigServiceImpl
180
180
const content = await fs . readFile ( cliConfigPath , {
181
181
encoding : 'utf8' ,
182
182
} ) ;
183
- const model = ( yaml . safeLoad ( content ) || { } ) as DefaultCliConfig ;
183
+ const model = ( yaml . safeLoad ( content ) || { } ) as CliConfig ;
184
184
this . logger . info ( `Loaded CLI configuration: ${ JSON . stringify ( model ) } ` ) ;
185
- if (
186
- model . directories &&
187
- model . directories . data &&
188
- model . directories . user
189
- ) {
185
+ if ( model . directories ?. data && model . directories ?. user ) {
190
186
this . logger . info (
191
187
"'directories.data' and 'directories.user' are set in the CLI configuration model."
192
188
) ;
193
- return model ;
189
+ return model as DefaultCliConfig ;
194
190
}
195
191
// The CLI can run with partial (missing `port`, `directories`), the IDE2 cannot.
196
192
// We merge the default CLI config with the partial user's config.
@@ -221,17 +217,14 @@ export class ConfigServiceImpl
221
217
222
218
private async getFallbackCliConfig ( ) : Promise < DefaultCliConfig > {
223
219
const cliPath = this . daemon . getExecPath ( ) ;
224
- const rawJson = await spawnCommand ( cliPath , [ 'config' , 'dump' , '--json' ] ) ;
225
- const config = JSON . parse ( rawJson ) ;
226
-
227
- // Since CLI 1.0, the command `config dump` only returns user-modified values and not default ones.
228
- // directories.user and directories.data are required by IDE2 so we get the default value explicitly.
229
- const directoriesRaw = await spawnCommand ( cliPath , [
230
- 'config' ,
231
- 'get' ,
232
- 'directories' ,
233
- '--json' ,
220
+ const [ configRaw , directoriesRaw ] = await Promise . all ( [
221
+ spawnCommand ( cliPath , [ 'config' , 'dump' , '--json' ] ) ,
222
+ // Since CLI 1.0, the command `config dump` only returns user-modified values and not default ones.
223
+ // directories.user and directories.data are required by IDE2 so we get the default value explicitly.
224
+ spawnCommand ( cliPath , [ 'config' , 'get' , 'directories' , '--json' ] ) ,
234
225
] ) ;
226
+
227
+ const config = JSON . parse ( configRaw ) ;
235
228
const { user, data } = JSON . parse ( directoriesRaw ) ;
236
229
237
230
return { ...config . config , directories : { user, data } } ;
@@ -317,25 +310,26 @@ export class ConfigServiceImpl
317
310
config . board_manager ?. additional_urls || [ ] ,
318
311
} ;
319
312
313
+ const client = createArduinoCoreServiceClient ( { port } ) ;
314
+
320
315
for ( const [ key , value ] of Object . entries ( updatableConfig ) ) {
321
- const client = createArduinoCoreServiceClient ( { port } ) ;
322
316
const req = new SettingsSetValueRequest ( ) ;
323
317
req . setKey ( key ) ;
324
318
req . setEncodedValue ( JSON . stringify ( value ) ) ;
325
- await new Promise < void > ( ( resolve , reject ) => {
319
+ await new Promise < void > ( ( resolve ) => {
326
320
client . settingsSetValue ( req , ( error ) => {
327
- try {
328
- if ( error ) {
329
- reject ( error ) ;
330
- return ;
331
- }
332
- resolve ( ) ;
333
- } finally {
334
- client . close ( ) ;
321
+ if ( error ) {
322
+ this . logger . error (
323
+ `Could not update config with key: ${ key } and value: ${ value } ` ,
324
+ error
325
+ ) ;
335
326
}
327
+ resolve ( ) ;
336
328
} ) ;
337
329
} ) ;
338
330
}
331
+
332
+ client . close ( ) ;
339
333
}
340
334
341
335
private async writeDaemonState ( port : number ) : Promise < void > {
@@ -359,7 +353,7 @@ export class ConfigServiceImpl
359
353
360
354
const cliConfigUri = await this . getCliConfigFileUri ( ) ;
361
355
const cliConfigPath = FileUri . fsPath ( cliConfigUri ) ;
362
- fs . writeFile ( cliConfigPath , configRaw , { encoding : 'utf-8' } ) ;
356
+ await fs . writeFile ( cliConfigPath , configRaw , { encoding : 'utf-8' } ) ;
363
357
}
364
358
365
359
// #1445
0 commit comments