diff --git a/.changes/expose-inner-tray-icon.md b/.changes/expose-inner-tray-icon.md new file mode 100644 index 000000000..fdb46e173 --- /dev/null +++ b/.changes/expose-inner-tray-icon.md @@ -0,0 +1,8 @@ +--- +"tauri": 'minor:enhance' +--- + +Introduce `with_inner_tray_icon` for Tauri `TrayIcon` to access the inner platform-specific tray icon. + +Note that `tray-icon` crate may be updated in minor releases of Tauri. +Therefore, it’s recommended to pin Tauri to at least a minor version when you’re using `with_inner_tray_icon`. diff --git a/crates/tauri/src/tray/mod.rs b/crates/tauri/src/tray/mod.rs index 59997f222..5980844c9 100644 --- a/crates/tauri/src/tray/mod.rs +++ b/crates/tauri/src/tray/mod.rs @@ -603,6 +603,18 @@ impl TrayIcon { }) }) } + + /// Do something with the inner [`tray_icon::TrayIcon`] on main thread + /// + /// Note that `tray-icon` crate may be updated in minor releases of Tauri. + /// Therefore, it’s recommended to pin Tauri to at least a minor version when you’re using `with_inner_tray_icon`. + pub fn with_inner_tray_icon(&self, f: F) -> crate::Result + where + F: FnOnce(&tray_icon::TrayIcon) -> T + Send + 'static, + T: Send + 'static, + { + run_item_main_thread!(self, |self_: Self| { f(&self_.inner) }) + } } impl Resource for TrayIcon {