@@ -130,28 +130,39 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
130
130
this . lastAvailablePortsOnUpload = value ;
131
131
}
132
132
133
- public forcePostUploadReconnect ( ) : void {
133
+ private portToAutoSelectCanBeDerived ( ) : boolean {
134
+ return Boolean (
135
+ this . lastBoardsConfigOnUpload && this . lastAvailablePortsOnUpload
136
+ ) ;
137
+ }
138
+
139
+ public attemptPostUploadAutoSelect ( ) : void {
134
140
setTimeout ( ( ) => {
135
- const newState = {
136
- ports : this . _availablePorts ,
137
- boards : this . _availableBoards ,
138
- } ;
139
- this . deriveBoardConfigToAutoSelect ( newState ) ;
140
- if ( this . lastBoardsConfigOnUpload ) {
141
- this . tryReconnect ( ) ;
141
+ if ( this . portToAutoSelectCanBeDerived ( ) ) {
142
+ this . attemptAutoSelect ( {
143
+ ports : this . _availablePorts ,
144
+ boards : this . _availableBoards ,
145
+ } ) ;
142
146
}
143
147
} , 2000 ) ; // 2 second delay same as IDE 1.8
144
148
}
145
149
150
+ private attemptAutoSelect (
151
+ newState : AttachedBoardsChangeEvent [ 'newState' ]
152
+ ) : void {
153
+ this . deriveBoardConfigToAutoSelect ( newState ) ;
154
+ this . tryReconnect ( ) ;
155
+ }
156
+
146
157
private deriveBoardConfigToAutoSelect (
147
158
newState : AttachedBoardsChangeEvent [ 'newState' ]
148
159
) : void {
149
- if ( ! this . lastBoardsConfigOnUpload || ! this . lastAvailablePortsOnUpload ) {
160
+ if ( ! this . portToAutoSelectCanBeDerived ( ) ) {
150
161
this . boardConfigToAutoSelect = undefined ;
151
162
return ;
152
163
}
153
164
154
- const oldPorts = this . lastAvailablePortsOnUpload ;
165
+ const oldPorts = this . lastAvailablePortsOnUpload ! ;
155
166
const { ports : newPorts , boards : newBoards } = newState ;
156
167
157
168
const appearedPorts =
@@ -167,12 +178,14 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
167
178
Port . sameAs ( board . port , port )
168
179
) ;
169
180
181
+ const lastBoardsConfigOnUpload = this . lastBoardsConfigOnUpload ! ;
182
+
170
183
if (
171
184
boardOnAppearedPort &&
172
- this . lastBoardsConfigOnUpload . selectedBoard &&
185
+ lastBoardsConfigOnUpload . selectedBoard &&
173
186
Board . sameAs (
174
187
boardOnAppearedPort ,
175
- this . lastBoardsConfigOnUpload . selectedBoard
188
+ lastBoardsConfigOnUpload . selectedBoard
176
189
)
177
190
) {
178
191
this . setLastBoardsConfigOnUpload ( undefined ) ;
@@ -197,18 +210,15 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
197
210
this . logger . info ( '------------------------------------------' ) ;
198
211
}
199
212
200
- const { uploadInProgress } = event ;
201
-
202
- if ( ! uploadInProgress ) {
203
- this . deriveBoardConfigToAutoSelect ( event . newState ) ;
204
- }
205
-
206
213
this . _attachedBoards = event . newState . boards ;
207
214
this . _availablePorts = event . newState . ports ;
208
215
this . onAvailablePortsChangedEmitter . fire ( this . _availablePorts ) ;
209
216
this . reconcileAvailableBoards ( ) . then ( ( ) => {
217
+ const { uploadInProgress } = event ;
218
+ // avoid attempting "auto-selection" while an
219
+ // upload is in progress
210
220
if ( ! uploadInProgress ) {
211
- this . tryReconnect ( ) ;
221
+ this . attemptAutoSelect ( event . newState ) ;
212
222
}
213
223
} ) ;
214
224
}
0 commit comments