Skip to content

Commit 99b1094

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Listen on the client's port change event
If the board select dialog is listening on the backend's event, the frontend might miss the event when it comes up, although boards are connected and ports are discovered. Closes arduino#573 Signed-off-by: Akos Kitta <[email protected]>
1 parent 960a2d0 commit 99b1094

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

arduino-ide-extension/src/browser/boards/boards-config.tsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { DisposableCollection } from '@theia/core/lib/common/disposable';
66
import {
77
Board,
88
Port,
9-
AttachedBoardsChangeEvent,
109
BoardWithPackage,
1110
} from '../../common/protocol/boards-service';
1211
import { NotificationCenter } from '../notification-center';
@@ -113,11 +112,14 @@ export class BoardsConfig extends React.Component<
113112
);
114113
}
115114
}),
116-
this.props.notificationCenter.onAttachedBoardsDidChange((event) =>
117-
this.updatePorts(
118-
event.newState.ports,
119-
AttachedBoardsChangeEvent.diff(event).detached.ports
120-
)
115+
this.props.boardsServiceProvider.onAvailablePortsChanged(
116+
({ newState, oldState }) => {
117+
const removedPorts = oldState.filter(
118+
(oldPort) =>
119+
!newState.find((newPort) => Port.sameAs(newPort, oldPort))
120+
);
121+
this.updatePorts(newState, removedPorts);
122+
}
121123
),
122124
this.props.boardsServiceProvider.onBoardsConfigChanged(
123125
({ selectedBoard, selectedPort }) => {

arduino-ide-extension/src/browser/boards/boards-service-provider.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ export class BoardsServiceProvider
6363
protected readonly onAvailableBoardsChangedEmitter = new Emitter<
6464
AvailableBoard[]
6565
>();
66-
protected readonly onAvailablePortsChangedEmitter = new Emitter<Port[]>();
66+
protected readonly onAvailablePortsChangedEmitter = new Emitter<{
67+
newState: Port[];
68+
oldState: Port[];
69+
}>();
6770
private readonly inheritedConfig = new Deferred<BoardsConfig.Config>();
6871

6972
/**
@@ -120,8 +123,12 @@ export class BoardsServiceProvider
120123
const { boards: attachedBoards, ports: availablePorts } =
121124
AvailablePorts.split(state);
122125
this._attachedBoards = attachedBoards;
126+
const oldState = this._availablePorts.slice();
123127
this._availablePorts = availablePorts;
124-
this.onAvailablePortsChangedEmitter.fire(this._availablePorts);
128+
this.onAvailablePortsChangedEmitter.fire({
129+
newState: this._availablePorts.slice(),
130+
oldState,
131+
});
125132

126133
await this.reconcileAvailableBoards();
127134

@@ -229,8 +236,12 @@ export class BoardsServiceProvider
229236
}
230237

231238
this._attachedBoards = event.newState.boards;
239+
const oldState = this._availablePorts.slice();
232240
this._availablePorts = event.newState.ports;
233-
this.onAvailablePortsChangedEmitter.fire(this._availablePorts);
241+
this.onAvailablePortsChangedEmitter.fire({
242+
newState: this._availablePorts.slice(),
243+
oldState,
244+
});
234245
this.reconcileAvailableBoards().then(() => {
235246
const { uploadInProgress } = event;
236247
// avoid attempting "auto-selection" while an

0 commit comments

Comments
 (0)