fix: app startup. Can't start another instance now.

This commit is contained in:
MasterAcnolo
2026-05-31 15:48:20 +02:00
parent 519dcad6e6
commit 6afc5e06d6

38
main.js
View File

@@ -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) {
/**
* If another instance want to run
*/
app.on("second-instance", () => {
logger.info("New instance detected, closing older...");
getMainWindow()?.destroy();
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();