tauri-apps / tauri

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

[bug] On MacOS when a new system_tray_menu is set the on_system_tray_event handler is no longer called #5842

Closed rikschennink closed 1 year ago

rikschennink commented 1 year ago

Describe the bug

  1. I set a menu during build as described in docs here

  2. Then later in a command from front-end I set a a new menu but now the on_system_tray_event handler is no longer called.

I tried to replace the entire system tray but that causes the app to crash on right click. See stack trace.

I'm super new to Rust so this could very well all be incompetence. Grateful for any feedback / ideas. I've also opened a Stack Overflow issue to cover the incompetence situation

Reproduction

Updating the menu resulting in events no longer working

#[tauri::command]
fn set_system_tray_menu(app: AppHandle) {

    let menu = SystemTrayMenu::new()
      .add_item(CustomMenuItem::new("test".to_string(), "Test"));

    match app.tray_handle().set_menu(menu) {
      Ok(_) => {},
      Err(error) => panic!("Problem setting system tray menu: {}", error),
    };

}

Replacing the menu causing a crash

fn set_system_tray_menu(app: AppHandle) {

    let menu = SystemTrayMenu::new()
      .add_item(CustomMenuItem::new("test".to_string(), "Test"));

    match SystemTray::new().with_menu(menu).build(&app) {
      Ok(_) => {},
      Err(error) => panic!("Problem setting system tray menu: {}", error),
    };

}

Expected behavior

Either one of these:

  1. The on_system_tray_event event handlers keep working
  2. A way to assign new event handlers

Platform and versions

MacOS 12.6

Stack trace

2022-12-15 14:59:48.060 hotlist-tauri[49478:21361707] -[_WKInspectorConfiguration _setMenuOwner:]: unrecognized selector sent to instance 0x13e7ecdd0
thread 'main' panicked at 'Uncaught exception <NSException: 0x13e709a30>', /Users/rikschennink/.cargo/registry/src/github.com-1ecc6299db9ec823/cocoa-0.24.1/src/appkit.rs:3740:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Additional context

No response

amrbashir commented 1 year ago

will be fixed in the next release