Skip to content

Commit

Permalink
enhance docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 13, 2023
1 parent 2c20d6b commit 6842939
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,18 @@ pub enum RunEvent {
MainEventsCleared,
/// Emitted when the user wants to open the specified resource with the app.
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg_attr(doc_cfg, doc(cfg(any(target_os = "macos", feature = "ios"))))]
Opened {
/// The URL of the resources that is being open.
urls: Vec<url::Url>,
},
/// An event from a menu item, could be on the window menu bar, application menu bar (on macOS) or tray icon menu.
#[cfg(desktop)]
#[cfg_attr(doc_cfg, doc(cfg(desktop)))]
MenuEvent(crate::menu::MenuEvent),
/// An event from a tray icon.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
TrayIconEvent(crate::tray::TrayIconEvent),
}

Expand Down Expand Up @@ -517,6 +520,7 @@ macro_rules! shared_app_impl {

/// Registers a global tray icon menu event listener.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub fn on_tray_icon_event<F: Fn(&AppHandle<R>, TrayIconEvent) + Send + Sync + 'static>(
&self,
handler: F,
Expand All @@ -533,6 +537,7 @@ macro_rules! shared_app_impl {
/// Gets the first tray icon registerd, usually the one configured in
/// tauri config file.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub fn tray(&self) -> Option<TrayIcon<R>> {
self
.manager
Expand All @@ -549,6 +554,7 @@ macro_rules! shared_app_impl {
///
/// Note that dropping the returned icon, will cause the tray icon to disappear.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub fn remove_tray(&self) -> Option<TrayIcon<R>> {
let mut tray_icons = self.manager.inner.tray_icons.lock().unwrap();
if !tray_icons.is_empty() {
Expand All @@ -559,6 +565,7 @@ macro_rules! shared_app_impl {

/// Gets a tray icon using the provided id.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub fn tray_by_id<'a, I>(&self, id: &'a I) -> Option<TrayIcon<R>>
where
I: ?Sized,
Expand All @@ -579,6 +586,7 @@ macro_rules! shared_app_impl {
///
/// Note that dropping the returned icon, will cause the tray icon to disappear.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub fn remove_tray_by_id<'a, I>(&self, id: &'a I) -> Option<TrayIcon<R>>
where
I: ?Sized,
Expand Down
2 changes: 2 additions & 0 deletions core/tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ pub enum Error {
/// Tray icon error.
#[error("tray icon error: {0}")]
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
Tray(#[from] tray_icon::Error),
/// Bad tray icon error.
#[error(transparent)]
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
BadTrayIcon(#[from] tray_icon::BadIcon),
}
5 changes: 5 additions & 0 deletions core/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub mod scope;
mod state;

#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
pub mod tray;
pub use tauri_utils as utils;

Expand Down Expand Up @@ -260,6 +261,7 @@ pub enum EventLoopMessage {
MenuEvent(menu::MenuEvent),
/// An event from a menu item, could be on the window menu bar, application menu bar (on macOS) or tray icon menu.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
TrayIconEvent(tray::TrayIconEvent),
}

Expand Down Expand Up @@ -462,13 +464,15 @@ impl<A: Assets> Context<A> {

/// The icon to use on the system tray UI.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[inline(always)]
pub fn tray_icon(&self) -> Option<&Icon> {
self.tray_icon.as_ref()
}

/// A mutable reference to the icon to use on the tray icon.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[inline(always)]
pub fn tray_icon_mut(&mut self) -> &mut Option<Icon> {
&mut self.tray_icon
Expand Down Expand Up @@ -519,6 +523,7 @@ impl<A: Assets> Context<A> {

/// Sets the app tray icon.
#[cfg(all(desktop, feature = "tray-icon"))]
#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "tray-icon"))))]
#[inline(always)]
pub fn set_tray_icon(&mut self, icon: Icon) {
self.tray_icon.replace(icon);
Expand Down

0 comments on commit 6842939

Please sign in to comment.