Open czheo opened 1 year ago
on macOS, you can't add a menu item directly to the Menu
, you can only add submenus. Looks like this is a documentation mistake so I will open a PR to fix that.
@amrbashir thanks for looking into this.
If add_item
were to be supported on MacOS, it makes most sense to me the item would be added under the dropdown of the app name.
If not support, how can I add an item under that dropdown then?
For example, I expect the tauri_bug menu will expand with some menu item, however there's no associated dropdown. I want something like in chrome, where the app name "Chrome" has its own dropdown, and "File", "Edit" and etc are other submenus.
It should take the first subitem automatically, maybe the submenu needs the app name as it's name but i don't think so. For reference here's the implementation of os_menu() which also fills that first menu: https://docs.rs/tauri-runtime/0.14.1/src/tauri_runtime/menu.rs.html#245
@FabianLars
It should take the first subitem automatically
Yes, that's my expectation. But It doesn't do so now, as my code example shows in: https://github.com/czheo/tauri_bug
maybe the submenu needs the app name as it's name but i don't think so.
I tested creating a submenu with the app name and it creates a different submenu next to the default one:
weird, it works for me:
Also picking up your comment from the PR:
I don't see a reason add_item shouldn't be supported in MacOS. My expectation is described as in https://github.com/tauri-apps/tauri/issues/7981#issuecomment-1752458454
The reason why this doesn't make sense is mostly due to cross-platform consistency. On Windows and Linux the "parent" items in the menu bar can be basically buttons and don't need submenus to provide functionality. iirc on macOS only submenu items trigger events the app can handle.
@FabianLars It seems behavior is different by OS version. I guess you are on MacOS 13. It's also weird your title shows nowhere. How are you supposed to create a menu next to the "react" menu then?
I guess you are on MacOS 13
I am, yes. But it used to work on 10.15 last time i used my VM too, can test again today or next week 🤔 What version are you on?
It's also weird your title shows nowhere.
Weird yes, but expected because the first menu item is set by macos reading the app name.
How are you supposed to create a menu next to the "react" menu then?
By adding another submenu to the main menu. Each submenu (on the main menu) will be displayed on the menu bar.
@FabianLars I see what you mean. I'm on OS: Mac OS 12.6.9 X64
. I think my machine is different from the behavior you explained. (I have first menu auto populated by the OS being empty, with all submenus added after it)
The reason why this doesn't make sense is mostly due to cross-platform consistency. On Windows and Linux the "parent" items in the menu bar can be basically buttons and don't need submenus to provide functionality. iirc on macOS only submenu items trigger events the app can handle.
Will it make more sense that add_item
on MacOs adds item to the default menu shown with app name that's populated by the OS automatically? (That was my original expectation)
To me it wouldn't make more sense than the current approach, no. In my mind the first Menu is the menu bar itself, and each submenu is a new menubutton on that bar, i think it'd me even more confusing if the first menu isn't a submenu while the others are, especially if we think about cross-platform code.
if we think about cross-platform code
Double thinking this claim. I think it makes sense to me that having similar behaviors on different platforms can have benefit. Cross-platform app builders need not have different code on different platforms.
Describe the bug
I added a item to the menu like above but it doesn't show up anywhere
Reproduction
Reproduced in https://github.com/czheo/tauri_bug This is created based on the app template created by
sh <(curl https://create.tauri.app/sh)
. With only this change: https://github.com/czheo/tauri_bug/commit/23171865aedffdfb38ccee13123d9d1ec5896eb7Expected behavior
There should be "Hide" button/menu item shown somewhere on the menu bar.
Platform and versions