1
1
import { join } from 'path' ;
2
- import { promises as fs } from 'fs' ;
3
2
import { inject , injectable , named } from '@theia/core/shared/inversify' ;
4
3
import { spawn , ChildProcess } from 'child_process' ;
5
4
import { FileUri } from '@theia/core/lib/node/file-uri' ;
@@ -16,7 +15,7 @@ import { BackendApplicationContribution } from '@theia/core/lib/node/backend-app
16
15
import { ArduinoDaemon , NotificationServiceServer } from '../common/protocol' ;
17
16
import { CLI_CONFIG } from './cli-config' ;
18
17
import { getExecPath } from './exec-util' ;
19
- import { ErrnoException } from './utils/errors ' ;
18
+ import { SettingsReader } from './settings-reader ' ;
20
19
21
20
@injectable ( )
22
21
export class ArduinoDaemonImpl
@@ -32,6 +31,9 @@ export class ArduinoDaemonImpl
32
31
@inject ( NotificationServiceServer )
33
32
private readonly notificationService : NotificationServiceServer ;
34
33
34
+ @inject ( SettingsReader )
35
+ private readonly settingsReader : SettingsReader ;
36
+
35
37
private readonly toDispose = new DisposableCollection ( ) ;
36
38
private readonly onDaemonStartedEmitter = new Emitter < string > ( ) ;
37
39
private readonly onDaemonStoppedEmitter = new Emitter < void > ( ) ;
@@ -149,34 +151,12 @@ export class ArduinoDaemonImpl
149
151
}
150
152
151
153
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 ;
179
158
}
159
+ return false ;
180
160
}
181
161
182
162
protected async spawnDaemonProcess ( ) : Promise < {
0 commit comments