diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 01f4f3b48..b69bf73d9 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -33,6 +33,13 @@ import { createIPCHandler } from "electron-trpc/main"; import { router, api } from "./api"; import { config } from "./utils/config"; import path from "path"; +import { bringToFront } from "./utils/bring-to-front"; + +// only run a single instance +if (!MAC_APP_STORE && !app.requestSingleInstanceLock()) { + console.log("Another instance is already running!"); + app.exit(); +} if (process.platform == "win32" && process.env.PORTABLE_EXECUTABLE_DIR) { console.log("Portable app: true"); @@ -42,11 +49,6 @@ if (process.platform == "win32" && process.env.PORTABLE_EXECUTABLE_DIR) { app.setPath("userData", path.join(root, "UserData")); } -// only run a single instance -if (!MAC_APP_STORE && !app.requestSingleInstanceLock()) { - app.exit(); -} - if (process.platform === "win32") { app.setAppUserModelId(app.name); } @@ -137,6 +139,11 @@ app.once("window-all-closed", () => { } }); +app.on("second-instance", () => { + if (!globalThis.window) return; + bringToFront(); +}); + app.on("activate", () => { if (globalThis.window === null) { createWindow();