mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-09-27 20:11:15 +02:00
refactor: extract shutdown logic in a function, rename server => serverInstance and now we stop the server smoothly
This commit is contained in:
38
main.js
38
main.js
@@ -76,6 +76,7 @@ const { registerIpcHandlers } = require("./app/ipcHandlers");
|
||||
const { createSplashWindow, closeSplashWindow, setSplashProgress } = require("./app/splashManager");
|
||||
const { userThemesPath, initUserThemes, isWindows, validateBinaries, defaultDownloadFolder } = require("./server/helpers/path.helpers");
|
||||
const {createSystemTray, destroyTray} = require("./app/tray");
|
||||
const { stopServer } = require("./server/server");
|
||||
|
||||
/**
|
||||
* Global flag indicating if the application is intentionally shutting down.
|
||||
@@ -91,6 +92,28 @@ app.isQuitting = false;
|
||||
*/
|
||||
let isCleanedUp = false;
|
||||
|
||||
/**
|
||||
* Performs a graceful shutdown of all application services asynchronously.
|
||||
* Once finished, it re-triggers the app.quit() process.
|
||||
*/
|
||||
async function cleanShutdown() {
|
||||
try {
|
||||
destroyTray();
|
||||
await stopRPC();
|
||||
stopServer();
|
||||
|
||||
} catch (err) {
|
||||
logger.error("Error during cleanup:", err);
|
||||
|
||||
} finally {
|
||||
logger.info("All services stopped. Have a nice day!");
|
||||
logSessionEnd();
|
||||
|
||||
isCleanedUp = true;
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If another instance want to run
|
||||
*/
|
||||
@@ -166,19 +189,6 @@ app.on("before-quit", (event) => {
|
||||
if (!isCleanedUp) {
|
||||
event.preventDefault();
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
destroyTray();
|
||||
await stopRPC();
|
||||
} catch (err) {
|
||||
logger.error("Error during cleanup:", err);
|
||||
} finally {
|
||||
logger.info("All services stopped. Have a nice day!");
|
||||
logSessionEnd();
|
||||
|
||||
isCleanedUp = true;
|
||||
app.quit();
|
||||
}
|
||||
})();
|
||||
cleanShutdown();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user