diff --git a/packages/desktop/src/webview.rs b/packages/desktop/src/webview.rs index ec0e8f01a..df662aaa9 100644 --- a/packages/desktop/src/webview.rs +++ b/packages/desktop/src/webview.rs @@ -261,7 +261,14 @@ impl WebviewInstance { asset_handlers, edits ]; + + #[cfg(feature = "tokio_runtime")] + let tokio_rt = tokio::runtime::Handle::current(); + move |_id: WebViewId, request, responder: RequestAsyncResponder| { + #[cfg(feature = "tokio_runtime")] + let _guard = tokio_rt.enter(); + protocol::desktop_handler( request, asset_handlers.clone(), @@ -382,11 +389,25 @@ impl WebviewInstance { } for (name, handler) in cfg.protocols.drain(..) { - webview = webview.with_custom_protocol(name, handler); + #[cfg(feature = "tokio_runtime")] + let tokio_rt = tokio::runtime::Handle::current(); + + webview = webview.with_custom_protocol(name, move |a, b| { + #[cfg(feature = "tokio_runtime")] + let _guard = tokio_rt.enter(); + handler(a, b) + }); } for (name, handler) in cfg.asynchronous_protocols.drain(..) { - webview = webview.with_asynchronous_custom_protocol(name, handler); + #[cfg(feature = "tokio_runtime")] + let tokio_rt = tokio::runtime::Handle::current(); + + webview = webview.with_asynchronous_custom_protocol(name, move |a, b, c| { + #[cfg(feature = "tokio_runtime")] + let _guard = tokio_rt.enter(); + handler(a, b, c) + }); } const INITIALIZATION_SCRIPT: &str = r#"