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' ;
14import {
25 ArduinoFirmwareUploader ,
36 FirmwareInfo ,
47} from '../common/protocol/arduino-firmware-uploader' ;
5- import { injectable , inject , named } from '@theia/core/shared/inversify' ;
6- import { ExecutableService , Port } from '../common/protocol' ;
78import { getExecPath , spawnCommand } from './exec-util' ;
8- import { ILogger } from '@theia/core/lib/common/logger' ;
99import { MonitorManager } from './monitor-manager' ;
1010
1111@injectable ( )
1212export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
13- @inject ( ExecutableService )
14- protected executableService : ExecutableService ;
15-
16- protected _execPath : string | undefined ;
17-
1813 @inject ( ILogger )
1914 @named ( 'fwuploader' )
20- protected readonly logger : ILogger ;
21-
15+ private readonly logger : ILogger ;
2216 @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 ;
4118
42- async uploadCertificates ( command : string ) : Promise < any > {
19+ async uploadCertificates ( command : string ) : Promise < string > {
4320 return await this . runCommand ( [ 'certificates' , 'flash' , command ] ) ;
4421 }
4522
@@ -70,14 +47,13 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
7047 }
7148
7249 async flash ( firmware : FirmwareInfo , port : Port ) : Promise < string > {
73- let output ;
7450 const board = {
7551 name : firmware . board_name ,
7652 fqbn : firmware . board_fqbn ,
7753 } ;
7854 try {
7955 await this . monitorManager . notifyUploadStarted ( board . fqbn , port ) ;
80- output = await this . runCommand ( [
56+ const output = await this . runCommand ( [
8157 'firmware' ,
8258 'flash' ,
8359 '--fqbn' ,
@@ -87,11 +63,18 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
8763 '--module' ,
8864 `${ firmware . module } @${ firmware . firmware_version } ` ,
8965 ] ) ;
90- } catch ( e ) {
91- throw e ;
66+ return output ;
9267 } finally {
9368 await this . monitorManager . notifyUploadFinished ( board . fqbn , port ) ;
94- return output ;
9569 }
9670 }
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+ }
9780}
0 commit comments