fix: tray behaviror. App will shutdown gracefully

This commit is contained in:
MasterAcnolo
2026-08-14 22:08:23 +02:00
parent c153db0244
commit 1a1acb53d1
2 changed files with 34 additions and 7 deletions

View File

@@ -87,7 +87,7 @@ async function createMainWindow() {
* cancels the destruction and hides the window instead.
*/
mainWindow.on('close', (event) => {
if (!app.isQuitting) {
if (!app.isQuitting && config.systemTray ) {
event.preventDefault();
mainWindow.hide();
return false;

31
main.js
View File

@@ -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;
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();
}
})();
}
});