From a92a86a924e02b43ff82a1c0a4ed78d8d840400e Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Fri, 27 Dec 2024 11:31:12 +1100 Subject: [PATCH] raise variable browser window, if already created, otherwise create a new window. For #1775. --- gui-js/apps/minsky-electron/src/app/app.ts | 1 + .../src/app/managers/WindowManager.ts | 25 ++++++++++++++++--- .../shared/src/lib/interfaces/ActiveWindow.ts | 3 ++- .../shared/src/lib/interfaces/Interfaces.ts | 1 + .../lib/wiring/variable/variable.component.ts | 19 +++++++------- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/gui-js/apps/minsky-electron/src/app/app.ts b/gui-js/apps/minsky-electron/src/app/app.ts index 632ed57aa..8e55f10ff 100644 --- a/gui-js/apps/minsky-electron/src/app/app.ts +++ b/gui-js/apps/minsky-electron/src/app/app.ts @@ -149,6 +149,7 @@ export default class App { context: App.mainWindow, systemWindowId: WindowManager.getSystemWindowId(this.mainWindow), menu: null, + url: "", }; WindowManager.activeWindows.set(App.mainWindow.id, mainWindowDetails); diff --git a/gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts b/gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts index f983398b0..b782f6738 100644 --- a/gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts +++ b/gui-js/apps/minsky-electron/src/app/managers/WindowManager.ts @@ -131,6 +131,19 @@ export class WindowManager { return initialURL; } + /// if window already exists attached to \a url, then raise it + /// @return window if it exists, null otherwise + static raiseWindow(url: string): BrowserWindow { + let window=null; + for (let i of this.activeWindows) + if (i[1].url==url) { + window=i[1].context; + break; + } + if (window) window.show(); + return window; + } + static createPopupWindowWithRouting( payload: CreateWindowPayload, // eslint-disable-next-line @typescript-eslint/ban-types @@ -167,8 +180,6 @@ export class WindowManager { slashes: true, }); - console.log(payload.url); - console.log(filePath); window.loadURL(filePath); return window; } @@ -177,8 +188,14 @@ export class WindowManager { payload: CreateWindowPayload, onCloseCallback?: (ev : Electron.Event) => void ) { - const { width, height, minWidth, minHeight, title, modal = true, backgroundColor=StoreManager.store.get('backgroundColor'), alwaysOnTop } = payload; + const { width, height, minWidth, minHeight, title, modal = true, backgroundColor=StoreManager.store.get('backgroundColor'), alwaysOnTop, url } = payload; + // do not duplicate window if requested and window already exists + if (payload.raiseIfPresent) { + const childWindow=this.raiseWindow(url); + if (childWindow) return childWindow; + } + const childWindow = new BrowserWindow({ width, height, @@ -225,6 +242,7 @@ export class WindowManager { context: childWindow, systemWindowId: windowId, menu: null, + url, }; if (payload.uid) { @@ -264,7 +282,6 @@ export class WindowManager { static onAppLayoutChanged(payload: AppLayoutPayload) { this.topOffset = Math.round(payload.offset.top); - console.log("topOffset=",this.topOffset); this.leftOffset = Math.round(payload.offset.left); this.scaleFactor = screen.getPrimaryDisplay().scaleFactor; if (Functions.isWindows()) diff --git a/gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts b/gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts index 731aeeea6..d5136326f 100644 --- a/gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts +++ b/gui-js/libs/shared/src/lib/interfaces/ActiveWindow.ts @@ -6,5 +6,6 @@ export interface ActiveWindow { isMainWindow: boolean; context: BrowserWindow; systemWindowId: bigint; - menu : Menu + menu: Menu; + url: string; } diff --git a/gui-js/libs/shared/src/lib/interfaces/Interfaces.ts b/gui-js/libs/shared/src/lib/interfaces/Interfaces.ts index da9cd53ee..b7bc26d65 100644 --- a/gui-js/libs/shared/src/lib/interfaces/Interfaces.ts +++ b/gui-js/libs/shared/src/lib/interfaces/Interfaces.ts @@ -132,6 +132,7 @@ export interface CreateWindowPayload { minWidth?: number; minHeight?: number; alwaysOnTop?: boolean; + raiseIfPresent?: boolean; ///< if true, then raise an existing window instead of creating a duplicate } diff --git a/gui-js/libs/ui-components/src/lib/wiring/variable/variable.component.ts b/gui-js/libs/ui-components/src/lib/wiring/variable/variable.component.ts index 2a995abf6..0c8acd8b9 100644 --- a/gui-js/libs/ui-components/src/lib/wiring/variable/variable.component.ts +++ b/gui-js/libs/ui-components/src/lib/wiring/variable/variable.component.ts @@ -42,14 +42,15 @@ export class VariableComponent { }); } } - openVariablePane() { - this.electronService.send(events.CREATE_MENU_POPUP, { - title: 'Variables', - url: "#/headless/variable-pane", - width: 400, - height: 450, - alwaysOnTop: true, - modal: false, - }); + openVariablePane() { + this.electronService.send(events.CREATE_MENU_POPUP, { + title: 'Variables', + url: "#/headless/variable-pane", + width: 400, + height: 450, + alwaysOnTop: true, + modal: false, + raiseIfPresent: true, + }); } }