From bb3c53d1d84ebc26b0d66230877ecc7b6a71db27 Mon Sep 17 00:00:00 2001 From: Jason Tsai Date: Mon, 10 Jul 2023 19:28:54 +0800 Subject: [PATCH] fix(macOS): fix `SystemTrayEvent` not emitted after calling `set_menu` (#764) --- .changes/macos-fix-set-tray-menu.md | 5 +++++ src/platform_impl/macos/system_tray.rs | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changes/macos-fix-set-tray-menu.md 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]; } }