tauri-apps / tauri

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

[bug] set_menu is not working under Linux for tauri 2.0.0 #8374

Closed vangork closed 9 months ago

vangork commented 9 months ago

Describe the bug

On linux when upgrade to tauri 2.0, using TrayIconBuilder the menu is not shown upon click (left or right)

Reproduction

tauri.conf.json:

"trayIcon": {
      "iconAsTemplate": false,
      "iconPath": "icons/icon.png"
},

main.rs

let config = MenuItemBuilder::with_id("config", "config").build(app_handle);
let exit = MenuItemBuilder::with_id("exit", "exit").build(app_handle);
let seperator = PredefinedMenuItem::separator(app_handle);
let tray_menu = MenuBuilder::new(app_handle).items(&[&config, &seperator, &exit]).build().unwrap();
let tray = app_handle.tray().unwrap();
tray.set_menu(Some(tray_menu)).unwrap();

In additional, since tauri 2.0.0 removed get_item() method in the app_handle.tray(), how should I change the title for an existing menuitem?

Expected behavior

The menu should show up upon click of the tray icon.

Platform and versions

[✔] Environment
    - OS: Ubuntu 22.04 X64
    ✔ webkit2gtk-4.1: 2.42.3
    ✔ rsvg2: 2.52.5
    ✔ 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-unknown-linux-gnu (default)
    - node: 20.10.0
    - yarn: 1.22.21
    - npm: 10.2.3

[-] Packages
    - tauri [RUST]: 2.0.0-alpha.18
    - tauri-build [RUST]: 2.0.0-alpha.12
    - wry [RUST]: 0.34.2
    - tao [RUST]: 0.23.0
    - @tauri-apps/api [NPM]: 2.0.0-alpha.12
    - @tauri-apps/cli [NPM]: 2.0.0-alpha.18

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite

Stack trace

No response

Additional context

No response

amrbashir commented 9 months ago

Thanks for the report, I believe this is the same as https://github.com/tauri-apps/tray-icon/issues/89 and will hopefully will be fixed in the next release.

vangork commented 9 months ago

@amrbashir Thanks for the response. BTW, since tauri 2.0.0 removed get_item() method in the app_handle.tray(), how should I change the title for an existing menu item?

vangork commented 9 months ago

@amrbashir Meanwhile, on_tray_icon_event is not working neither on Linux.

amrbashir commented 9 months ago

I believe you want to see the menu events of the tray, in this case, use .on_menu_event