max-mapper / menubar

➖ high level way to create menubar desktop applications with electron
BSD 2-Clause "Simplified" License
6.68k stars 365 forks source link

Unexpected Behavior in 'Tips' Documentation -- re: window.hide() & always-on-top #324

Open ArthurD opened 3 years ago

ArthurD commented 3 years ago

Description

My overarching goal is an app that is a "pure" menubar, targeting specifically macOS users, with the purpose being to show at-a-glance data in the menubar along with additional detail & quick "controls" when the app is open. I want it to function similar to most macOS menubar apps (ie 1Password) -- when focus is lost, the window should hide completely.

The 'Tips' section of the documentation specifies the following:

Use mb.on('focus-lost') if you would like to perform some operation when using the option browserWindow.alwaysOnTop: true

Steps to Reproduce the Problem

  1. Based on the 'tips' part of the README, I used the following code to cause the window to hide when focus is lost:

mb.on('focus-lost', () => { mb.window.hide(); });

  1. With the menubar app open, click anywhere away from the menubar app (causing it to lose focus).
  2. After closing the app via clicking outside of it [ie loss of focus], now attempt to re-open the menubar app via clicking it in the macOS menubar.
  3. Note that it does not open upon clicking it; a second click is required to get it to open.

Expected Behaviour

After closing the app via clicking outside of it [ie loss of focus], any future click on the app in the macOS menubar should re-activate & display the app/window.

Actual Behaviour

After closing the app via clicking outside of it [ie loss of focus], any future click on the app in the macOS menubar will intermittently (seems to toggle/alternate) have no effect / be a no-op click (window does not display). Clicking it a second time opens the window.

Specifications

Other information

It appears that using the following code, instead of the code above, actually causes the behavior to be as expected -- ie it resolves the issue -- so maybe this "issue" can just be 'fixed' via simply updating the documentation, I'm not sure.

mb.on('focus-lost', () => { mb.hideWindow(); });

If nothing else, I'd like to understand why this works & the approach that I tried initially does not; and if there is a way to make my initial approach work I'd love to hear & learn/understand it (ie do I need to call/init the window again somehow, or listen for menubar click manually & call show(), or similar). :)

Thank you very much; this is a fantastic project and I very much appreciate all the work that has gone into it! It's really quite nice -- thank you! :)

savely-krasovsky commented 2 months ago

After a lot of testing I personally think it's the limitations of the Electron itself. No one develop Electron as a standalone menubar app framework. So there are a lot of edge cases when it just don't work as you want unfortunately. For the best menubar experience the only option is to write it natively (but you can use Flutter for example, because it allows you to customize native code fully).