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

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

Open
czheo opened this issue Oct 8, 2023 · 11 comments · Fixed by #7983
Open

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

czheo opened this issue Oct 8, 2023 · 11 comments · Fixed by #7983
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug type: documentation Need to update the API documentation

Comments

@czheo
Copy link

czheo commented Oct 8, 2023

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: czheo/tauri_bug@2317186

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_
@czheo czheo added status: needs triage This issue needs to triage, applied to new issues type: bug labels Oct 8, 2023
@amrbashir
Copy link
Member

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 amrbashir changed the title [bug] menu item doesn't show up on MacOS [docs] menu item doesn't show up on MacOS Oct 8, 2023
@amrbashir amrbashir added type: bug type: documentation Need to update the API documentation and removed type: bug labels Oct 8, 2023
@amrbashir amrbashir linked a pull request Oct 8, 2023 that will close this issue
13 tasks
@czheo
Copy link
Author

czheo commented Oct 9, 2023

@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
Copy link
Member

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
Copy link
Author

czheo commented Oct 10, 2023

@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
Copy link
Member

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 #7981 (comment)

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
Copy link
Author

czheo commented Oct 10, 2023

@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
Copy link
Member

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
Copy link
Author

czheo commented Oct 10, 2023

@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
Copy link
Author

czheo commented Oct 10, 2023

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
Copy link
Member

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
Copy link
Author

czheo commented Oct 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug type: documentation Need to update the API documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants