1
1
import { promises as fs } from 'node:fs' ;
2
2
import { dirname } from 'node:path' ;
3
3
import yaml from 'js-yaml' ;
4
- import * as grpc from '@grpc/grpc-js' ;
5
4
import { injectable , inject , named } from '@theia/core/shared/inversify' ;
6
5
import URI from '@theia/core/lib/common/uri' ;
7
6
import { ILogger } from '@theia/core/lib/common/logger' ;
@@ -16,18 +15,17 @@ import {
16
15
ConfigState ,
17
16
} from '../common/protocol' ;
18
17
import { spawnCommand } from './exec-util' ;
19
- import {
20
- MergeRequest ,
21
- WriteRequest ,
22
- } from './cli-protocol/cc/arduino/cli/settings/v1/settings_pb' ;
23
- import { SettingsServiceClient } from './cli-protocol/cc/arduino/cli/settings/v1/settings_grpc_pb' ;
24
- import * as serviceGrpcPb from './cli-protocol/cc/arduino/cli/settings/v1/settings_grpc_pb' ;
25
18
import { ArduinoDaemonImpl } from './arduino-daemon-impl' ;
26
19
import { DefaultCliConfig , CLI_CONFIG } from './cli-config' ;
27
20
import { Deferred } from '@theia/core/lib/common/promise-util' ;
28
21
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables' ;
29
22
import { deepClone , nls } from '@theia/core' ;
30
23
import { ErrnoException } from './utils/errors' ;
24
+ import {
25
+ SettingsMergeRequest ,
26
+ SettingsWriteRequest ,
27
+ } from './cli-protocol/cc/arduino/cli/commands/v1/settings_pb' ;
28
+ import { createArduinoCoreServiceClient } from './arduino-core-service-client' ;
31
29
32
30
const deepmerge = require ( 'deepmerge' ) ;
33
31
@@ -293,16 +291,16 @@ export class ConfigServiceImpl
293
291
}
294
292
295
293
private async updateDaemon (
296
- port : string | number ,
294
+ port : number | number ,
297
295
config : DefaultCliConfig
298
296
) : Promise < void > {
299
- const client = this . createClient ( port ) ;
300
- const req = new MergeRequest ( ) ;
297
+ const client = createArduinoCoreServiceClient ( { port } ) ;
298
+ const req = new SettingsMergeRequest ( ) ;
301
299
const json = JSON . stringify ( config , null , 2 ) ;
302
300
req . setJsonData ( json ) ;
303
301
this . logger . info ( `Updating daemon with 'data': ${ json } ` ) ;
304
302
return new Promise < void > ( ( resolve , reject ) => {
305
- client . merge ( req , ( error ) => {
303
+ client . settingsMerge ( req , ( error ) => {
306
304
try {
307
305
if ( error ) {
308
306
reject ( error ) ;
@@ -316,14 +314,14 @@ export class ConfigServiceImpl
316
314
} ) ;
317
315
}
318
316
319
- private async writeDaemonState ( port : string | number ) : Promise < void > {
320
- const client = this . createClient ( port ) ;
321
- const req = new WriteRequest ( ) ;
317
+ private async writeDaemonState ( port : number | number ) : Promise < void > {
318
+ const client = createArduinoCoreServiceClient ( { port } ) ;
319
+ const req = new SettingsWriteRequest ( ) ;
322
320
const cliConfigUri = await this . getCliConfigFileUri ( ) ;
323
321
const cliConfigPath = FileUri . fsPath ( cliConfigUri ) ;
324
322
req . setFilePath ( cliConfigPath ) ;
325
323
return new Promise < void > ( ( resolve , reject ) => {
326
- client . write ( req , ( error ) => {
324
+ client . settingsWrite ( req , ( error ) => {
327
325
try {
328
326
if ( error ) {
329
327
reject ( error ) ;
@@ -337,19 +335,6 @@ export class ConfigServiceImpl
337
335
} ) ;
338
336
}
339
337
340
- private createClient ( port : string | number ) : SettingsServiceClient {
341
- // https://github.com/agreatfool/grpc_tools_node_protoc_ts/blob/master/doc/grpcjs_support.md#usage
342
- const SettingsServiceClient = grpc . makeClientConstructor (
343
- // @ts -expect-error: ignore
344
- serviceGrpcPb [ 'cc.arduino.cli.settings.v1.SettingsService' ] ,
345
- 'SettingsServiceService'
346
- ) as any ;
347
- return new SettingsServiceClient (
348
- `localhost:${ port } ` ,
349
- grpc . credentials . createInsecure ( )
350
- ) as SettingsServiceClient ;
351
- }
352
-
353
338
// #1445
354
339
private async ensureUserDirExists (
355
340
cliConfig : DefaultCliConfig
0 commit comments