fix: tokio rt is not set when calling handlers (#4850)

This commit is contained in:
Jonathan Kelley authored and GitHub committed 2025-10-27 14:30:23 -07:00
1 parent c3ff0c0ab3
commit 9f0bacc85c
1 file changed
+23 -2
+23 -2
View File
@@ -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#"