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

This commit is contained in:
Abdullah Atta
2023-08-05 12:10:47 +05:00
parent 9951b83539
commit 80d2f64f10

View File

@@ -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();