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:
@@ -87,7 +87,7 @@ async function createMainWindow() {
|
|||||||
* cancels the destruction and hides the window instead.
|
* cancels the destruction and hides the window instead.
|
||||||
*/
|
*/
|
||||||
mainWindow.on('close', (event) => {
|
mainWindow.on('close', (event) => {
|
||||||
if (!app.isQuitting) {
|
if (!app.isQuitting && config.systemTray ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
mainWindow.hide();
|
mainWindow.hide();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
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 { userThemesPath, initUserThemes, isWindows, validateBinaries, defaultDownloadFolder } = require("./server/helpers/path.helpers");
|
||||||
const {createSystemTray, destroyTray} = require("./app/tray");
|
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;
|
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
|
* If another instance want to run
|
||||||
*/
|
*/
|
||||||
@@ -145,7 +157,7 @@ app.whenReady().then(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.on("window-all-closed", () => {
|
app.on("window-all-closed", () => {
|
||||||
if (app.isQuitting) {
|
if (app.isQuitting || !configFeatures.systemTray) {
|
||||||
logger.info("Shutting down...");
|
logger.info("Shutting down...");
|
||||||
app.quit();
|
app.quit();
|
||||||
} else if (process.platform !== "darwin") {
|
} 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;
|
app.isQuitting = true;
|
||||||
destroyTray();
|
|
||||||
await stopRPC();
|
if (!isCleanedUp) {
|
||||||
logger.info("All services stopped. Have a nice day!");
|
event.preventDefault();
|
||||||
logSessionEnd();
|
|
||||||
|
(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