11import { join } from 'path' ;
2- import { promises as fs } from 'fs' ;
32import { inject , injectable , named } from '@theia/core/shared/inversify' ;
43import { spawn , ChildProcess } from 'child_process' ;
54import { FileUri } from '@theia/core/lib/node/file-uri' ;
@@ -16,7 +15,7 @@ import { BackendApplicationContribution } from '@theia/core/lib/node/backend-app
1615import { ArduinoDaemon , NotificationServiceServer } from '../common/protocol' ;
1716import { CLI_CONFIG } from './cli-config' ;
1817import { getExecPath } from './exec-util' ;
19- import { ErrnoException } from './utils/errors ' ;
18+ import { SettingsReader } from './settings-reader ' ;
2019
2120@injectable ( )
2221export class ArduinoDaemonImpl
@@ -32,6 +31,9 @@ export class ArduinoDaemonImpl
3231 @inject ( NotificationServiceServer )
3332 private readonly notificationService : NotificationServiceServer ;
3433
34+ @inject ( SettingsReader )
35+ private readonly settingsReader : SettingsReader ;
36+
3537 private readonly toDispose = new DisposableCollection ( ) ;
3638 private readonly onDaemonStartedEmitter = new Emitter < string > ( ) ;
3739 private readonly onDaemonStoppedEmitter = new Emitter < void > ( ) ;
@@ -149,34 +151,12 @@ export class ArduinoDaemonImpl
149151 }
150152
151153 private async debugDaemon ( ) : Promise < boolean > {
152- // Poor man's preferences on the backend. (https://github.com/arduino/arduino-ide/issues/1056#issuecomment-1153975064)
153- const configDirUri = await this . envVariablesServer . getConfigDirUri ( ) ;
154- const configDirPath = FileUri . fsPath ( configDirUri ) ;
155- try {
156- const raw = await fs . readFile ( join ( configDirPath , 'settings.json' ) , {
157- encoding : 'utf8' ,
158- } ) ;
159- const json = this . tryParse ( raw ) ;
160- if ( json ) {
161- const value = json [ 'arduino.cli.daemon.debug' ] ;
162- return typeof value === 'boolean' && ! ! value ;
163- }
164- return false ;
165- } catch ( error ) {
166- if ( ErrnoException . isENOENT ( error ) ) {
167- return false ;
168- }
169- throw error ;
170- }
171- }
172-
173- // eslint-disable-next-line @typescript-eslint/no-explicit-any
174- private tryParse ( raw : string ) : any | undefined {
175- try {
176- return JSON . parse ( raw ) ;
177- } catch {
178- return undefined ;
154+ const settings = await this . settingsReader . read ( ) ;
155+ if ( settings ) {
156+ const value = settings [ 'arduino.cli.daemon.debug' ] ;
157+ return value === true ;
179158 }
159+ return false ;
180160 }
181161
182162 protected async spawnDaemonProcess ( ) : Promise < {
0 commit comments