tray-icon icon indicating copy to clipboard operation
tray-icon copied to clipboard

Missing useful fields on menu event

Open ofluffydev opened this issue 10 months ago • 2 comments

The MenuEvent appears to only show it's ID, which does not help. It should give more useful info for filtering and handling events.

https://docs.rs/tray-icon/0.19.2/tray_icon/menu/struct.MenuEvent.html

ofluffydev avatar Feb 14 '25 18:02 ofluffydev

What info would you like to see in there?

amrbashir avatar Feb 15 '25 13:02 amrbashir

Agree. I was so confused as to why it was missing so many useful things from system-tray.

For example, how amazing it would've been if the event had a reference to the actual menu item where the handler could do any updates to that particular item like checking or unchecking it depending on the user's action.

I've had to stop the migration process of one of my applications to Tauri v2, due to this very issue. Previously with system-tray, all I had to do was this:

/// Adds support for setting the selected state of a menu item inline
trait SelectableMenuItem {
    fn set_selected(self, selected: bool) -> Self;
}

impl SelectableMenuItem for CustomMenuItem {
    fn set_selected(mut self, selected: bool) -> Self {
        self.selected = selected;
        self
    }
}

/// Sets the selected state of a system tray menu item
fn set_menu_item_selected(app: &AppHandle, menu_item_id: &str, selected: bool) {
    app.tray_handle()
        .get_item(menu_item_id)
        .set_selected(selected)
        .expect("Unable to update the system tray menu item");
}

Now with tray-icon, we have to jump through a million hoops to achieve the same functionality by iterating through every single item starting from the root menu just to find the menu item and manipulate it. The most mind-blowing thing is, TrayIcon doesn't even have a getter for the menu. Huh? It has set_menu() but no get_menu()? 😭

m4heshd avatar Mar 18 '25 04:03 m4heshd