From 6afc5e06d6f1378d57034a3b9ee8f4fe26b12812 Mon Sep 17 00:00:00 2001 From: MasterAcnolo <68693319+MasterAcnolo@users.noreply.github.com> Date: Sun, 31 May 2026 15:48:20 +0200 Subject: [PATCH] fix: app startup. Can't start another instance now. --- main.js | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index 04ecc5f..c5ebbc2 100644 --- a/main.js +++ b/main.js @@ -9,6 +9,23 @@ process.on("unhandledRejection", (reason) => { }); const { app } = require("electron"); + +/** + * True if this is the primary instance (lock acquired successfully) + */ +const isPrimaryInstance = app.requestSingleInstanceLock(); + +/** + * If we are on a second instance + */ +if (!isPrimaryInstance) { + app.quit(); + process.exit(0); +} + +/** + * Load the app + */ const { createSplashWindow, closeSplashWindow, setSplashProgress } = require("./app/splashManager"); const path = require("path"); @@ -30,15 +47,22 @@ app.setName("Freedom Loader"); app.setAppUserModelId("com.masteracnolo.freedomloader"); app.disableHardwareAcceleration(); -if (!config.devMode) { - const gotLock = app.requestSingleInstanceLock(); - if (gotLock) { - app.on("second-instance", () => { - logger.info("New instance detected, closing older..."); - getMainWindow()?.destroy(); - }); - } -} + +/** + * If another instance want to run + */ +app.on("second-instance", () => { + logger.info("Second instance detected"); + + const mainWindow = require("./app/windowManager").getMainWindow(); + + if (!mainWindow) return; + + if (mainWindow.isMinimized()) mainWindow.restore(); + + mainWindow.show(); + mainWindow.focus(); +}); app.whenReady().then(async () => { logSessionStart();