diff --git a/arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts b/arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts index 94ab4d0f5..1f40a5f2c 100644 --- a/arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts +++ b/arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts @@ -46,6 +46,7 @@ export class MonitorManagerProxyClientImpl private wsPort?: number; private lastConnectedBoard: BoardsConfig.Config; private onBoardsConfigChanged: Disposable | undefined; + private isMonitorWidgetOpen = false; getWebSocketPort(): number | undefined { return this.wsPort; @@ -174,6 +175,14 @@ export class MonitorManagerProxyClientImpl return this.server().getCurrentSettings(board, port); } + setMonitorWidgetStatus(value: boolean): void { + this.isMonitorWidgetOpen = value; + } + + getMonitorWidgetStatus(): boolean { + return this.isMonitorWidgetOpen; + } + send(message: string): void { if (!this.webSocket) { return; diff --git a/arduino-ide-extension/src/browser/serial/monitor/monitor-widget.tsx b/arduino-ide-extension/src/browser/serial/monitor/monitor-widget.tsx index f9aba5ed4..9b913ef57 100644 --- a/arduino-ide-extension/src/browser/serial/monitor/monitor-widget.tsx +++ b/arduino-ide-extension/src/browser/serial/monitor/monitor-widget.tsx @@ -74,6 +74,10 @@ export class MonitorWidget extends ReactWidget { this.monitorManagerProxy.startMonitor(); } + protected override onAfterAttach(msg: Message): void { + this.monitorManagerProxy.setMonitorWidgetStatus(this.isAttached); + } + onMonitorSettingsDidChange(settings: MonitorSettings): void { this.settings = { ...this.settings, @@ -91,6 +95,7 @@ export class MonitorWidget extends ReactWidget { } override dispose(): void { + this.monitorManagerProxy.setMonitorWidgetStatus(this.isAttached); super.dispose(); } diff --git a/arduino-ide-extension/src/browser/serial/plotter/plotter-frontend-contribution.ts b/arduino-ide-extension/src/browser/serial/plotter/plotter-frontend-contribution.ts index c403c4201..70cdfa1ed 100644 --- a/arduino-ide-extension/src/browser/serial/plotter/plotter-frontend-contribution.ts +++ b/arduino-ide-extension/src/browser/serial/plotter/plotter-frontend-contribution.ts @@ -65,6 +65,9 @@ export class PlotterFrontendContribution extends Contribution { ipcRenderer.on(CLOSE_PLOTTER_WINDOW, async () => { if (!!this.window) { + if (!this.monitorManagerProxy.getMonitorWidgetStatus()) { + this.monitorManagerProxy.disconnect(); + } this.window = null; } }); diff --git a/arduino-ide-extension/src/common/protocol/monitor-service.ts b/arduino-ide-extension/src/common/protocol/monitor-service.ts index 7374951db..dbbc77562 100644 --- a/arduino-ide-extension/src/common/protocol/monitor-service.ts +++ b/arduino-ide-extension/src/common/protocol/monitor-service.ts @@ -37,6 +37,8 @@ export interface MonitorManagerProxyClient { isWSConnected(): Promise; startMonitor(settings?: PluggableMonitorSettings): Promise; getCurrentSettings(board: Board, port: Port): Promise; + setMonitorWidgetStatus(value: boolean): void; + getMonitorWidgetStatus(): boolean; send(message: string): void; changeSettings(settings: MonitorSettings): void; }