fix #28: restore dock on close, hide dock on focus if req

This commit is contained in:
dragonwocky 2023-08-24 18:39:19 +10:00
parent 999213801f
commit b60e453b68
Signed by: dragonwocky
GPG Key ID: 7998D08F7D7BD7A8
2 changed files with 26 additions and 12 deletions

36
main.js
View File

@ -59,6 +59,19 @@ const vaultWindows = new Set(),
};
onWindowCreation(getCurrentWindow());
getCurrentWindow().webContents.on("did-create-window", onWindowCreation);
if (process.platform === "darwin") {
// on macos, the "hide taskbar icon" option is implemented
// via app.dock.hide(): thus, the app as a whole will be
// hidden from the dock, including windows from other vaults.
// when a vault is closed via the "close vault" button,
// the cleanup process will call app.dock.show() to restore
// access to any other open vaults w/out the tray enabled
// => thus, this listener is required to re-hide the dock
// if switching to another vault with the option enabled
getCurrentWindow().on("focus", () => {
if (plugin.settings.hideTaskbarIcon) hideTaskbarIcons();
});
}
},
showWindows = () => {
log(LOG_SHOWING_WINDOWS);
@ -110,14 +123,21 @@ const hideTaskbarIcons = () => {
showTaskbarIcons = () => {
getWindows().forEach((win) => win.setSkipTaskbar(false));
if (process.platform === "darwin") app.dock.show();
};
const setLaunchOnStartup = () => {
},
setLaunchOnStartup = () => {
const { launchOnStartup, runInBackground, hideOnLaunch } = plugin.settings;
app.setLoginItemSettings({
openAtLogin: launchOnStartup,
openAsHidden: runInBackground && hideOnLaunch,
});
};
const cleanup = () => {
log(LOG_CLEANUP);
unregisterHotkeys();
showTaskbarIcons();
allowWindowClose();
destroyTray();
},
relaunchApp = () => {
app.relaunch();
@ -125,9 +145,7 @@ const setLaunchOnStartup = () => {
},
closeVault = () => {
log(LOG_CLEANUP);
unregisterHotkeys();
allowWindowClose();
destroyTray();
cleanup();
const vaultWindows = getWindows(),
obsidianWindows = BrowserWindow.getAllWindows();
if (obsidianWindows.length === vaultWindows.length) {
@ -454,11 +472,7 @@ class TrayPlugin extends obsidian.Plugin {
});
}
onunload() {
log(LOG_CLEANUP);
unregisterHotkeys();
allowWindowClose();
showTaskbarIcons();
destroyTray();
cleanup();
}
async loadSettings() {

View File

@ -4,7 +4,7 @@
"author": "dragonwocky",
"authorUrl": "https://dragonwocky.me/",
"description": "Run Obsidian from the system tray for customisable window management & global quick notes",
"version": "0.3.3",
"version": "0.3.4",
"isDesktopOnly": true,
"minAppVersion": "1.0.0"
}