#on_tray_icon_event does not work on ubuntu(popOS)

8 messages · Page 1 of 1 (latest)

mossy crystal
#

I am trying to add .on_tray_icon_event on my menu bar application but it is not working. I need to apply positioning but it doesn't even go inside this code
I am using https://v2.tauri.app/learn/system-tray/#listen-to-tray-events as reference

        .on_tray_icon_event(|tray, event| {
            let app = tray.app_handle();

            tauri_plugin_positioner::on_tray_event(app.app_handle(), &event);

            println!("positioning applied");
            if let TrayIconEvent::Click {
                button: MouseButton::Left,
                button_state: MouseButtonState::Up,
                ..
            } = event
            {
                if let Some(window) = app.get_webview_window("main") {
                    println!("{}", window.is_visible().unwrap());
                    if window.is_visible().unwrap_or(false) {
                        println!("hiding.....");
                        let _ = window.hide();
                    } else {
                        println!("positioning.....");
                        let _ =
                            window.move_window(tauri_plugin_positioner::Position::TrayBottomCenter);
                        let _ = window.show();
                        let _ = window.set_focus();
                    }
                }
            }
        })
Tauri

The cross-platform app building toolkit

lofty steeple
#

this is expected and should be documented. the linux tray library we use (appindicator) doesn't provide these events.

#

okay sad, it's not documented in the guide, only in the function docs

mossy crystal
#

Is there any option to set positioning for tray icon click? I want it to always right below the menu bar icon

lofty steeple
#

i don't really understand what you mean tbh

mossy crystal
lofty steeple
#

ah that. that's not directly supported in our crates then.

I also only see a single api that would help but it relies on GtkStatusIcon which would conflict with libappindicator.

#

unless you have quite some knowledge in gdk or x11 or whatever is needed, i'd recommend to wait for https://github.com/tauri-apps/tray-icon/pull/201 where libappindicator will be replaced with another backend which should hopefully give us the click events.