Skip to content

Close WebSocket connection after closing Serial Plotter #1702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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();
}

Original file line number Diff line number Diff line change
@@ -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;
}
});
2 changes: 2 additions & 0 deletions arduino-ide-extension/src/common/protocol/monitor-service.ts
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@ export interface MonitorManagerProxyClient {
isWSConnected(): Promise<boolean>;
startMonitor(settings?: PluggableMonitorSettings): Promise<void>;
getCurrentSettings(board: Board, port: Port): Promise<MonitorSettings>;
setMonitorWidgetStatus(value: boolean): void;
getMonitorWidgetStatus(): boolean;
send(message: string): void;
changeSettings(settings: MonitorSettings): void;
}