@@ -29,6 +29,8 @@ use webview2_com::FocusChangedEventHandler;
2929#[ cfg( windows) ]
3030use windows:: Win32 :: { Foundation :: HWND , System :: WinRT :: EventRegistrationToken } ;
3131#[ cfg( target_os = "macos" ) ]
32+ use wry:: application:: platform:: macos:: EventLoopWindowTargetExtMacOS ;
33+ #[ cfg( target_os = "macos" ) ]
3234use wry:: application:: platform:: macos:: WindowBuilderExtMacOS ;
3335#[ cfg( target_os = "linux" ) ]
3436use wry:: application:: platform:: unix:: { WindowBuilderExtUnix , WindowExtUnix } ;
@@ -1021,6 +1023,13 @@ unsafe impl Send for GtkWindow {}
10211023pub struct RawWindowHandle ( pub raw_window_handle:: RawWindowHandle ) ;
10221024unsafe impl Send for RawWindowHandle { }
10231025
1026+ #[ cfg( target_os = "macos" ) ]
1027+ #[ derive( Debug , Clone ) ]
1028+ pub enum ApplicationMessage {
1029+ Show ,
1030+ Hide ,
1031+ }
1032+
10241033pub enum WindowMessage {
10251034 #[ cfg( desktop) ]
10261035 WithWebview ( Box < dyn FnOnce ( Webview ) + Send > ) ,
@@ -1126,6 +1135,8 @@ pub type CreateWebviewClosure<T> = Box<
11261135
11271136pub enum Message < T : ' static > {
11281137 Task ( Box < dyn FnOnce ( ) + Send > ) ,
1138+ #[ cfg( target_os = "macos" ) ]
1139+ Application ( ApplicationMessage ) ,
11291140 Window ( WebviewId , WindowMessage ) ,
11301141 Webview ( WebviewId , WebviewMessage ) ,
11311142 #[ cfg( all( desktop, feature = "system-tray" ) ) ]
@@ -1786,6 +1797,22 @@ impl<T: UserEvent> RuntimeHandle<T> for WryHandle<T> {
17861797 fn raw_display_handle ( & self ) -> RawDisplayHandle {
17871798 self . context . main_thread . window_target . raw_display_handle ( )
17881799 }
1800+
1801+ #[ cfg( target_os = "macos" ) ]
1802+ fn show ( & self ) -> tauri_runtime:: Result < ( ) > {
1803+ send_user_message (
1804+ & self . context ,
1805+ Message :: Application ( ApplicationMessage :: Show ) ,
1806+ )
1807+ }
1808+
1809+ #[ cfg( target_os = "macos" ) ]
1810+ fn hide ( & self ) -> tauri_runtime:: Result < ( ) > {
1811+ send_user_message (
1812+ & self . context ,
1813+ Message :: Application ( ApplicationMessage :: Hide ) ,
1814+ )
1815+ }
17891816}
17901817
17911818impl < T : UserEvent > Wry < T > {
@@ -1995,6 +2022,16 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
19952022 } ) ;
19962023 }
19972024
2025+ #[ cfg( target_os = "macos" ) ]
2026+ fn show ( & self ) {
2027+ self . event_loop . show_application ( ) ;
2028+ }
2029+
2030+ #[ cfg( target_os = "macos" ) ]
2031+ fn hide ( & self ) {
2032+ self . event_loop . hide_application ( ) ;
2033+ }
2034+
19982035 #[ cfg( desktop) ]
19992036 fn run_iteration < F : FnMut ( RunEvent < T > ) + ' static > ( & mut self , mut callback : F ) -> RunIteration {
20002037 use wry:: application:: platform:: run_return:: EventLoopExtRunReturn ;
@@ -2185,6 +2222,15 @@ fn handle_user_message<T: UserEvent>(
21852222 } = context;
21862223 match message {
21872224 Message :: Task ( task) => task ( ) ,
2225+ #[ cfg( target_os = "macos" ) ]
2226+ Message :: Application ( application_message) => match application_message {
2227+ ApplicationMessage :: Show => {
2228+ event_loop. show_application ( ) ;
2229+ }
2230+ ApplicationMessage :: Hide => {
2231+ event_loop. hide_application ( ) ;
2232+ }
2233+ } ,
21882234 Message :: Window ( id, window_message) => {
21892235 if let WindowMessage :: UpdateMenuItem ( item_id, update) = window_message {
21902236 if let Some ( menu_items) = windows. borrow_mut ( ) . get_mut ( & id) . map ( |w| & mut w. menu_items ) {
0 commit comments