From 71ba850a1564feec9b69b2440ec074963dd0de31 Mon Sep 17 00:00:00 2001 From: Zarpyk <30746531+Zarpyk@users.noreply.github.com> Date: Thu, 27 Jul 2023 13:58:32 +0200 Subject: [PATCH] Fix #22 --- main.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 164722b..60b0b58 100644 --- a/main.js +++ b/main.js @@ -69,6 +69,21 @@ const childWindows = new Set(), else showWindows(); }; +let isMaximized = false; +const onMinimize = () => { + if (isMaximized) getCurrentWindow().maximize(); + hideWindows(); + }, interceptWindowMinimize = () => { + isMaximized = getCurrentWindow().isMaximized(); + getCurrentWindow().on("maximize", () => { + isMaximized = true; + }); + getCurrentWindow().on("unmaximize", () => { + isMaximized = false; + }); + getCurrentWindow().on("minimize", onMinimize); + }; + const onWindowClose = (event) => event.preventDefault(), onWindowUnload = (event) => { log(LOG_WINDOW_CLOSE); @@ -394,7 +409,10 @@ class TrayPlugin extends obsidian.Plugin { setHideTaskbarIcon(); setLaunchOnStartup(); observeChildWindows(); - if (settings.runInBackground) interceptWindowClose(); + if (settings.runInBackground) { + interceptWindowMinimize(); + interceptWindowClose(); + } if (settings.hideOnLaunch) { this.registerEvent(this.app.workspace.onLayoutReady(hideWindows)); }