mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-03 20:31:54 +03:00
actually apply item changes
This commit is contained in:
parent
a9cc84dbdf
commit
66abc2199c
@ -3,6 +3,3 @@
|
||||
---
|
||||
|
||||
Ensure system tray is created when the event loop is ready. Menu item modifications are not applied unless it is ready.
|
||||
If you need to modify the menu items immediately after creating a tray in the setup hook,
|
||||
either directly configure the menu item change when creating the menu or move the code when `RunEvent::Ready` is fired.
|
||||
See https://docs.rs/tauri/latest/tauri/struct.App.html#method.run for more information.
|
||||
|
@ -195,8 +195,31 @@ impl<T: UserEvent> TrayHandle for SystemTrayHandle<T> {
|
||||
|
||||
fn update_item(&self, id: u16, update: MenuUpdate) -> Result<()> {
|
||||
if !self.context.is_event_loop_ready.load(Ordering::Relaxed) {
|
||||
if let Some(_pending) = &mut *self.pending.0.borrow_mut() {
|
||||
// do nothing - menu items not available yet
|
||||
if let Some(pending) = &mut *self.pending.0.borrow_mut() {
|
||||
if let Some(menu) = &mut pending.menu {
|
||||
for item in &mut menu.items {
|
||||
if let SystemTrayMenuEntry::CustomItem(item) = item {
|
||||
if item.id == id {
|
||||
match update {
|
||||
MenuUpdate::SetEnabled(enabled) => {
|
||||
item.enabled = enabled;
|
||||
}
|
||||
MenuUpdate::SetTitle(title) => {
|
||||
item.title = title;
|
||||
}
|
||||
MenuUpdate::SetSelected(selected) => {
|
||||
item.selected = selected;
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
MenuUpdate::SetNativeImage(img) => {
|
||||
item.native_image.replace(img);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user