Skip to content

Commit 409d835

Browse files
authored
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`.
1 parent d01a820 commit 409d835

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

‎packages/desktop/src/android_sync_lock.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// This is a hack to get around the fact that wry is currently not thread safe on android
22
///
33
/// We want to acquire this mutex before doing anything with the virtualdom directly
4+
#[cfg(target_os = "android")]
45
pub fn android_runtime_lock() -> std::sync::MutexGuard<'static, ()> {
56
use std::sync::{Mutex, OnceLock};
67

‎packages/desktop/src/app.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ impl App {
330330
{
331331
// This is a place where wry says it's threadsafe but it's actually not.
332332
// If we're patching the app, we want to make sure it's not going to progress in the interim.
333-
let lock = crate::android_sync_lock::android_runtime_lock();
333+
#[cfg(target_os = "android")]
334+
let _lock = crate::android_sync_lock::android_runtime_lock();
334335
dioxus_devtools::apply_changes(&webview.dom, &hr_msg);
335-
drop(lock);
336336
}
337337

338338
webview.poll_vdom();

‎packages/desktop/src/webview.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl WebviewEdits {
7878
let response = match serde_json::from_slice(&data_from_header) {
7979
Ok(event) => {
8080
// we need to wait for the mutex lock to let us munge the main thread..
81+
#[cfg(target_os = "android")]
8182
let _lock = crate::android_sync_lock::android_runtime_lock();
8283
self.handle_html_event(event)
8384
}
@@ -557,6 +558,7 @@ impl WebviewInstance {
557558

558559
{
559560
// lock the hack-ed in lock sync wry has some thread-safety issues with event handlers and async tasks
561+
#[cfg(target_os = "android")]
560562
let _lock = crate::android_sync_lock::android_runtime_lock();
561563
let fut = self.dom.wait_for_work();
562564
pin_mut!(fut);
@@ -568,6 +570,7 @@ impl WebviewInstance {
568570
}
569571

570572
// lock the hack-ed in lock sync wry has some thread-safety issues with event handlers
573+
#[cfg(target_os = "android")]
571574
let _lock = crate::android_sync_lock::android_runtime_lock();
572575

573576
self.edits

0 commit comments

Comments
 (0)