@@ -65,7 +65,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
65
65
protected _availablePorts : Port [ ] = [ ] ;
66
66
protected _availableBoards : AvailableBoard [ ] = [ ] ;
67
67
68
- private lastItemRemovedForUpload : { board : Board ; port : Port } | undefined ;
68
+ private lastBoardsConfigOnUpload : BoardsConfig . Config | undefined ;
69
69
// "lastPersistingUploadPort", is a port created during an upload, that persisted after
70
70
// the upload finished, it's "substituting" the port selected when the user invoked the upload
71
71
private lastPersistingUploadPort : Port | undefined ;
@@ -116,62 +116,44 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
116
116
return this . _reconciled . promise ;
117
117
}
118
118
119
- private checkForItemRemoved ( event : AttachedBoardsChangeEvent ) : void {
120
- if ( ! this . lastItemRemovedForUpload ) {
121
- const {
122
- oldState : { ports : oldPorts , boards : oldBoards } ,
123
- newState : { ports : newPorts } ,
124
- } = event ;
125
-
126
- const disappearedPorts = oldPorts . filter ( ( oldPort : Port ) =>
127
- newPorts . every ( ( newPort : Port ) => ! Port . sameAs ( oldPort , newPort ) )
128
- ) ;
129
-
130
- if ( disappearedPorts . length > 0 ) {
131
- this . lastItemRemovedForUpload = {
132
- board : oldBoards . find ( ( board : Board ) =>
133
- Port . sameAs ( board . port , disappearedPorts [ 0 ] )
134
- ) as Board ,
135
- port : disappearedPorts [ 0 ] ,
136
- } ;
137
- }
119
+ public setLastBoardsConfigOnUpload (
120
+ value : BoardsConfig . Config | undefined
121
+ ) : void {
122
+ this . lastBoardsConfigOnUpload = value ;
123
+ }
138
124
125
+ private derivePersistingUploadPort ( event : AttachedBoardsChangeEvent ) : void {
126
+ if ( ! this . lastBoardsConfigOnUpload ) {
127
+ this . lastPersistingUploadPort = undefined ;
139
128
return ;
140
129
}
141
- }
142
130
143
- private checkForPersistingPort ( event : AttachedBoardsChangeEvent ) : void {
144
- if ( this . lastItemRemovedForUpload ) {
145
- const {
146
- oldState : { ports : oldPorts } ,
147
- newState : { ports : newPorts , boards : newBoards } ,
148
- } = event ;
131
+ const lastSelectionOnUpload = this . lastBoardsConfigOnUpload ;
132
+ this . setLastBoardsConfigOnUpload ( undefined ) ;
149
133
150
- const disappearedItem = this . lastItemRemovedForUpload ;
151
- this . lastItemRemovedForUpload = undefined ;
134
+ const {
135
+ oldState : { ports : oldPorts } ,
136
+ newState : { ports : newPorts , boards : newBoards } ,
137
+ } = event ;
152
138
153
- const appearedPorts = newPorts . filter ( ( newPort : Port ) =>
154
- oldPorts . every ( ( oldPort : Port ) => ! Port . sameAs ( newPort , oldPort ) )
155
- ) ;
139
+ const appearedPorts = newPorts . filter ( ( newPort : Port ) =>
140
+ oldPorts . every ( ( oldPort : Port ) => ! Port . sameAs ( newPort , oldPort ) )
141
+ ) ;
156
142
157
- if ( appearedPorts . length > 0 ) {
158
- const boardOnAppearedPort = newBoards . find ( ( board : Board ) =>
159
- Port . sameAs ( board . port , appearedPorts [ 0 ] )
160
- ) ;
143
+ if ( appearedPorts . length > 0 ) {
144
+ const boardOnAppearedPort = newBoards . find ( ( board : Board ) =>
145
+ Port . sameAs ( board . port , appearedPorts [ 0 ] )
146
+ ) ;
161
147
162
- if (
163
- boardOnAppearedPort &&
164
- Board . sameAs ( boardOnAppearedPort , disappearedItem . board )
165
- ) {
166
- this . lastPersistingUploadPort = appearedPorts [ 0 ] ;
167
- return ;
168
- }
148
+ if (
149
+ boardOnAppearedPort &&
150
+ lastSelectionOnUpload . selectedBoard &&
151
+ Board . sameAs ( boardOnAppearedPort , lastSelectionOnUpload . selectedBoard )
152
+ ) {
153
+ this . lastPersistingUploadPort = appearedPorts [ 0 ] ;
154
+ return ;
169
155
}
170
-
171
- return ;
172
156
}
173
-
174
- this . lastPersistingUploadPort = undefined ;
175
157
}
176
158
177
159
protected notifyAttachedBoardsChanged (
@@ -185,10 +167,8 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
185
167
186
168
const { uploadInProgress } = event ;
187
169
188
- if ( uploadInProgress ) {
189
- this . checkForItemRemoved ( event ) ;
190
- } else {
191
- this . checkForPersistingPort ( event ) ;
170
+ if ( ! uploadInProgress ) {
171
+ this . derivePersistingUploadPort ( event ) ;
192
172
}
193
173
194
174
this . _attachedBoards = event . newState . boards ;
0 commit comments