From 63ae30f1873548f6fed41a32244b2b9209a1aaed Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sun, 26 Sep 2021 01:48:13 -0300 Subject: [PATCH] fix(core): deadlocks on previous commit --- core/tauri-runtime-wry/src/lib.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index bc591b353..8a0c6bafe 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -1888,8 +1888,11 @@ fn handle_user_message( match message { Message::Task(task) => task(), Message::Window(id, window_message) => { - let mut windows = windows.lock().expect("poisoned webview collection"); - if let Some(webview) = windows.get_mut(&id) { + if let Some(webview) = windows + .lock() + .expect("poisoned webview collection") + .get_mut(&id) + { let window = webview.inner.window(); match window_message { // Getters @@ -1961,7 +1964,7 @@ fn handle_user_message( on_window_close( callback, id, - &mut windows, + windows.lock().expect("poisoned webview collection"), control_flow, #[cfg(target_os = "linux")] window_event_listeners, @@ -2314,11 +2317,13 @@ fn handle_event_loop( } match event { WryWindowEvent::CloseRequested => { - let mut windows = windows.lock().expect("poisoned webview collection"); let (tx, rx) = channel(); - if let Some(w) = windows.get(&window_id) { + let windows_guard = windows.lock().expect("poisoned webview collection"); + if let Some(w) = windows_guard.get(&window_id) { + let label = w.label.clone(); + drop(windows_guard); callback(RunEvent::CloseRequested { - label: w.label.clone(), + label, signal_tx: tx, }); if let Ok(true) = rx.try_recv() { @@ -2326,7 +2331,7 @@ fn handle_event_loop( on_window_close( callback, window_id, - &mut windows, + windows.lock().expect("poisoned webview collection"), control_flow, #[cfg(target_os = "linux")] window_event_listeners, @@ -2380,16 +2385,18 @@ fn handle_event_loop( fn on_window_close<'a>( callback: &'a (dyn Fn(RunEvent) + 'static), window_id: WindowId, - windows: &mut MutexGuard<'a, HashMap>, + mut windows: MutexGuard<'a, HashMap>, control_flow: &mut ControlFlow, #[cfg(target_os = "linux")] window_event_listeners: &WindowEventListeners, menu_event_listeners: MenuEventListeners, ) { if let Some(webview) = windows.remove(&window_id) { + let is_empty = windows.is_empty(); + drop(windows); menu_event_listeners.lock().unwrap().remove(&window_id); callback(RunEvent::WindowClose(webview.label.clone())); - if windows.is_empty() { + if is_empty { let (tx, rx) = channel(); callback(RunEvent::ExitRequested { window_label: webview.label,