@@ -22,15 +22,21 @@ export class UploadSketch extends SketchContribution {
22
22
@inject ( BoardsServiceProvider )
23
23
protected readonly boardsServiceClientImpl : BoardsServiceProvider ;
24
24
25
+ uploadInProgress = false ;
26
+
25
27
registerCommands ( registry : CommandRegistry ) : void {
26
28
registry . registerCommand ( UploadSketch . Commands . UPLOAD_SKETCH , {
27
- execute : ( ) => this . uploadSketch ( )
29
+ execute : ( ) => this . uploadSketch ( ) ,
30
+ isEnabled : ( ) => ! this . uploadInProgress ,
28
31
} ) ;
29
32
registry . registerCommand ( UploadSketch . Commands . UPLOAD_SKETCH_USING_PROGRAMMER , {
30
- execute : ( ) => this . uploadSketch ( true )
33
+ execute : ( ) => this . uploadSketch ( true ) ,
34
+ isEnabled : ( ) => ! this . uploadInProgress ,
31
35
} ) ;
32
36
registry . registerCommand ( UploadSketch . Commands . UPLOAD_SKETCH_TOOLBAR , {
33
37
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
38
+ isEnabled : ( ) => ! this . uploadInProgress ,
39
+ isToggled : ( ) => this . uploadInProgress ,
34
40
execute : ( ) => registry . executeCommand ( UploadSketch . Commands . UPLOAD_SKETCH . id )
35
41
} ) ;
36
42
}
@@ -69,6 +75,11 @@ export class UploadSketch extends SketchContribution {
69
75
}
70
76
71
77
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
+
72
83
const sketch = await this . sketchServiceClient . currentSketch ( ) ;
73
84
if ( ! sketch ) {
74
85
return ;
@@ -131,6 +142,7 @@ export class UploadSketch extends SketchContribution {
131
142
} catch ( e ) {
132
143
this . messageService . error ( e . toString ( ) ) ;
133
144
} finally {
145
+ this . uploadInProgress = false ;
134
146
if ( monitorConfig ) {
135
147
const { board, port } = monitorConfig ;
136
148
try {
0 commit comments