1
- import { inject , injectable } from 'inversify ' ;
1
+ import * as fs from 'fs ' ;
2
2
import * as grpc from '@grpc/grpc-js' ;
3
+ import * as PQueue from 'p-queue' ;
4
+ import { inject , injectable } from 'inversify' ;
5
+ import URI from '@theia/core/lib/common/uri' ;
6
+ import { FileSystem } from '@theia/filesystem/lib/common' ;
7
+ import { WorkspaceServiceExt } from '../browser/workspace-service-ext' ;
8
+ import { ToolOutputServiceServer } from '../common/protocol/tool-output-service' ;
3
9
import { ArduinoCoreClient } from './cli-protocol/commands/commands_grpc_pb' ;
4
10
import {
5
11
InitResp ,
@@ -10,16 +16,9 @@ import {
10
16
UpdateLibrariesIndexReq ,
11
17
UpdateLibrariesIndexResp
12
18
} from './cli-protocol/commands/commands_pb' ;
13
- import { WorkspaceServiceExt } from '../browser/workspace-service-ext' ;
14
- import { FileSystem } from '@theia/filesystem/lib/common' ;
15
- import URI from '@theia/core/lib/common/uri' ;
16
- import { CoreClientProvider , Client } from './core-client-provider' ;
17
- import * as PQueue from 'p-queue' ;
18
- import { ToolOutputServiceServer } from '../common/protocol/tool-output-service' ;
19
+ import { ArduinoCli } from './arduino-cli' ;
19
20
import { Instance } from './cli-protocol/commands/common_pb' ;
20
- import * as fs from 'fs-extra' ;
21
- import * as path from 'path' ;
22
- import * as os from 'os' ;
21
+ import { CoreClientProvider , Client } from './core-client-provider' ;
23
22
24
23
@injectable ( )
25
24
export class CoreClientProviderImpl implements CoreClientProvider {
@@ -36,6 +35,9 @@ export class CoreClientProviderImpl implements CoreClientProvider {
36
35
@inject ( ToolOutputServiceServer )
37
36
protected readonly toolOutputService : ToolOutputServiceServer ;
38
37
38
+ @inject ( ArduinoCli )
39
+ protected readonly cli : ArduinoCli ;
40
+
39
41
async getClient ( workspaceRootOrResourceUri ?: string ) : Promise < Client | undefined > {
40
42
return this . clientRequestQueue . add ( ( ) => new Promise < Client | undefined > ( async resolve => {
41
43
const roots = await this . workspaceServiceExt . roots ( ) ;
@@ -76,19 +78,19 @@ export class CoreClientProviderImpl implements CoreClientProvider {
76
78
throw new Error ( `Could not resolve filesystem path of URI: ${ rootUri } .` ) ;
77
79
}
78
80
79
- const defaultDownloadsDirPath = path . resolve ( os . homedir ( ) , 'Arduino-PoC' , 'downloads' ) ;
80
- if ( ! fs . existsSync ( defaultDownloadsDirPath ) ) {
81
- fs . mkdirpSync ( defaultDownloadsDirPath ) ;
81
+ const { dataDirPath, sketchDirPath } = await this . cli . getDefaultConfig ( ) ;
82
+
83
+ if ( ! fs . existsSync ( dataDirPath ) ) {
84
+ throw new Error ( `Data dir path does not exist: ${ dataDirPath } .` ) ;
82
85
}
83
86
84
- const defaultDataDirPath = path . resolve ( os . homedir ( ) , 'Arduino-PoC' , 'data' )
85
- if ( ! fs . existsSync ( defaultDataDirPath ) ) {
86
- fs . mkdirpSync ( defaultDataDirPath ) ;
87
+ if ( ! fs . existsSync ( sketchDirPath ) ) {
88
+ throw new Error ( `Sketch dir path does not exist: ${ sketchDirPath } .` ) ;
87
89
}
88
90
89
- config . setSketchbookdir ( rootPath ) ;
90
- config . setDatadir ( defaultDataDirPath ) ;
91
- config . setDownloadsdir ( defaultDownloadsDirPath ) ;
91
+ config . setSketchbookdir ( sketchDirPath ) ;
92
+ config . setDatadir ( dataDirPath ) ;
93
+ config . setDownloadsdir ( dataDirPath ) ;
92
94
config . setBoardmanageradditionalurlsList ( [ 'https://downloads.arduino.cc/packages/package_index.json' ] ) ;
93
95
94
96
const initReq = new InitReq ( ) ;
0 commit comments