Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

desktop: bring app to front on start of 2nd instance

Abdullah Atta80d2f64f10b9
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();