From 9f0bacc85ca2291cace46662dd478d09795c78a0 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Mon, 27 Oct 2025 14:30:23 -0700 Subject: [PATCH] fix: tokio rt is not set when calling handlers (#4850) --- packages/desktop/src/webview.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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#"