use ipc message to focus on serial plotter window (#1410)

This commit is contained in:
Alberto Iannaccone 2022-09-15 16:07:13 +02:00 committed by GitHub
parent 026e80e7fc
commit 4e590ab618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

View File

@ -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<void> {
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<void> {
await this.monitorManagerProxy.startMonitor();
if (!!this.window) {
this.window.focus();
ipcRenderer.send(SHOW_PLOTTER_WINDOW);
return;
}
const wsPort = this.monitorManagerProxy.getWebSocketPort();

View File

@ -0,0 +1,2 @@
export const SHOW_PLOTTER_WINDOW = 'SHOW_PLOTTER_WINDOW';
export const CLOSE_PLOTTER_WINDOW = 'CLOSE_PLOTTER_WINDOW';

View File

@ -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);
}
}
);