From 0829a68390cc57722b8b1604ca25955c4a76bcd7 Mon Sep 17 00:00:00 2001 From: Alberto Iannaccone Date: Wed, 7 Sep 2022 12:30:48 +0200 Subject: [PATCH] use ipc message to focus on serial plotter window --- .../plotter/plotter-frontend-contribution.ts | 8 ++++++-- .../src/common/ipc-communication.ts | 2 ++ .../theia/electron-main-application.ts | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 arduino-ide-extension/src/common/ipc-communication.ts 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 2a7c0a23f..3914c061a 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 @@ -14,6 +14,10 @@ import { MonitorManagerProxyClient } from '../../../common/protocol'; import { BoardsServiceProvider } from '../../boards/boards-service-provider'; import { MonitorModel } from '../../monitor-model'; import { ArduinoToolbar } from '../../toolbar/arduino-toolbar'; +import { + CLOSE_PLOTTER_WINDOW, + SHOW_PLOTTER_WINDOW, +} from '../../../common/ipc-communication'; const queryString = require('query-string'); @@ -58,7 +62,7 @@ export class PlotterFrontendContribution extends Contribution { override onStart(app: FrontendApplication): MaybePromise { this.url = new Endpoint({ path: '/plotter' }).getRestUrl().toString(); - ipcRenderer.on('CLOSE_CHILD_WINDOW', async () => { + ipcRenderer.on(CLOSE_PLOTTER_WINDOW, async () => { if (!!this.window) { this.window = null; } @@ -96,7 +100,7 @@ export class PlotterFrontendContribution extends Contribution { async startPlotter(): Promise { await this.monitorManagerProxy.startMonitor(); if (!!this.window) { - this.window.focus(); + ipcRenderer.send(SHOW_PLOTTER_WINDOW); return; } const wsPort = this.monitorManagerProxy.getWebSocketPort(); diff --git a/arduino-ide-extension/src/common/ipc-communication.ts b/arduino-ide-extension/src/common/ipc-communication.ts new file mode 100644 index 000000000..826daf532 --- /dev/null +++ b/arduino-ide-extension/src/common/ipc-communication.ts @@ -0,0 +1,2 @@ +export const SHOW_PLOTTER_WINDOW = 'SHOW_PLOTTER_WINDOW'; +export const CLOSE_PLOTTER_WINDOW = 'CLOSE_PLOTTER_WINDOW'; diff --git a/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts b/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts index 981c5ad68..bb85405b3 100644 --- a/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts +++ b/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts @@ -23,6 +23,10 @@ import * as os from '@theia/core/lib/common/os'; import { Restart } from '@theia/core/lib/electron-common/messaging/electron-messages'; import { TheiaBrowserWindowOptions } from '@theia/core/lib/electron-main/theia-electron-window'; import { IsTempSketch } from '../../node/is-temp-sketch'; +import { + CLOSE_PLOTTER_WINDOW, + SHOW_PLOTTER_WINDOW, +} from '../../common/ipc-communication'; app.commandLine.appendSwitch('disable-http-cache'); @@ -324,15 +328,21 @@ export class ElectronMainApplication extends TheiaElectronMainApplication { webPreferences: { devTools: true, nativeWindowOpen: true, - openerId: electronWindow?.webContents.id, + openerId: electronWindow.webContents.id, }, }); event.newGuest = new BrowserWindow(options); + + const showPlotterWindow = () => { + event.newGuest?.show(); + }; + ipcMain.on(SHOW_PLOTTER_WINDOW, showPlotterWindow); event.newGuest.setMenu(null); - event.newGuest?.on('closed', () => { - electronWindow?.webContents.send('CLOSE_CHILD_WINDOW'); + event.newGuest.on('closed', () => { + ipcMain.removeListener(SHOW_PLOTTER_WINDOW, showPlotterWindow); + electronWindow.webContents.send(CLOSE_PLOTTER_WINDOW); }); - event.newGuest?.loadURL(url); + event.newGuest.loadURL(url); } } );