@@ -66,6 +66,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
66
66
protected _availableBoards : AvailableBoard [ ] = [ ] ;
67
67
68
68
private lastBoardsConfigOnUpload : BoardsConfig . Config | undefined ;
69
+ private lastAvailablePortsOnUpload : Port [ ] | undefined ;
69
70
private boardConfigToAutoSelect : BoardsConfig . Config | undefined ;
70
71
71
72
/**
@@ -114,24 +115,44 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
114
115
return this . _reconciled . promise ;
115
116
}
116
117
117
- public setLastBoardsConfigOnUpload (
118
+ public snapshotBoardDiscoveryOnUpload ( ) : void {
119
+ this . setLastBoardsConfigOnUpload ( this . boardsConfig ) ;
120
+ this . setAvailablePortsOnUpload ( this . _availablePorts ) ;
121
+ }
122
+
123
+ private setLastBoardsConfigOnUpload (
118
124
value : BoardsConfig . Config | undefined
119
125
) : void {
120
126
this . lastBoardsConfigOnUpload = value ;
121
127
}
122
128
129
+ private setAvailablePortsOnUpload ( value : Port [ ] | undefined ) : void {
130
+ this . lastAvailablePortsOnUpload = value ;
131
+ }
132
+
133
+ public forcePostUploadReconnect ( ) : void {
134
+ setTimeout ( ( ) => {
135
+ const newState = {
136
+ ports : this . _availablePorts ,
137
+ boards : this . _availableBoards ,
138
+ } ;
139
+ this . deriveBoardConfigToAutoSelect ( newState ) ;
140
+ if ( this . lastBoardsConfigOnUpload ) {
141
+ this . tryReconnect ( ) ;
142
+ }
143
+ } , 2000 ) ; // 2 second delay same as IDE 1.8
144
+ }
145
+
123
146
private deriveBoardConfigToAutoSelect (
124
- event : AttachedBoardsChangeEvent
147
+ newState : AttachedBoardsChangeEvent [ 'newState' ]
125
148
) : void {
126
- if ( ! this . lastBoardsConfigOnUpload ) {
149
+ if ( ! this . lastBoardsConfigOnUpload || ! this . lastAvailablePortsOnUpload ) {
127
150
this . boardConfigToAutoSelect = undefined ;
128
151
return ;
129
152
}
130
153
131
- const {
132
- oldState : { ports : oldPorts } ,
133
- newState : { ports : newPorts , boards : newBoards } ,
134
- } = event ;
154
+ const oldPorts = this . lastAvailablePortsOnUpload ;
155
+ const { ports : newPorts , boards : newBoards } = newState ;
135
156
136
157
const appearedPorts =
137
158
oldPorts . length > 0
@@ -141,25 +162,28 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
141
162
: newPorts ;
142
163
143
164
if ( appearedPorts . length > 0 ) {
144
- const lastSelectionOnUpload = this . lastBoardsConfigOnUpload ;
145
- this . setLastBoardsConfigOnUpload ( undefined ) ;
146
-
147
- const appearedPort = appearedPorts [ 0 ] ;
165
+ for ( const port of appearedPorts ) {
166
+ const boardOnAppearedPort = newBoards . find ( ( board : Board ) =>
167
+ Port . sameAs ( board . port , port )
168
+ ) ;
148
169
149
- const boardOnAppearedPort = newBoards . find ( ( board : Board ) =>
150
- Port . sameAs ( board . port , appearedPort )
151
- ) ;
170
+ if (
171
+ boardOnAppearedPort &&
172
+ this . lastBoardsConfigOnUpload . selectedBoard &&
173
+ Board . sameAs (
174
+ boardOnAppearedPort ,
175
+ this . lastBoardsConfigOnUpload . selectedBoard
176
+ )
177
+ ) {
178
+ this . setLastBoardsConfigOnUpload ( undefined ) ;
179
+ this . setAvailablePortsOnUpload ( undefined ) ;
152
180
153
- if (
154
- boardOnAppearedPort &&
155
- lastSelectionOnUpload . selectedBoard &&
156
- Board . sameAs ( boardOnAppearedPort , lastSelectionOnUpload . selectedBoard )
157
- ) {
158
- this . boardConfigToAutoSelect = {
159
- selectedBoard : boardOnAppearedPort ,
160
- selectedPort : appearedPort ,
161
- } ;
162
- return ;
181
+ this . boardConfigToAutoSelect = {
182
+ selectedBoard : boardOnAppearedPort ,
183
+ selectedPort : port ,
184
+ } ;
185
+ return ;
186
+ }
163
187
}
164
188
}
165
189
}
@@ -176,7 +200,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
176
200
const { uploadInProgress } = event ;
177
201
178
202
if ( ! uploadInProgress ) {
179
- this . deriveBoardConfigToAutoSelect ( event ) ;
203
+ this . deriveBoardConfigToAutoSelect ( event . newState ) ;
180
204
}
181
205
182
206
this . _attachedBoards = event . newState . boards ;
0 commit comments