-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Labels
scope: coreCore packages of TauriCore packages of Tauristatus: backlogIssue is ready and we can work on itIssue is ready and we can work on ittype: feature request
Description
Describe the problem
Currently, when trying to use an unknown system tray menu item, the get_item function panics
window.app_handle().tray_handle().get_item("unknown_id") => panic!("item id not found")
Describe the solution you'd like
Ideally the get_item should return an Option<SystemTrayMenuItemHandle<R>>
Should also apply to the menu.get_item(id) function as well?
That way the user can execute, without fear of a panic
if Some(tray_entry) = window.app_handle().tray_handle().get_item("known_id") {
tray_entry.set_title("It works!").unwrap();
}
// or
window.app_handle().tray_handle().get_item("known_id").map(|i|i.set_title("It works!").unwrap());At first glance to me - I haven't tested this fully yet, but on my basic app it's working - it looks like the get_item function could be changed to
impl<R: Runtime> SystemTrayHandle<R> {
/// Gets an Option<handle> to the menu item that has the specified `id`.
pub fn get_item(&self, id: MenuIdRef<'_>) -> Option<SystemTrayMenuItemHandle<R>> {
self.ids.lock().unwrap().iter().find(|i|i.1 == id).and_then(|i| Some(SystemTrayMenuItemHandle {
id: *i.0,
tray_handler: self.inner.clone(),
})
)
}Or am I missing something really obvious / completely misunderstanding the component model?
Alternatives considered
No response
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
scope: coreCore packages of TauriCore packages of Tauristatus: backlogIssue is ready and we can work on itIssue is ready and we can work on ittype: feature request