From 409d8358b6bd0422f81631585b19e9aa7909bf92 Mon Sep 17 00:00:00 2001 From: Christopher Serr Date: Tue, 20 Jan 2026 23:42:45 +0100 Subject: [PATCH] Fix `android_runtime_lock` not being `cfg` guarded (#5244) The `android_runtime_lock` wasn't properly `cfg` guarded in various places, so it got included on all operating systems, not just Android by accident. This causes deadlocks when trying to use `muda`. --- packages/desktop/src/android_sync_lock.rs | 1 + packages/desktop/src/app.rs | 4 ++-- packages/desktop/src/webview.rs | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/desktop/src/android_sync_lock.rs b/packages/desktop/src/android_sync_lock.rs index b52ef2c39..f8e5a1a8d 100644 --- a/packages/desktop/src/android_sync_lock.rs +++ b/packages/desktop/src/android_sync_lock.rs @@ -1,6 +1,7 @@ /// This is a hack to get around the fact that wry is currently not thread safe on android /// /// We want to acquire this mutex before doing anything with the virtualdom directly +#[cfg(target_os = "android")] pub fn android_runtime_lock() -> std::sync::MutexGuard<'static, ()> { use std::sync::{Mutex, OnceLock}; diff --git a/packages/desktop/src/app.rs b/packages/desktop/src/app.rs index 56bd0b417..1bb9f96ee 100644 --- a/packages/desktop/src/app.rs +++ b/packages/desktop/src/app.rs @@ -330,9 +330,9 @@ impl App { { // This is a place where wry says it's threadsafe but it's actually not. // If we're patching the app, we want to make sure it's not going to progress in the interim. - let lock = crate::android_sync_lock::android_runtime_lock(); + #[cfg(target_os = "android")] + let _lock = crate::android_sync_lock::android_runtime_lock(); dioxus_devtools::apply_changes(&webview.dom, &hr_msg); - drop(lock); } webview.poll_vdom(); diff --git a/packages/desktop/src/webview.rs b/packages/desktop/src/webview.rs index d6a0d5738..38421c92c 100644 --- a/packages/desktop/src/webview.rs +++ b/packages/desktop/src/webview.rs @@ -78,6 +78,7 @@ impl WebviewEdits { let response = match serde_json::from_slice(&data_from_header) { Ok(event) => { // we need to wait for the mutex lock to let us munge the main thread.. + #[cfg(target_os = "android")] let _lock = crate::android_sync_lock::android_runtime_lock(); self.handle_html_event(event) } @@ -557,6 +558,7 @@ impl WebviewInstance { { // lock the hack-ed in lock sync wry has some thread-safety issues with event handlers and async tasks + #[cfg(target_os = "android")] let _lock = crate::android_sync_lock::android_runtime_lock(); let fut = self.dom.wait_for_work(); pin_mut!(fut); @@ -568,6 +570,7 @@ impl WebviewInstance { } // lock the hack-ed in lock sync wry has some thread-safety issues with event handlers + #[cfg(target_os = "android")] let _lock = crate::android_sync_lock::android_runtime_lock(); self.edits