Reestablish monitor connection after reloading the window, reconnect after selecting another board

Signed-off-by: jbicker <jan.bicker@typefox.io>
This commit is contained in:
jbicker 2019-08-20 14:32:42 +02:00
parent 2046c0bdee
commit 79731304c1

View File

@ -195,22 +195,29 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
super.onAfterAttach(msg); super.onAfterAttach(msg);
this.clear(); this.clear();
this.connect(); this.connect();
this.toDisposeOnDetach.push(this.boardsServiceClient.onBoardsChanged(async states => { this.toDisposeOnDetach.push(
const currentConnectionConfig = this.connection.connectionConfig; this.boardsServiceClient.onBoardsChanged(async states => {
const connectedBoard = states.newState.boards const currentConnectionConfig = this.connection.connectionConfig;
.filter(AttachedSerialBoard.is) const connectedBoard = states.newState.boards
.find(board => { .filter(AttachedSerialBoard.is)
const potentiallyConnected = currentConnectionConfig && currentConnectionConfig.board; .find(board => {
if (AttachedSerialBoard.is(potentiallyConnected)) { const potentiallyConnected = currentConnectionConfig && currentConnectionConfig.board;
return Board.equals(board, potentiallyConnected) && board.port === potentiallyConnected.port; if (AttachedSerialBoard.is(potentiallyConnected)) {
} return Board.equals(board, potentiallyConnected) && board.port === potentiallyConnected.port;
return false; }
}); return false;
if (connectedBoard && currentConnectionConfig) { });
this.continuePreviousConnection = true; if (connectedBoard && currentConnectionConfig) {
this.connection.connect(currentConnectionConfig); this.continuePreviousConnection = true;
} this.connection.connect(currentConnectionConfig);
})); }
})
);
this.toDisposeOnDetach.push(
this.boardsServiceClient.onBoardsConfigChanged(async boardConfig => {
this.connect();
})
)
this.toDisposeOnDetach.push(this.connection.onConnectionChanged(() => { this.toDisposeOnDetach.push(this.connection.onConnectionChanged(() => {
if (!this.continuePreviousConnection) { if (!this.continuePreviousConnection) {
@ -255,7 +262,6 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget {
const attachedBoards = await this.boardsService.getAttachedBoards(); const attachedBoards = await this.boardsService.getAttachedBoards();
const connectedBoard = attachedBoards.boards.filter(AttachedSerialBoard.is).find(board => BoardsConfig.Config.sameAs(boardsConfig, board)); const connectedBoard = attachedBoards.boards.filter(AttachedSerialBoard.is).find(board => BoardsConfig.Config.sameAs(boardsConfig, board));
if (!connectedBoard) { if (!connectedBoard) {
this.messageService.warn(`The selected '${name}' board is not connected on ${selectedPort}.`);
return; return;
} }