1
+ import { ILogger } from '@theia/core/lib/common/logger' ;
2
+ import { inject , injectable , named } from '@theia/core/shared/inversify' ;
3
+ import type { Port } from '../common/protocol' ;
1
4
import {
2
5
ArduinoFirmwareUploader ,
3
6
FirmwareInfo ,
4
7
} from '../common/protocol/arduino-firmware-uploader' ;
5
- import { injectable , inject , named } from '@theia/core/shared/inversify' ;
6
- import { ExecutableService , Port } from '../common/protocol' ;
7
8
import { getExecPath , spawnCommand } from './exec-util' ;
8
- import { ILogger } from '@theia/core/lib/common/logger' ;
9
9
import { MonitorManager } from './monitor-manager' ;
10
10
11
11
@injectable ( )
12
12
export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
13
- @inject ( ExecutableService )
14
- protected executableService : ExecutableService ;
15
-
16
- protected _execPath : string | undefined ;
17
-
18
13
@inject ( ILogger )
19
14
@named ( 'fwuploader' )
20
- protected readonly logger : ILogger ;
21
-
15
+ private readonly logger : ILogger ;
22
16
@inject ( MonitorManager )
23
- protected readonly monitorManager : MonitorManager ;
24
-
25
- protected onError ( error : any ) : void {
26
- this . logger . error ( error ) ;
27
- }
28
-
29
- async getExecPath ( ) : Promise < string > {
30
- if ( this . _execPath ) {
31
- return this . _execPath ;
32
- }
33
- this . _execPath = await getExecPath ( 'arduino-fwuploader' ) ;
34
- return this . _execPath ;
35
- }
36
-
37
- async runCommand ( args : string [ ] ) : Promise < any > {
38
- const execPath = await this . getExecPath ( ) ;
39
- return await spawnCommand ( `"${ execPath } "` , args , this . onError . bind ( this ) ) ;
40
- }
17
+ private readonly monitorManager : MonitorManager ;
41
18
42
- async uploadCertificates ( command : string ) : Promise < any > {
19
+ async uploadCertificates ( command : string ) : Promise < string > {
43
20
return await this . runCommand ( [ 'certificates' , 'flash' , command ] ) ;
44
21
}
45
22
@@ -70,14 +47,13 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
70
47
}
71
48
72
49
async flash ( firmware : FirmwareInfo , port : Port ) : Promise < string > {
73
- let output ;
74
50
const board = {
75
51
name : firmware . board_name ,
76
52
fqbn : firmware . board_fqbn ,
77
53
} ;
78
54
try {
79
55
await this . monitorManager . notifyUploadStarted ( board . fqbn , port ) ;
80
- output = await this . runCommand ( [
56
+ const output = await this . runCommand ( [
81
57
'firmware' ,
82
58
'flash' ,
83
59
'--fqbn' ,
@@ -87,11 +63,18 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
87
63
'--module' ,
88
64
`${ firmware . module } @${ firmware . firmware_version } ` ,
89
65
] ) ;
90
- } catch ( e ) {
91
- throw e ;
66
+ return output ;
92
67
} finally {
93
68
await this . monitorManager . notifyUploadFinished ( board . fqbn , port ) ;
94
- return output ;
95
69
}
96
70
}
71
+
72
+ private onError ( error : Error ) : void {
73
+ this . logger . error ( error ) ;
74
+ }
75
+
76
+ private async runCommand ( args : string [ ] ) : Promise < string > {
77
+ const execPath = getExecPath ( 'arduino-fwuploader' ) ;
78
+ return await spawnCommand ( execPath , args , this . onError . bind ( this ) ) ;
79
+ }
97
80
}
0 commit comments