@@ -62,6 +62,8 @@ pub struct SystemTray {
6262 menu_on_left_click_set : bool ,
6363 #[ cfg( target_os = "macos" ) ]
6464 icon_as_template_set : bool ,
65+ #[ cfg( target_os = "macos" ) ]
66+ title : Option < String > ,
6567}
6668
6769impl fmt:: Debug for SystemTray {
@@ -94,6 +96,8 @@ impl Default for SystemTray {
9496 icon_as_template_set : false ,
9597 #[ cfg( target_os = "macos" ) ]
9698 menu_on_left_click_set : false ,
99+ #[ cfg( target_os = "macos" ) ]
100+ title : None ,
97101 }
98102 }
99103}
@@ -228,6 +232,31 @@ impl SystemTray {
228232 self
229233 }
230234
235+ /// Sets the menu title`
236+ ///
237+ /// # Examples
238+ ///
239+ /// ```
240+ /// use tauri::SystemTray;
241+ ///
242+ /// tauri::Builder::default()
243+ /// .setup(|app| {
244+ /// let mut tray_builder = SystemTray::new();
245+ /// #[cfg(target_os = "macos")]
246+ /// {
247+ /// tray_builder = tray_builder.with_title("My App");
248+ /// }
249+ /// let tray_handle = tray_builder.build(app)?;
250+ /// Ok(())
251+ /// });
252+ /// ```
253+ #[ cfg( target_os = "macos" ) ]
254+ #[ must_use]
255+ pub fn with_title ( mut self , title : & str ) -> Self {
256+ self . title = Some ( title. to_owned ( ) ) ;
257+ self
258+ }
259+
231260 /// Sets the event listener for this system tray.
232261 ///
233262 /// # Examples
@@ -342,6 +371,14 @@ impl SystemTray {
342371 . as_ref ( )
343372 . map_or ( false , |t| t. menu_on_left_click ) ;
344373 }
374+ if self . title . is_none ( ) {
375+ self . title = manager
376+ . config ( )
377+ . tauri
378+ . system_tray
379+ . as_ref ( )
380+ . and_then ( |t| t. title . clone ( ) )
381+ }
345382 }
346383
347384 let tray_id = self . id . clone ( ) ;
@@ -372,6 +409,9 @@ impl SystemTray {
372409 {
373410 runtime_tray = runtime_tray. with_icon_as_template ( self . icon_as_template ) ;
374411 runtime_tray = runtime_tray. with_menu_on_left_click ( self . menu_on_left_click ) ;
412+ if let Some ( title) = self . title {
413+ runtime_tray = runtime_tray. with_title ( & title) ;
414+ }
375415 }
376416
377417 let id = runtime_tray. id ;
@@ -564,6 +604,12 @@ impl<R: Runtime> SystemTrayHandle<R> {
564604 . map_err ( Into :: into)
565605 }
566606
607+ /// Adds the title to the tray menu
608+ #[ cfg( target_os = "macos" ) ]
609+ pub fn set_title ( & self , title : & str ) -> crate :: Result < ( ) > {
610+ self . inner . set_title ( title) . map_err ( Into :: into)
611+ }
612+
567613 /// Destroys this system tray.
568614 pub fn destroy ( & self ) -> crate :: Result < ( ) > {
569615 self . inner . destroy ( ) . map_err ( Into :: into)
0 commit comments