0

How can you make sure that the menu bar stays active when a BrowserWindow in Electron is visible?

Case Explanation: Once you click on my Tray icon, a BrowserWindow is opened with some HTML. Once the cursor moves down from the Mac menu bar, the menu bar is hidden, but the BrowserWindow is still visible.

Desired Case: Ideally, the Mac menu bar remains visible until the BrowserWindow is de-focused and hidden.

Here is an image of how the problem looks:

enter image description here

Interestingly, when I create a context menu instead of having a custom BrowserWindow...

const contextMenu = Menu.buildFromTemplate([
    { label: 'Item1', type: 'radio' },
    { label: 'Item2', type: 'radio' },
    { label: 'Item3', type: 'radio', checked: true },
    { label: 'Item4', type: 'radio' }
])

tray.setContextMenu(contextMenu)

... the Mac menu bar remains. See this image:

enter image description here

user2500558
  • 73
  • 3
  • 10
  • 1
    Not possible. Auto hiding menu bar is macOS the host system's behavior. The host is the boss, you don't get to tell it what to do unless it voluntarily provides an API for you to submit such request. But there isn't one AFAIK. – hackape Jul 17 '22 at 09:33
  • I do not think here its about changing system behavior. If I use the standard Electron Menu and set this as a context menu for the tray, the tray icon is focused even when I move my mouse away from the menu bar. I updated my post to show this. I want the same behavior but instead of the Electron menu, I want to have my custom BrowserWindow. – user2500558 Jul 17 '22 at 09:39
  • 2
    Sorry, I haven't made my point clear enough. Yes, as a tray menu, it can hold the menu bar from hiding, but that's the only way to go, which in your case isn't what you want. If you have other apps installed as tray items, like 1Password perhaps, test with them, same thing. Only tray menu can hold menu bar, popover app windows cannot cus they're effectively unrelated with menu bar. – hackape Jul 17 '22 at 10:03
  • 1
    Think about it, popover is just an icon in the tray which triggers the popping of another window. The icon is related to menu bar, the window is not. – hackape Jul 17 '22 at 10:05

0 Answers0