Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] MacOS menu doesn't change based on window #5768

Open
Sytten opened this issue Dec 5, 2022 · 10 comments
Open

[bug] MacOS menu doesn't change based on window #5768

Sytten opened this issue Dec 5, 2022 · 10 comments
Labels
platform: macOS status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@Sytten
Copy link

Sytten commented Dec 5, 2022

Describe the bug

This might be a "works as intended" but it should be documented.
Basically, the menu stays with the value of the latest call to .menu and doesn't change based on the currently focused window. Meaning that you are kinda forced to use a single menu for the whole application.

Reproduction

  1. Start with any basic application
  2. Open a second window with with .menu
  3. The menu sticks with the menu defined in the second window

Expected behavior

Unsure what behaviour is expected on MacOS, it would be nice if it switched but worst case it should be documented.

Platform and versions

Environment
  › OS: Mac OS 11.6.3 X64
  › Node.js: 16.17.0
  › npm: 8.15.0
  › pnpm: 7.17.1
  › yarn: 1.22.15
  › rustup: 1.25.1
  › rustc: 1.65.0
  › cargo: 1.65.0
  › Rust toolchain: stable-x86_64-apple-darwin

Packages
  › @tauri-apps/cli [NPM]: 1.2.0 (outdated, latest: 1.2.1)
  › @tauri-apps/api [NPM]: 1.2.0
  › tauri [RUST]: git+https://github.com/caido/dependency-tauri?branch=caido#f73dc6487fa9e5ca8f60b092d31ea7f5d8a7a24b (1.2.0),
  › tauri-build [RUST]: git+https://github.com/caido/dependency-tauri?branch=caido#f73dc6487fa9e5ca8f60b092d31ea7f5d8a7a24b (1.2.0),
  › tao [RUST]: 0.15.3,
  › wry [RUST]: 0.22.0,

App
  › build-type: bundle
  › CSP: default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  › distDir: ../caido-ui/dist
  › devPath: http://localhost:10000/
  › framework: Vue.js

App directory structure
  ├─ dist
  ├─ node_modules
  ├─ scripts
  └─ src

Stack trace

No response

Additional context

No response

@Sytten Sytten added status: needs triage This issue needs to triage, applied to new issues type: bug labels Dec 5, 2022
@amrbashir
Copy link
Member

Since the menu are global on macOS, it is expected that the menu won't change. I think the documentation is clear enough but if it is not, please go ahead and open a PR with a better documentation.

@amrbashir amrbashir closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2022
@matthme
Copy link
Contributor

matthme commented Dec 6, 2022

I just came across a similar issue (probably the same root cause):

I made a repro here: https://github.com/matthme/menu-stuck-tauri-macos

I don't think this behavior is documented at all and it is quite counterintuitive given that the menu method is part of WindowBuilder.

@FabianLars
Copy link
Member

Reopening because it's a really weird situation which needs some clarification (in the docs) or even better a change in behavior.

@FabianLars
Copy link
Member

Maybe the menu apis should be on the App|Handle on macos for v2 instead? A bit more annoying to use cross-platform wise but at least it's clear what's happening, and it would prevent that new windows would overwrite the menu without a way to go back.

@amrbashir
Copy link
Member

that's indeed the planned changes for v2 leveraging the new menu crate (muda).

@amrbashir
Copy link
Member

I think we can internally disable WindowBuilder::menu on macOS so it doesn't cause this behavior for now.

@matthme
Copy link
Contributor

matthme commented Dec 6, 2022

Or would it be possible to have a boolean property overwrite_macOS_main_menu or similar in the menu method?

@Sytten
Copy link
Author

Sytten commented Dec 6, 2022

Sorry my wording was not very good above, but this is exactly what @matthme said!

@matthme
Copy link
Contributor

matthme commented Dec 15, 2022

Oh, and it comes even worse. It seems that one can't even disable the menu for an external window on Linux (and probably also Windows but not tested): https://github.com/matthme/menu-stuck-tauri-macos/tree/inherit-menu
Omitting the menu() method leads to inheriting the menu of the main window.
So it's an unresolvable conflict between platforms. I can choose between:

  1. One global menu that is forced onto every window
  2. Make custom menus for different windows and have the "main" menu be overwritten on macOS

Both are not an option in my case so I have to go with the lesser evil of the two which I think is number 2 for me. Or I'll have to create a JS-based custom menu...

I would at least want to be able to explicitly not show any menu at all on Linux/Windows for external windows.

@matthme
Copy link
Contributor

matthme commented Jan 9, 2023

For people reading this and having a similar conflict between platforms: One may hardly believe it but I had a breakthrough in my Rust skills recently and discovered conditional compilation. So it's easily possible to have different menus on windows other than the main window be only applied to Linux/Windows by simply using platform-specific Rust code.
It doesn't solve this issue but at least makes things work on Linux/Windows as intended without negative side effects on the global menu on macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: macOS status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
Status: 📬Proposal
Development

No branches or pull requests

4 participants