mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-09-27 20:11:15 +02:00
fix: tray behaviror. App will shutdown gracefully
This commit is contained in:
39
main.js
39
main.js
@@ -82,8 +82,20 @@ const { createSplashWindow, closeSplashWindow, setSplashProgress } = require("./
|
||||
const { userThemesPath, initUserThemes, isWindows, validateBinaries, defaultDownloadFolder } = require("./server/helpers/path.helpers");
|
||||
const {createSystemTray, destroyTray} = require("./app/tray");
|
||||
|
||||
/**
|
||||
* Global flag indicating if the application is intentionally shutting down.
|
||||
* Used across the app to bypass the "minimize to tray on close" behavior.
|
||||
* @type {boolean}
|
||||
*/
|
||||
app.isQuitting = false;
|
||||
|
||||
/**
|
||||
* State flag to track the asynchronous cleanup process during shutdown.
|
||||
* Prevents the application from exiting before services (RPC, Tray, Logs) are properly closed.
|
||||
* @type {boolean}
|
||||
*/
|
||||
let isCleanedUp = false;
|
||||
|
||||
/**
|
||||
* If another instance want to run
|
||||
*/
|
||||
@@ -145,7 +157,7 @@ app.whenReady().then(async () => {
|
||||
});
|
||||
|
||||
app.on("window-all-closed", () => {
|
||||
if (app.isQuitting) {
|
||||
if (app.isQuitting || !configFeatures.systemTray) {
|
||||
logger.info("Shutting down...");
|
||||
app.quit();
|
||||
} else if (process.platform !== "darwin") {
|
||||
@@ -153,10 +165,25 @@ app.on("window-all-closed", () => {
|
||||
}
|
||||
});
|
||||
|
||||
app.on("before-quit", async () => {
|
||||
app.on("before-quit", (event) => {
|
||||
app.isQuitting = true;
|
||||
destroyTray();
|
||||
await stopRPC();
|
||||
logger.info("All services stopped. Have a nice day!");
|
||||
logSessionEnd();
|
||||
|
||||
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();
|
||||
}
|
||||
})();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user