From 79731304c16c9d2c8efb0887a2197587519201b1 Mon Sep 17 00:00:00 2001 From: jbicker Date: Tue, 20 Aug 2019 14:32:42 +0200 Subject: [PATCH] Reestablish monitor connection after reloading the window, reconnect after selecting another board Signed-off-by: jbicker --- .../src/browser/monitor/monitor-widget.tsx | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx b/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx index eb39641f..84425bff 100644 --- a/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx +++ b/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx @@ -195,22 +195,29 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget { super.onAfterAttach(msg); this.clear(); this.connect(); - this.toDisposeOnDetach.push(this.boardsServiceClient.onBoardsChanged(async states => { - const currentConnectionConfig = this.connection.connectionConfig; - const connectedBoard = states.newState.boards - .filter(AttachedSerialBoard.is) - .find(board => { - const potentiallyConnected = currentConnectionConfig && currentConnectionConfig.board; - if (AttachedSerialBoard.is(potentiallyConnected)) { - return Board.equals(board, potentiallyConnected) && board.port === potentiallyConnected.port; - } - return false; - }); - if (connectedBoard && currentConnectionConfig) { - this.continuePreviousConnection = true; - this.connection.connect(currentConnectionConfig); - } - })); + this.toDisposeOnDetach.push( + this.boardsServiceClient.onBoardsChanged(async states => { + const currentConnectionConfig = this.connection.connectionConfig; + const connectedBoard = states.newState.boards + .filter(AttachedSerialBoard.is) + .find(board => { + const potentiallyConnected = currentConnectionConfig && currentConnectionConfig.board; + if (AttachedSerialBoard.is(potentiallyConnected)) { + return Board.equals(board, potentiallyConnected) && board.port === potentiallyConnected.port; + } + return false; + }); + if (connectedBoard && currentConnectionConfig) { + this.continuePreviousConnection = true; + this.connection.connect(currentConnectionConfig); + } + }) + ); + this.toDisposeOnDetach.push( + this.boardsServiceClient.onBoardsConfigChanged(async boardConfig => { + this.connect(); + }) + ) this.toDisposeOnDetach.push(this.connection.onConnectionChanged(() => { if (!this.continuePreviousConnection) { @@ -255,7 +262,6 @@ export class MonitorWidget extends ReactWidget implements StatefulWidget { const attachedBoards = await this.boardsService.getAttachedBoards(); const connectedBoard = attachedBoards.boards.filter(AttachedSerialBoard.is).find(board => BoardsConfig.Config.sameAs(boardsConfig, board)); if (!connectedBoard) { - this.messageService.warn(`The selected '${name}' board is not connected on ${selectedPort}.`); return; }