Native menubar example broken
Jip-Hop opened this issue · 5 comments
Description
The native menubar example is broken. Clicking the icon in the menubar opens the native menu, but also the browser window. Right clicking the menubar icon will only open the native menubar normally.
Steps to Reproduce the Problem
- Follow installation instructions from native menubar example
- Click the menubar icon several times
- See that both the native menu as well as the browser window appear
Expected Behaviour
Only the native menubar should appear.
Actual Behaviour
Also the browser window appears.
When the browser window appears, the following error is thrown:
yarn run v1.22.10
$ electron .
Menubar app is ready.
(node:2391) UnhandledPromiseRejectionWarning: Error: ERR_FILE_NOT_FOUND (-6) loading 'file:///GitHub/menubar/examples/native-menu/index.html'
at rejectAndCleanup (electron/js2c/browser_init.js:217:1457)
at Object.failListener (electron/js2c/browser_init.js:217:1670)
at Object.emit (events.js:315:20)
(Use `Electron --trace-warnings ...` to show where the warning was created)
(node:2391) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2391) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Specifications
- Menubar version: 9.0.4
- Platform: MacOS 11.4 and Windows 10 Home 20H2
- Electron version: v9.4.0 (also tested with v12.0.12, same behaviour)
This code disables opening the browser window, and only opens the native menu (at least on MacOS).
mb.on('ready', () => {
console.log('Menubar app is ready.');
// your app code here
tray.removeAllListeners();
});
Using tray.removeAllListeners("click");
is not enough, because then on double click the browser window will still open.
Seems like these events are bound when they shouldn't in case the tray is set.
Thanks @Jip-Hop. This does seem to be a bug, but your solution worked for me too.
@Jip-Hop wow! thank u sooo much! should be in the example!
If someone creates a PR I'll merge it
Created a PR for it! The issue can be closed!