@@ -509,13 +509,7 @@ macro_rules! shared_app_impl {
509509 & self ,
510510 handler: F ,
511511 ) {
512- self
513- . manager
514- . menu
515- . global_event_listeners
516- . lock( )
517- . unwrap( )
518- . push( Box :: new( handler) ) ;
512+ self . manager. menu. on_menu_event( handler)
519513 }
520514
521515 /// Registers a global tray icon menu event listener.
@@ -525,35 +519,7 @@ macro_rules! shared_app_impl {
525519 & self ,
526520 handler: F ,
527521 ) {
528- self
529- . manager
530- . tray
531- . global_event_listeners
532- . lock( )
533- . unwrap( )
534- . push( Box :: new( handler) ) ;
535- }
536-
537- /// Gets the first tray icon registered,
538- /// usually the one configured in the Tauri configuration file.
539- #[ cfg( all( desktop, feature = "tray-icon" ) ) ]
540- #[ cfg_attr( docsrs, doc( cfg( all( desktop, feature = "tray-icon" ) ) ) ) ]
541- pub fn tray( & self ) -> Option <TrayIcon <R >> {
542- self . manager. tray. icons. lock( ) . unwrap( ) . first( ) . cloned( )
543- }
544-
545- /// Removes the first tray icon registered, usually the one configured in
546- /// tauri config file, from tauri's internal state and returns it.
547- ///
548- /// Note that dropping the returned icon, will cause the tray icon to disappear.
549- #[ cfg( all( desktop, feature = "tray-icon" ) ) ]
550- #[ cfg_attr( docsrs, doc( cfg( all( desktop, feature = "tray-icon" ) ) ) ) ]
551- pub fn remove_tray( & self ) -> Option <TrayIcon <R >> {
552- let mut icons = self . manager. tray. icons. lock( ) . unwrap( ) ;
553- if !icons. is_empty( ) {
554- return Some ( icons. swap_remove( 0 ) ) ;
555- }
556- None
522+ self . manager. tray. on_tray_icon_event( handler)
557523 }
558524
559525 /// Gets a tray icon using the provided id.
@@ -564,33 +530,21 @@ macro_rules! shared_app_impl {
564530 I : ?Sized ,
565531 TrayIconId : PartialEq <& ' a I >,
566532 {
567- self
568- . manager
569- . tray
570- . icons
571- . lock( )
572- . unwrap( )
573- . iter( )
574- . find( |t| t. id( ) == & id)
575- . cloned( )
533+ self . manager. tray. tray_by_id( id)
576534 }
577535
578536 /// Removes a tray icon using the provided id from tauri's internal state and returns it.
579537 ///
580- /// Note that dropping the returned icon, will cause the tray icon to disappear.
538+ /// Note that dropping the returned icon, may cause the tray icon to disappear
539+ /// if it wasn't cloned somewhere else or referenced by JS.
581540 #[ cfg( all( desktop, feature = "tray-icon" ) ) ]
582541 #[ cfg_attr( docsrs, doc( cfg( all( desktop, feature = "tray-icon" ) ) ) ) ]
583542 pub fn remove_tray_by_id<' a, I >( & self , id: & ' a I ) -> Option <TrayIcon <R >>
584543 where
585544 I : ?Sized ,
586545 TrayIconId : PartialEq <& ' a I >,
587546 {
588- let mut icons = self . manager. tray. icons. lock( ) . unwrap( ) ;
589- let idx = icons. iter( ) . position( |t| t. id( ) == & id) ;
590- if let Some ( idx) = idx {
591- return Some ( icons. swap_remove( idx) ) ;
592- }
593- None
547+ self . manager. tray. remove_tray_by_id( id)
594548 }
595549
596550 /// Gets the app's configuration, defined on the `tauri.conf.json` file.
0 commit comments