Skip to content

Commit f123267

Browse files
feat: expose internal TrayIcon (#13959)
1 parent 0c402bf commit f123267

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

.changes/expose-inner-tray-icon.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri": 'minor:enhance'
3+
---
4+
5+
Introduce `with_inner_tray_icon` for Tauri `TrayIcon` to access the inner platform-specific tray icon.
6+
7+
Note that `tray-icon` crate may be updated in minor releases of Tauri.
8+
Therefore, it’s recommended to pin Tauri to at least a minor version when you’re using `with_inner_tray_icon`.

crates/tauri/src/tray/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,18 @@ impl<R: Runtime> TrayIcon<R> {
603603
})
604604
})
605605
}
606+
607+
/// Do something with the inner [`tray_icon::TrayIcon`] on main thread
608+
///
609+
/// Note that `tray-icon` crate may be updated in minor releases of Tauri.
610+
/// Therefore, it’s recommended to pin Tauri to at least a minor version when you’re using `with_inner_tray_icon`.
611+
pub fn with_inner_tray_icon<F, T>(&self, f: F) -> crate::Result<T>
612+
where
613+
F: FnOnce(&tray_icon::TrayIcon) -> T + Send + 'static,
614+
T: Send + 'static,
615+
{
616+
run_item_main_thread!(self, |self_: Self| { f(&self_.inner) })
617+
}
606618
}
607619

608620
impl<R: Runtime> Resource for TrayIcon<R> {

0 commit comments

Comments
 (0)