From 6456576a7766eceaa78cec7f19443cdd9cc3fc0e Mon Sep 17 00:00:00 2001 From: Moritz Hedtke Date: Sat, 4 Oct 2025 03:31:56 +0200 Subject: [PATCH] Don't try launching a tokio runtime if we are already within one (#4699) --- packages/desktop/src/launch.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/desktop/src/launch.rs b/packages/desktop/src/launch.rs index d159dac8f..550b0af25 100644 --- a/packages/desktop/src/launch.rs +++ b/packages/desktop/src/launch.rs @@ -115,15 +115,24 @@ pub fn launch_virtual_dom_blocking(virtual_dom: VirtualDom, mut desktop_config: pub fn launch_virtual_dom(virtual_dom: VirtualDom, desktop_config: Config) -> ! { #[cfg(feature = "tokio_runtime")] { - tokio::runtime::Builder::new_multi_thread() - .enable_all() - .build() - .unwrap() - .block_on(tokio::task::unconstrained(async move { - launch_virtual_dom_blocking(virtual_dom, desktop_config) - })); + if let std::result::Result::Ok(handle) = tokio::runtime::Handle::try_current() { + assert_ne!( + handle.runtime_flavor(), + tokio::runtime::RuntimeFlavor::CurrentThread, + "The tokio current-thread runtime does not work with dioxus event handling" + ); + launch_virtual_dom_blocking(virtual_dom, desktop_config); + } else { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() + .block_on(tokio::task::unconstrained(async move { + launch_virtual_dom_blocking(virtual_dom, desktop_config) + })); - unreachable!("The desktop launch function will never exit") + unreachable!("The desktop launch function will never exit") + } } #[cfg(not(feature = "tokio_runtime"))]