@@ -67,6 +67,9 @@ pub type SetupHook<R> =
6767 Box < dyn FnOnce ( & mut App < R > ) -> std:: result:: Result < ( ) , Box < dyn std:: error:: Error > > + Send > ;
6868/// A closure that is run every time a page starts or finishes loading.
6969pub type OnPageLoad < R > = dyn Fn ( & Webview < R > , & PageLoadPayload < ' _ > ) + Send + Sync + ' static ;
70+ /// A closure that is run when the web content process terminates.
71+ #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
72+ pub type OnWebContentProcessTerminate < R > = dyn Fn ( & Webview < R > ) + Send + Sync + ' static ;
7073pub type ChannelInterceptor < R > =
7174 Box < dyn Fn ( & Webview < R > , CallbackFn , usize , & InvokeResponseBody ) -> bool + Send + Sync + ' static > ;
7275
@@ -1483,6 +1486,10 @@ pub struct Builder<R: Runtime> {
14831486 /// Page load hook.
14841487 on_page_load : Option < Arc < OnPageLoad < R > > > ,
14851488
1489+ /// Web content process termination hook.
1490+ #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
1491+ on_web_content_process_terminate : Option < Arc < OnWebContentProcessTerminate < R > > > ,
1492+
14861493 /// All passed plugins
14871494 plugins : PluginStore < R > ,
14881495
@@ -1569,6 +1576,8 @@ impl<R: Runtime> Builder<R> {
15691576 . into_string ( ) ,
15701577 channel_interceptor : None ,
15711578 on_page_load : None ,
1579+ #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
1580+ on_web_content_process_terminate : None ,
15721581 plugins : PluginStore :: default ( ) ,
15731582 uri_scheme_protocols : Default :: default ( ) ,
15741583 state : StateManager :: new ( ) ,
@@ -1749,6 +1758,23 @@ tauri::Builder::default()
17491758 self
17501759 }
17511760
1761+ /// Defines the web content process termination hook.
1762+ ///
1763+ /// ## Platform-specific
1764+ ///
1765+ /// - **Linux / Windows / Android:** Unsupported.
1766+ #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
1767+ #[ must_use]
1768+ pub fn on_web_content_process_terminate < F > ( mut self , on_web_content_process_terminate : F ) -> Self
1769+ where
1770+ F : Fn ( & Webview < R > ) + Send + Sync + ' static ,
1771+ {
1772+ self
1773+ . on_web_content_process_terminate
1774+ . replace ( Arc :: new ( on_web_content_process_terminate) ) ;
1775+ self
1776+ }
1777+
17521778 /// Adds a Tauri application plugin.
17531779 ///
17541780 /// A plugin is created using the [`crate::plugin::Builder`] struct.Check its documentation for more information.
@@ -2197,6 +2223,8 @@ tauri::Builder::default()
21972223 self . plugins ,
21982224 self . invoke_handler ,
21992225 self . on_page_load ,
2226+ #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
2227+ self . on_web_content_process_terminate ,
22002228 self . uri_scheme_protocols ,
22012229 self . state ,
22022230 #[ cfg( desktop) ]
0 commit comments