@@ -65,11 +65,12 @@ 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 ;
69
68
// "lastPersistingUploadPort", is a port created during an upload, that persisted after
70
69
// the upload finished, it's "substituting" the port selected when the user invoked the upload
71
70
private lastPersistingUploadPort : Port | undefined ;
72
71
72
+ private lastSelectionOnUpload : BoardsConfig . Config | undefined ;
73
+
73
74
/**
74
75
* Unlike `onAttachedBoardsChanged` this even fires when the user modifies the selected board in the IDE.\
75
76
* This even also fires, when the boards package was not available for the currently selected board,
@@ -116,62 +117,43 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
116
117
return this . _reconciled . promise ;
117
118
}
118
119
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
- }
120
+ public setLastSelectionOnUpload (
121
+ config : BoardsConfig . Config | undefined
122
+ ) : void {
123
+ this . lastSelectionOnUpload = config ;
124
+ }
138
125
126
+ private checkForPersistingPort ( event : AttachedBoardsChangeEvent ) : void {
127
+ if ( ! this . lastSelectionOnUpload ) {
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 . lastSelectionOnUpload ;
132
+ this . lastSelectionOnUpload = 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,9 +167,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
185
167
186
168
const { uploadInProgress } = event ;
187
169
188
- if ( uploadInProgress ) {
189
- this . checkForItemRemoved ( event ) ;
190
- } else {
170
+ if ( ! uploadInProgress ) {
191
171
this . checkForPersistingPort ( event ) ;
192
172
}
193
173
0 commit comments