mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
fix: app startup. Can't start another instance now.
This commit is contained in:
38
main.js
38
main.js
@@ -9,6 +9,23 @@ process.on("unhandledRejection", (reason) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { app } = require("electron");
|
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 { createSplashWindow, closeSplashWindow, setSplashProgress } = require("./app/splashManager");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
@@ -30,15 +47,22 @@ app.setName("Freedom Loader");
|
|||||||
app.setAppUserModelId("com.masteracnolo.freedomloader");
|
app.setAppUserModelId("com.masteracnolo.freedomloader");
|
||||||
app.disableHardwareAcceleration();
|
app.disableHardwareAcceleration();
|
||||||
|
|
||||||
if (!config.devMode) {
|
|
||||||
const gotLock = app.requestSingleInstanceLock();
|
/**
|
||||||
if (gotLock) {
|
* If another instance want to run
|
||||||
|
*/
|
||||||
app.on("second-instance", () => {
|
app.on("second-instance", () => {
|
||||||
logger.info("New instance detected, closing older...");
|
logger.info("Second instance detected");
|
||||||
getMainWindow()?.destroy();
|
|
||||||
|
const mainWindow = require("./app/windowManager").getMainWindow();
|
||||||
|
|
||||||
|
if (!mainWindow) return;
|
||||||
|
|
||||||
|
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||||
|
|
||||||
|
mainWindow.show();
|
||||||
|
mainWindow.focus();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
logSessionStart();
|
logSessionStart();
|
||||||
|
|||||||
Reference in New Issue
Block a user