@@ -62,6 +62,8 @@ pub struct SystemTray {
62
62
menu_on_left_click_set : bool ,
63
63
#[ cfg( target_os = "macos" ) ]
64
64
icon_as_template_set : bool ,
65
+ #[ cfg( target_os = "macos" ) ]
66
+ title : Option < String > ,
65
67
}
66
68
67
69
impl fmt:: Debug for SystemTray {
@@ -94,6 +96,8 @@ impl Default for SystemTray {
94
96
icon_as_template_set : false ,
95
97
#[ cfg( target_os = "macos" ) ]
96
98
menu_on_left_click_set : false ,
99
+ #[ cfg( target_os = "macos" ) ]
100
+ title : None ,
97
101
}
98
102
}
99
103
}
@@ -228,6 +232,31 @@ impl SystemTray {
228
232
self
229
233
}
230
234
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
+
231
260
/// Sets the event listener for this system tray.
232
261
///
233
262
/// # Examples
@@ -342,6 +371,14 @@ impl SystemTray {
342
371
. as_ref ( )
343
372
. map_or ( false , |t| t. menu_on_left_click ) ;
344
373
}
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
+ }
345
382
}
346
383
347
384
let tray_id = self . id . clone ( ) ;
@@ -372,6 +409,9 @@ impl SystemTray {
372
409
{
373
410
runtime_tray = runtime_tray. with_icon_as_template ( self . icon_as_template ) ;
374
411
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
+ }
375
415
}
376
416
377
417
let id = runtime_tray. id ;
@@ -564,6 +604,12 @@ impl<R: Runtime> SystemTrayHandle<R> {
564
604
. map_err ( Into :: into)
565
605
}
566
606
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
+
567
613
/// Destroys this system tray.
568
614
pub fn destroy ( & self ) -> crate :: Result < ( ) > {
569
615
self . inner . destroy ( ) . map_err ( Into :: into)
0 commit comments