diff --git a/index.js b/index.js index b6ce031..9493aa6 100644 --- a/index.js +++ b/index.js @@ -96,6 +96,22 @@ app.on('ready', () => { icon: image, }); + // Flag to detect if the window was hidden manually + let manualHide = false; + + // Prevent window from hiding when in development mode if not hidden manually + // (for debugging) + if (process.env.NODE_ENV === 'development') { + const originalHideWindow = mb.hideWindow.bind(mb); + + mb.hideWindow = () => { + if (manualHide) { + manualHide = false; // Reset the flag + originalHideWindow(); // Call the original hideWindow method + } + }; + } + // On menubar ready, the following code will execute mb.on('ready', () => { const { window } = mb; @@ -234,6 +250,16 @@ app.on('ready', () => { }, ]; + // FYI to the user that they are in development mode + if (process.env.NODE_ENV === 'development') { + menuHeader.unshift( + { + label: '👨‍💻 IN DEV MODE 👨‍💻', + }, + separator, + ); + } + // Return the complete context menu template return [ ...menuHeader, @@ -259,12 +285,20 @@ app.on('ready', () => { if (e.ctrlKey || e.metaKey) { const contextMenuTemplate = createContextMenuTemplate(); mb.tray.popUpContextMenu(Menu.buildFromTemplate(contextMenuTemplate)); + } else { + quickOpen(); } }); + + tray.on('double-click', () => { + quickOpen(); + }); + const menu = new Menu(); function quickOpen() { if (window.isVisible()) { + manualHide = true; // Honor manual hide in development mode mb.hideWindow(); } else { mb.showWindow(); @@ -358,13 +392,6 @@ app.on('ready', () => { }); }); - if (process.platform == 'darwin') { - // restore focus to previous app on hiding - mb.on('after-hide', () => { - mb.app.hide(); - }); - } - // open links in new window // app.on("web-contents-created", (event, contents) => { // contents.on("will-navigate", (event, navigationUrl) => {