diff --git a/main.js b/main.js index 7f7c461..dbb02c5 100644 --- a/main.js +++ b/main.js @@ -20,6 +20,8 @@ const LOG_PREFIX = "obsidian-tray", ACTION_HIDE = "Hide Vault", ACTION_RELAUNCH = "Relaunch Obsidian", ACTION_CLOSE = "Close Vault", + ACTION_OPEN = "Open Vault", + ACTION_TOGGLE = "Toggle Vault Window", DEFAULT_DATE_FORMAT = "YYYY-MM-DD", ACCELERATOR_FORMAT = ` This hotkey is registered globally and will be detected even if Obsidian does @@ -95,6 +97,19 @@ const vaultWindows = new Set(), }); if (openWindows) hideWindows(); else showWindows(); + }, + toggleVault = (checkForFocus = true) => { + const openWindows = getWindows().some((win) => { + return (!checkForFocus || win.isFocused()) && win.isVisible(); + }); + if (openWindows) hideWindows(); + else { + getWindows().forEach((win) => { + win.show(); + win.minimize(); + win.maximize(); + }); + }; }; const onWindowClose = (event) => event.preventDefault(), @@ -473,6 +488,16 @@ class TrayPlugin extends obsidian.Plugin { name: ACTION_CLOSE, callback: closeVault, }); + this.addCommand({ + id: "open-vault", + name: ACTION_OPEN, + callback: showWindows, + }); + this.addCommand({ + id: "toggle-vault", + name: ACTION_TOGGLE, + callback: toggleVault, + }); } onunload() { cleanup();