Skip to content

Commit 70ff55c

Browse files
authored
fix(core): panic on menu event with minimized windows, closes #3902 (#3918)
1 parent 3bd3d92 commit 70ff55c

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

.changes/fix-menu-event-macos.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch
3+
"tauri-runtime-wry": patch
4+
---
5+
6+
Fixes a panic when a menu event is triggered when all windows are minimized on macOS.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2395,7 +2395,18 @@ fn handle_event_loop<T: UserEvent>(
23952395
origin: MenuType::MenuBar,
23962396
..
23972397
} => {
2398-
let window_id = window_id.unwrap(); // always Some on MenuBar event
2398+
#[allow(unused_mut)]
2399+
let mut window_id = window_id.unwrap(); // always Some on MenuBar event
2400+
2401+
#[cfg(target_os = "macos")]
2402+
{
2403+
// safety: we're only checking to see if the window_id is 0
2404+
// which is the value sent by macOS when the window is minimized (NSApplication::sharedApplication::mainWindow is null)
2405+
if window_id == unsafe { WindowId::dummy() } {
2406+
window_id = *webview_id_map.0.lock().unwrap().keys().next().unwrap();
2407+
}
2408+
}
2409+
23992410
let event = MenuEvent {
24002411
menu_item_id: menu_id.0,
24012412
};

0 commit comments

Comments
 (0)