From 61d4910b6dd3cb639dff6affa28c4e52bce48d5f Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Thu, 30 Jan 2025 02:31:06 -0300 Subject: [PATCH] feat: prevent multiple editor windows for the same theme --- src/main/services/window-manager.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index 5f599e1b..0fb33f15 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -23,6 +23,8 @@ import { AuthPage } from "@shared"; export class WindowManager { public static mainWindow: Electron.BrowserWindow | null = null; + private static editorWindows: Map = new Map(); + private static loadMainWindowURL(hash = "") { // HMR for renderer base on electron-vite cli. // Load the remote URL for development or the local html file for production. @@ -196,6 +198,15 @@ export class WindowManager { public static openEditorWindow(themeId: string) { if (this.mainWindow) { + const existingWindow = this.editorWindows.get(themeId); + if (existingWindow) { + if (existingWindow.isMinimized()) { + existingWindow.restore(); + } + existingWindow.focus(); + return; + } + const editorWindow = new BrowserWindow({ width: 600, height: 720, @@ -217,6 +228,8 @@ export class WindowManager { show: false, }); + this.editorWindows.set(themeId, editorWindow); + editorWindow.removeMenu(); if (is.dev && process.env["ELECTRON_RENDERER_URL"]) { @@ -237,6 +250,7 @@ export class WindowManager { editorWindow.on("close", () => { WindowManager.mainWindow?.webContents.closeDevTools(); + this.editorWindows.delete(themeId); }); } }