Skip to content

Commit

Permalink
Dev mode (#99)
Browse files Browse the repository at this point in the history
* feat(index) menubar stays open in development for debugging

* reverting focusable change

* feat(index.js) add development mode detections, refactor(index.js) modify window hiding function with manual flag, feat(index.js) add double-click on tray for quicker open.

* disable hiding on click away

i think this completes our transition away from a menubar app towards just a straight up full app that happens to have a keyboard shortcut to activate

---------

Co-authored-by: swyx.io <[email protected]>
  • Loading branch information
seanoliver and swyxio authored Aug 3, 2023
1 parent 107da36 commit 262a4c1
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 262a4c1

Please sign in to comment.