From 9489963e004bfbc83874bb43fa9ddf2777520c50 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Fri, 25 Mar 2022 09:17:32 -0700 Subject: [PATCH] fix(core): deadlock when closing the app on a tray event handler (#3771) --- core/tauri-runtime-wry/src/lib.rs | 5 +++-- core/tauri-runtime-wry/src/system_tray.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 6ea22bd4a..e14c9b19d 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -1832,7 +1832,7 @@ impl Runtime for Wry { .listeners .lock() .unwrap() - .insert(id, Box::new(f)); + .insert(id, Arc::new(Box::new(f))); id } @@ -2355,7 +2355,8 @@ fn handle_event_loop( .. } => { let event = SystemTrayEvent::MenuItemClick(menu_id.0); - for handler in tray_context.listeners.lock().unwrap().values() { + let listeners = tray_context.listeners.lock().unwrap().clone(); + for handler in listeners.values() { handler(&event); } } diff --git a/core/tauri-runtime-wry/src/system_tray.rs b/core/tauri-runtime-wry/src/system_tray.rs index 568c08433..db16ee0ae 100644 --- a/core/tauri-runtime-wry/src/system_tray.rs +++ b/core/tauri-runtime-wry/src/system_tray.rs @@ -32,7 +32,7 @@ use std::{ }; pub type SystemTrayEventHandler = Box; -pub type SystemTrayEventListeners = Arc>>; +pub type SystemTrayEventListeners = Arc>>>; pub type SystemTrayItems = Arc>>; #[derive(Debug, Clone)]