From 70ff55c1aa69ed59cd2a78d865e1cb398ef2a4ba Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Wed, 20 Apr 2022 07:30:59 -0700 Subject: [PATCH] fix(core): panic on menu event with minimized windows, closes #3902 (#3918) --- .changes/fix-menu-event-macos.md | 6 ++++++ core/tauri-runtime-wry/src/lib.rs | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-menu-event-macos.md diff --git a/.changes/fix-menu-event-macos.md b/.changes/fix-menu-event-macos.md new file mode 100644 index 000000000..a6f777061 --- /dev/null +++ b/.changes/fix-menu-event-macos.md @@ -0,0 +1,6 @@ +--- +"tauri": patch +"tauri-runtime-wry": patch +--- + +Fixes a panic when a menu event is triggered when all windows are minimized on macOS. diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index 006236143..069da7572 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -2395,7 +2395,18 @@ fn handle_event_loop( origin: MenuType::MenuBar, .. } => { - let window_id = window_id.unwrap(); // always Some on MenuBar event + #[allow(unused_mut)] + let mut window_id = window_id.unwrap(); // always Some on MenuBar event + + #[cfg(target_os = "macos")] + { + // safety: we're only checking to see if the window_id is 0 + // which is the value sent by macOS when the window is minimized (NSApplication::sharedApplication::mainWindow is null) + if window_id == unsafe { WindowId::dummy() } { + window_id = *webview_id_map.0.lock().unwrap().keys().next().unwrap(); + } + } + let event = MenuEvent { menu_item_id: menu_id.0, };