tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
83.67k stars 2.51k forks source link

[docs] menu item doesn't show up on MacOS #7981

Open czheo opened 1 year ago

czheo commented 1 year ago

Describe the bug

let menu = Menu::new().add_item(CustomMenuItem::new("hide", "Hide"));
tauri::Builder::default()
  .menu(menu)
  ...

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/23171865aedffdfb38ccee13123d9d1ec5896eb7

Expected behavior

There should be "Hide" button/menu item shown somewhere on the menu bar.

Platform and versions

$ cargo tauri info
WARNING: no lock files found, defaulting to npm

[✔] Environment
    - OS: Mac OS 12.6.9 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.73.0 (cc66ad468 2023-10-03)
    ✔ Cargo: 1.73.0 (9c4383fb5 2023-08-26)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-apple-darwin (environment override by RUSTUP_TOOLCHAIN)
    - node: 19.8.1
    - pnpm: 8.8.0
    - yarn: 3.4.1
    - npm: 9.6.2

[-] Packages
    - tauri [RUST]: 1.5.1
    - tauri-build [RUST]: 1.5.0
    - wry [RUST]: 0.24.4
    - tao [RUST]: 0.16.4
    - tauri-cli [RUST]: 1.5.1
    - @tauri-apps/api [NPM]: not installed!
    - @tauri-apps/cli [NPM]: 1.5.1

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../src
    - devPath: ../src


### Stack trace

_No response_

### Additional context

_No response_
amrbashir commented 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.

czheo commented 1 year ago

@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. image I want something like in chrome, where the app name "Chrome" has its own dropdown, and "File", "Edit" and etc are other submenus. image

FabianLars commented 1 year ago

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

czheo commented 1 year ago

@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: image

FabianLars commented 1 year ago

weird, it works for me:

Bildschirmfoto 2023-10-10 um 10 59 05

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.

czheo commented 1 year ago

@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?

FabianLars commented 1 year ago

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.

czheo commented 1 year ago

@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)

czheo commented 1 year ago

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)

FabianLars commented 1 year ago

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.

czheo commented 1 year ago

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.