diff --git a/.changes/macos-fix-set-tray-menu.md b/.changes/macos-fix-set-tray-menu.md new file mode 100644 index 000000000..d910c5e98 --- /dev/null +++ b/.changes/macos-fix-set-tray-menu.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +On macOS, fix `SystemTrayEvent` not emitted after calling `set_menu`. diff --git a/src/platform_impl/macos/system_tray.rs b/src/platform_impl/macos/system_tray.rs index c51fb58d7..568cf8d95 100644 --- a/src/platform_impl/macos/system_tray.rs +++ b/src/platform_impl/macos/system_tray.rs @@ -145,7 +145,11 @@ impl SystemTray { pub fn set_menu(&mut self, tray_menu: &Menu) { unsafe { - self.ns_status_bar.setMenu_(tray_menu.menu); + self.tray_menu = Some(tray_menu.clone()); + + let tray_target: id = msg_send![self.ns_status_bar.button(), target]; + (*tray_target).set_ivar("menu", tray_menu.menu); + let () = msg_send![tray_menu.menu, setDelegate: tray_target]; } }