From 4c0c3da898c6eb2b1314bc944d94ef90b5c0fdb9 Mon Sep 17 00:00:00 2001
From: dragonwocky <thedragonring.bod@gmail.com>
Date: Wed, 23 Aug 2023 21:38:04 +1000
Subject: [PATCH] theoretically fix #27: call app.dock.hide() on mac

+ restore hidden taskbar icons on plugin cleanup/disable
---
 main.js | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/main.js b/main.js
index 784b4e4..3f5ffdb 100644
--- a/main.js
+++ b/main.js
@@ -100,12 +100,16 @@ const onWindowClose = (event) => event.preventDefault(),
     window.removeEventListener("beforeunload", onWindowUnload, true);
   };
 
-const setHideTaskbarIcon = () => {
-    getWindows().forEach((win) => {
-      win.setSkipTaskbar(plugin.settings.hideTaskbarIcon);
-    });
+const hideTaskbarIcons = () => {
+    getWindows().forEach((win) => win.setSkipTaskbar(true));
+    if (process.platform === "darwin") app.dock.hide();
   },
-  setLaunchOnStartup = () => {
+  showTaskbarIcons = () => {
+    getWindows().forEach((win) => win.setSkipTaskbar(false));
+    if (process.platform === "darwin") app.dock.show();
+  };
+
+const setLaunchOnStartup = () => {
     const { launchOnStartup, runInBackground, hideOnLaunch } = plugin.settings;
     app.setLoginItemSettings({
       openAtLogin: launchOnStartup,
@@ -248,7 +252,10 @@ const OPTIONS = [
     `,
     type: "toggle",
     default: false,
-    onChange: setHideTaskbarIcon,
+    onChange() {
+      if (plugin.settings.hideTaskbarIcon) hideTaskbarIcons();
+      else showTaskbarIcons();
+    },
   },
   {
     key: "createTrayIcon",
@@ -410,10 +417,10 @@ class TrayPlugin extends obsidian.Plugin {
     plugin = this;
     createTrayIcon();
     registerHotkeys();
-    setHideTaskbarIcon();
     setLaunchOnStartup();
     observeWindows();
     if (settings.runInBackground) interceptWindowClose();
+    if (settings.hideTaskbarIcon) hideTaskbarIcons();
     if (settings.hideOnLaunch) {
       this.registerEvent(this.app.workspace.onLayoutReady(hideWindows));
     }
@@ -435,6 +442,7 @@ class TrayPlugin extends obsidian.Plugin {
     log(LOG_CLEANUP);
     unregisterHotkeys();
     allowWindowClose();
+    showTaskbarIcons();
     destroyTray();
   }