@@ -12,7 +12,7 @@ import {
12
12
SketchContribution ,
13
13
TabBarToolbarRegistry ,
14
14
} from './contribution' ;
15
- import { nls } from '@theia/core/lib/common' ;
15
+ import { MaybePromise , nls } from '@theia/core/lib/common' ;
16
16
17
17
@injectable ( )
18
18
export class Debug extends SketchContribution {
@@ -79,52 +79,15 @@ export class Debug extends SketchContribution {
79
79
: Debug . Commands . START_DEBUGGING . label
80
80
} `)
81
81
) ;
82
- const refreshState = async (
83
- board : Board | undefined = this . boardsServiceProvider . boardsConfig
84
- . selectedBoard
85
- ) => {
86
- if ( ! board ) {
87
- this . disabledMessage = nls . localize (
88
- 'arduino/common/noBoardSelected' ,
89
- 'No board selected'
90
- ) ;
91
- return ;
92
- }
93
- const fqbn = board . fqbn ;
94
- if ( ! fqbn ) {
95
- this . disabledMessage = nls . localize (
96
- 'arduino/debug/noPlatformInstalledFor' ,
97
- "Platform is not installed for '{0}'" ,
98
- board . name
99
- ) ;
100
- return ;
101
- }
102
- const details = await this . boardService . getBoardDetails ( { fqbn } ) ;
103
- if ( ! details ) {
104
- this . disabledMessage = nls . localize (
105
- 'arduino/debug/noPlatformInstalledFor' ,
106
- "Platform is not installed for '{0}'" ,
107
- board . name
108
- ) ;
109
- return ;
110
- }
111
- const { debuggingSupported } = details ;
112
- if ( ! debuggingSupported ) {
113
- this . disabledMessage = nls . localize (
114
- 'arduino/debug/debuggingNotSupported' ,
115
- "Debugging is not supported by '{0}'" ,
116
- board . name
117
- ) ;
118
- } else {
119
- this . disabledMessage = undefined ;
120
- }
121
- } ;
122
82
this . boardsServiceProvider . onBoardsConfigChanged ( ( { selectedBoard } ) =>
123
- refreshState ( selectedBoard )
83
+ this . refreshState ( selectedBoard )
124
84
) ;
125
- this . notificationCenter . onPlatformInstalled ( ( ) => refreshState ( ) ) ;
126
- this . notificationCenter . onPlatformUninstalled ( ( ) => refreshState ( ) ) ;
127
- refreshState ( ) ;
85
+ this . notificationCenter . onPlatformInstalled ( ( ) => this . refreshState ( ) ) ;
86
+ this . notificationCenter . onPlatformUninstalled ( ( ) => this . refreshState ( ) ) ;
87
+ }
88
+
89
+ override onReady ( ) : MaybePromise < void > {
90
+ this . refreshState ( ) ;
128
91
}
129
92
130
93
override registerCommands ( registry : CommandRegistry ) : void {
@@ -140,6 +103,47 @@ export class Debug extends SketchContribution {
140
103
registry . registerItem ( this . debugToolbarItem ) ;
141
104
}
142
105
106
+ private async refreshState (
107
+ board : Board | undefined = this . boardsServiceProvider . boardsConfig
108
+ . selectedBoard
109
+ ) : Promise < void > {
110
+ if ( ! board ) {
111
+ this . disabledMessage = nls . localize (
112
+ 'arduino/common/noBoardSelected' ,
113
+ 'No board selected'
114
+ ) ;
115
+ return ;
116
+ }
117
+ const fqbn = board . fqbn ;
118
+ if ( ! fqbn ) {
119
+ this . disabledMessage = nls . localize (
120
+ 'arduino/debug/noPlatformInstalledFor' ,
121
+ "Platform is not installed for '{0}'" ,
122
+ board . name
123
+ ) ;
124
+ return ;
125
+ }
126
+ const details = await this . boardService . getBoardDetails ( { fqbn } ) ;
127
+ if ( ! details ) {
128
+ this . disabledMessage = nls . localize (
129
+ 'arduino/debug/noPlatformInstalledFor' ,
130
+ "Platform is not installed for '{0}'" ,
131
+ board . name
132
+ ) ;
133
+ return ;
134
+ }
135
+ const { debuggingSupported } = details ;
136
+ if ( ! debuggingSupported ) {
137
+ this . disabledMessage = nls . localize (
138
+ 'arduino/debug/debuggingNotSupported' ,
139
+ "Debugging is not supported by '{0}'" ,
140
+ board . name
141
+ ) ;
142
+ } else {
143
+ this . disabledMessage = undefined ;
144
+ }
145
+ }
146
+
143
147
protected async startDebug (
144
148
board : Board | undefined = this . boardsServiceProvider . boardsConfig
145
149
. selectedBoard
0 commit comments