Skip to content

Commit

Permalink
fix(core): panic on menu event with minimized windows, closes tauri-a…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored and dceddia committed May 13, 2022
1 parent 4efcb39 commit 23059c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/fix-menu-event-macos.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 12 additions & 1 deletion core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,18 @@ fn handle_event_loop<T: UserEvent>(
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,
};
Expand Down

0 comments on commit 23059c0

Please sign in to comment.