@@ -22,15 +22,21 @@ export class UploadSketch extends SketchContribution {
2222 @inject ( BoardsServiceProvider )
2323 protected readonly boardsServiceClientImpl : BoardsServiceProvider ;
2424
25+ uploadInProgress = false ;
26+
2527 registerCommands ( registry : CommandRegistry ) : void {
2628 registry . registerCommand ( UploadSketch . Commands . UPLOAD_SKETCH , {
27- execute : ( ) => this . uploadSketch ( )
29+ execute : ( ) => this . uploadSketch ( ) ,
30+ isEnabled : ( ) => ! this . uploadInProgress ,
2831 } ) ;
2932 registry . registerCommand ( UploadSketch . Commands . UPLOAD_SKETCH_USING_PROGRAMMER , {
30- execute : ( ) => this . uploadSketch ( true )
33+ execute : ( ) => this . uploadSketch ( true ) ,
34+ isEnabled : ( ) => ! this . uploadInProgress ,
3135 } ) ;
3236 registry . registerCommand ( UploadSketch . Commands . UPLOAD_SKETCH_TOOLBAR , {
3337 isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
38+ isEnabled : ( ) => ! this . uploadInProgress ,
39+ isToggled : ( ) => this . uploadInProgress ,
3440 execute : ( ) => registry . executeCommand ( UploadSketch . Commands . UPLOAD_SKETCH . id )
3541 } ) ;
3642 }
@@ -69,6 +75,11 @@ export class UploadSketch extends SketchContribution {
6975 }
7076
7177 async uploadSketch ( usingProgrammer : boolean = false ) : Promise < void > {
78+
79+ // toggle the toolbar button and menu item state.
80+ // uploadInProgress will be set to false whether the upload fails or not
81+ this . uploadInProgress = true ;
82+
7283 const sketch = await this . sketchServiceClient . currentSketch ( ) ;
7384 if ( ! sketch ) {
7485 return ;
@@ -131,6 +142,7 @@ export class UploadSketch extends SketchContribution {
131142 } catch ( e ) {
132143 this . messageService . error ( e . toString ( ) ) ;
133144 } finally {
145+ this . uploadInProgress = false ;
134146 if ( monitorConfig ) {
135147 const { board, port } = monitorConfig ;
136148 try {
0 commit comments