diff --git a/apps/desktop/src/api/os-integration.ts b/apps/desktop/src/api/os-integration.ts index 086a259ff..65c6179af 100644 --- a/apps/desktop/src/api/os-integration.ts +++ b/apps/desktop/src/api/os-integration.ts @@ -83,7 +83,7 @@ export const osIntegrationRouter = t.router({ AutoLaunch.disable(); } config.desktopSettings = settings; - setupDesktopIntegration(); + setupDesktopIntegration(settings); }), selectDirectory: t.procedure diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index dc152eda9..dd8d420ee 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -107,7 +107,7 @@ async function createWindow() { } await AssetManager.loadIcons(); - setupDesktopIntegration(); + setupDesktopIntegration(config.desktopSettings); mainWindow.webContents.session.setSpellCheckerDictionaryDownloadURL( "http://dictionaries.notesnook.com/" diff --git a/apps/desktop/src/utils/desktop-integration.ts b/apps/desktop/src/utils/desktop-integration.ts index c96751cb9..cf3184d66 100644 --- a/apps/desktop/src/utils/desktop-integration.ts +++ b/apps/desktop/src/utils/desktop-integration.ts @@ -17,25 +17,27 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ import { app } from "electron"; -import { config } from "./config"; -import { setupTray } from "./tray"; +import { DesktopIntegration, config } from "./config"; +import { setupTray, destroyTray } from "./tray"; import { AutoLaunch } from "./autolaunch"; -export function setupDesktopIntegration() { - const desktopIntegration = config.desktopSettings; - +export function setupDesktopIntegration( + desktopIntegration: DesktopIntegration +) { if ( desktopIntegration.closeToSystemTray || desktopIntegration.minimizeToSystemTray ) { setupTray(); + } else { + destroyTray(); } // when close to system tray is enabled, it becomes nigh impossible // to "quit" the app. This is necessary in order to fix that. - if (desktopIntegration.closeToSystemTray) { - app.on("before-quit", () => app.exit(0)); - } + app.on("before-quit", () => + desktopIntegration.closeToSystemTray ? app.exit(0) : null + ); globalThis.window?.on("close", (e) => { if (config.desktopSettings.closeToSystemTray) { @@ -49,7 +51,9 @@ export function setupDesktopIntegration() { try { globalThis.window?.minimize(); globalThis.window?.hide(); - } catch (error) {} + } catch (error) { + console.error(error); + } } } });