Skip to content
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

Close WebSocket connection after closing Serial Plotter #1702

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class MonitorWidget extends ReactWidget {
this.monitorManagerProxy.startMonitor();
}

protected override onAfterAttach(msg: Message): void {
this.monitorManagerProxy.setMonitorWidgetStatus(this.isAttached);
kittaakos marked this conversation as resolved.
Show resolved Hide resolved
}

onMonitorSettingsDidChange(settings: MonitorSettings): void {
this.settings = {
...this.settings,
Expand All @@ -91,6 +95,7 @@ export class MonitorWidget extends ReactWidget {
}

override dispose(): void {
this.monitorManagerProxy.setMonitorWidgetStatus(this.isAttached);
super.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down
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
Expand Up @@ -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;
}
Expand Down