|
@@ -62,6 +62,8 @@ pub struct SystemTray {
|
|
|
menu_on_left_click_set: bool,
|
|
|
#[cfg(target_os = "macos")]
|
|
|
icon_as_template_set: bool,
|
|
|
+ #[cfg(target_os = "macos")]
|
|
|
+ title: Option<String>,
|
|
|
}
|
|
|
|
|
|
impl fmt::Debug for SystemTray {
|
|
@@ -94,6 +96,8 @@ impl Default for SystemTray {
|
|
|
icon_as_template_set: false,
|
|
|
#[cfg(target_os = "macos")]
|
|
|
menu_on_left_click_set: false,
|
|
|
+ #[cfg(target_os = "macos")]
|
|
|
+ title: None,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -228,6 +232,31 @@ impl SystemTray {
|
|
|
self
|
|
|
}
|
|
|
|
|
|
+ /// Sets the menu title`
|
|
|
+ ///
|
|
|
+ /// # Examples
|
|
|
+ ///
|
|
|
+ /// ```
|
|
|
+ /// use tauri::SystemTray;
|
|
|
+ ///
|
|
|
+ /// tauri::Builder::default()
|
|
|
+ /// .setup(|app| {
|
|
|
+ /// let mut tray_builder = SystemTray::new();
|
|
|
+ /// #[cfg(target_os = "macos")]
|
|
|
+ /// {
|
|
|
+ /// tray_builder = tray_builder.with_title("My App");
|
|
|
+ /// }
|
|
|
+ /// let tray_handle = tray_builder.build(app)?;
|
|
|
+ /// Ok(())
|
|
|
+ /// });
|
|
|
+ /// ```
|
|
|
+ #[cfg(target_os = "macos")]
|
|
|
+ #[must_use]
|
|
|
+ pub fn with_title(mut self, title: &str) -> Self {
|
|
|
+ self.title = Some(title.to_owned());
|
|
|
+ self
|
|
|
+ }
|
|
|
+
|
|
|
/// Sets the event listener for this system tray.
|
|
|
///
|
|
|
/// # Examples
|
|
@@ -342,6 +371,14 @@ impl SystemTray {
|
|
|
.as_ref()
|
|
|
.map_or(false, |t| t.menu_on_left_click);
|
|
|
}
|
|
|
+ if self.title.is_none() {
|
|
|
+ self.title = manager
|
|
|
+ .config()
|
|
|
+ .tauri
|
|
|
+ .system_tray
|
|
|
+ .as_ref()
|
|
|
+ .and_then(|t| t.title.clone())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
let tray_id = self.id.clone();
|
|
@@ -372,6 +409,9 @@ impl SystemTray {
|
|
|
{
|
|
|
runtime_tray = runtime_tray.with_icon_as_template(self.icon_as_template);
|
|
|
runtime_tray = runtime_tray.with_menu_on_left_click(self.menu_on_left_click);
|
|
|
+ if let Some(title) = self.title {
|
|
|
+ runtime_tray = runtime_tray.with_title(&title);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
let id = runtime_tray.id;
|
|
@@ -564,6 +604,12 @@ impl<R: Runtime> SystemTrayHandle<R> {
|
|
|
.map_err(Into::into)
|
|
|
}
|
|
|
|
|
|
+ /// Adds the title to the tray menu
|
|
|
+ #[cfg(target_os = "macos")]
|
|
|
+ pub fn set_title(&self, title: &str) -> crate::Result<()> {
|
|
|
+ self.inner.set_title(title).map_err(Into::into)
|
|
|
+ }
|
|
|
+
|
|
|
/// Destroys this system tray.
|
|
|
pub fn destroy(&self) -> crate::Result<()> {
|
|
|
self.inner.destroy().map_err(Into::into)
|