tauri-apps / tauri

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

[bug] with_menu_on_left_click on osx prevent focus on additional windows and requires an non-wanted additional click before focus #7740

Open Jarrodsz opened 1 year ago

Jarrodsz commented 1 year ago

Describe the bug

when building a tray

   .system_tray(SystemTray::new().with_menu(tray_menu).with_menu_on_left_click(true))

causes a bug with additional windows beeing created having no focus. on osx. you cannot close the window by clicking the (x) without clicking 2 times on the window! also you have no focus on the window so say you wanted to click a button in the window itself, then you would have to click 2 times.. 1 click to get the window respond or get focus 2. to close the window with (x) or click any additional elements in the window.

with

.system_tray(SystemTray::new().with_menu(tray_menu))

it works correctly, very ugly bug wasted hours and hours on finding out this was the reason

Reproduction

see above just create a tray with a option that opens a window.

add the tray as

.system_tray(SystemTray::new().with_menu(tray_menu).with_menu_on_left_click(true))

to view the 2 times click bug.

or

.system_tray(SystemTray::new().with_menu(tray_menu))

which works fine

Expected behavior

be able to use

        .system_tray(SystemTray::new().with_menu(tray_menu).with_menu_on_left_click(true))

without it messes up my additional windows and require me to click 2 times on it!!

Additional setting the setting not in code but from the config does not seem to do anything ! so true or false does not do anything

"systemTray": {
      "iconPath": "icons/icon.png",
      "iconAsTemplate": true,
      "menuOnLeftClick": false
    },

Platform and versions

[✔] Environment
    - OS: Mac OS 13.4.1 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.72.0 (5680fa18f 2023-08-23)
    ✔ Cargo: 1.72.0 (103a7ff2e 2023-08-15)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 20.3.1
    - pnpm: 8.7.1
    - yarn: 1.22.19
    - npm: 9.6.7

[-] Packages
    - tauri [RUST]: 1.4.1
    - tauri-build [RUST]: 1.4.0
    - wry [RUST]: no manifest (0.18.3, 0.24.3)
    - tao [RUST]: no manifest (0.11.2, 0.16.2)
    - @tauri-apps/api [NPM]: 1.4.0
    - @tauri-apps/cli [NPM]: 1.4.0

Stack trace

text
no crash just does not respond the way it should see above

Additional context

on osx i have not tested how this behaves on windows

Jarrodsz commented 1 year ago

Additional:

     SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {

                        "check_for_updates" => {}
                        "settings" => {
                            let w = app.get_window("settings").unwrap();
                            w.show().unwrap();
                            w.set_focus().unwrap();
                        }
.setup(|app| {
            let app_handle = app.handle();
            match ui::setup_settings_window(&app_handle) {
                Ok(settings_window) => {
                    settings_window.set_always_on_top(true).unwrap();
                }
                Err(e) => {
                    println!("Failed to setup settings window: {}", e);
                }
            }

            Ok(())
        })

settings window initiated from:

pub fn setup_settings_window<R: Runtime>(app_handle: &AppHandle<R>) -> Result<Window<R>> {
  let settings_window = WindowBuilder::new(
    app_handle,
    crate::SETTINGS_WINDOW_LABEL,
    WindowUrl::App("/pages/settings/settings.html".into()),
  )
      .visible(false)
      .resizable(false)
      .inner_size(500., 400.)
      .skip_taskbar(true)
      .decorations(true)
      .focused(true)
      .build()?;

  Ok(settings_window)
}