@@ -65,7 +65,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
6565 protected _availablePorts : Port [ ] = [ ] ;
6666 protected _availableBoards : AvailableBoard [ ] = [ ] ;
6767
68- private lastItemRemovedForUpload : { board : Board ; port : Port } | undefined ;
68+ private lastBoardsConfigOnUpload : BoardsConfig . Config | undefined ;
6969 // "lastPersistingUploadPort", is a port created during an upload, that persisted after
7070 // the upload finished, it's "substituting" the port selected when the user invoked the upload
7171 private lastPersistingUploadPort : Port | undefined ;
@@ -116,62 +116,44 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
116116 return this . _reconciled . promise ;
117117 }
118118
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+ }
138124
125+ private derivePersistingUploadPort ( event : AttachedBoardsChangeEvent ) : void {
126+ if ( ! this . lastBoardsConfigOnUpload ) {
127+ this . lastPersistingUploadPort = undefined ;
139128 return ;
140129 }
141- }
142130
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 ) ;
149133
150- const disappearedItem = this . lastItemRemovedForUpload ;
151- this . lastItemRemovedForUpload = undefined ;
134+ const {
135+ oldState : { ports : oldPorts } ,
136+ newState : { ports : newPorts , boards : newBoards } ,
137+ } = event ;
152138
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+ ) ;
156142
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+ ) ;
161147
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 ;
169155 }
170-
171- return ;
172156 }
173-
174- this . lastPersistingUploadPort = undefined ;
175157 }
176158
177159 protected notifyAttachedBoardsChanged (
@@ -185,10 +167,8 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
185167
186168 const { uploadInProgress } = event ;
187169
188- if ( uploadInProgress ) {
189- this . checkForItemRemoved ( event ) ;
190- } else {
191- this . checkForPersistingPort ( event ) ;
170+ if ( ! uploadInProgress ) {
171+ this . derivePersistingUploadPort ( event ) ;
192172 }
193173
194174 this . _attachedBoards = event . newState . boards ;
0 commit comments