mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-15 04:32:13 +00:00
feat: prevent multiple editor windows for the same theme
This commit is contained in:
parent
e49a32166a
commit
61d4910b6d
1 changed files with 14 additions and 0 deletions
|
@ -23,6 +23,8 @@ import { AuthPage } from "@shared";
|
||||||
export class WindowManager {
|
export class WindowManager {
|
||||||
public static mainWindow: Electron.BrowserWindow | null = null;
|
public static mainWindow: Electron.BrowserWindow | null = null;
|
||||||
|
|
||||||
|
private static editorWindows: Map<string, BrowserWindow> = new Map();
|
||||||
|
|
||||||
private static loadMainWindowURL(hash = "") {
|
private static loadMainWindowURL(hash = "") {
|
||||||
// HMR for renderer base on electron-vite cli.
|
// HMR for renderer base on electron-vite cli.
|
||||||
// Load the remote URL for development or the local html file for production.
|
// 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) {
|
public static openEditorWindow(themeId: string) {
|
||||||
if (this.mainWindow) {
|
if (this.mainWindow) {
|
||||||
|
const existingWindow = this.editorWindows.get(themeId);
|
||||||
|
if (existingWindow) {
|
||||||
|
if (existingWindow.isMinimized()) {
|
||||||
|
existingWindow.restore();
|
||||||
|
}
|
||||||
|
existingWindow.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const editorWindow = new BrowserWindow({
|
const editorWindow = new BrowserWindow({
|
||||||
width: 600,
|
width: 600,
|
||||||
height: 720,
|
height: 720,
|
||||||
|
@ -217,6 +228,8 @@ export class WindowManager {
|
||||||
show: false,
|
show: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.editorWindows.set(themeId, editorWindow);
|
||||||
|
|
||||||
editorWindow.removeMenu();
|
editorWindow.removeMenu();
|
||||||
|
|
||||||
if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
|
if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
|
||||||
|
@ -237,6 +250,7 @@ export class WindowManager {
|
||||||
|
|
||||||
editorWindow.on("close", () => {
|
editorWindow.on("close", () => {
|
||||||
WindowManager.mainWindow?.webContents.closeDevTools();
|
WindowManager.mainWindow?.webContents.closeDevTools();
|
||||||
|
this.editorWindows.delete(themeId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue