Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(macOS): fix SystemTrayEvent not emitted after calling set_menu #764

Merged
merged 1 commit into from
Jul 10, 2023

Conversation

pewsheen
Copy link
Contributor

@pewsheen pewsheen commented Jul 10, 2023

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

Checklist

Other information

We didn't set the tray menu direct to ns_status_bar. Instead, we set it to tray_target.menu and let the tray_target attach it when we click the tray icon.

// attach menu only if provided
if let Some(menu) = self.system_tray.tray_menu.clone() {
// We set the tray menu to tray_target instead of status bar
// Because setting directly to status bar will overwrite the event callback of the button
// See `make_tray_class` for more information.
(*tray_target).set_ivar("menu", menu.menu);
let () = msg_send![menu.menu, setDelegate: tray_target];
}

However, when calling the set_menu, it sets the new menu to ns_status_bar, not tray_target. Therefore the customized click handler is not triggered

pub fn set_menu(&mut self, tray_menu: &Menu) {
unsafe {
self.ns_status_bar.setMenu_(tray_menu.menu);
}
}

@pewsheen pewsheen requested a review from a team as a code owner July 10, 2023 10:25
@amrbashir amrbashir merged commit bb3c53d into tauri-apps:dev Jul 10, 2023
9 checks passed
@github-actions github-actions bot mentioned this pull request Jul 10, 2023
@amrbashir
Copy link
Member

cherry picked in to v0.16 branch in 019d9e9e

@pewsheen pewsheen deleted the mac-set-menu branch July 11, 2023 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Buggy behaviors of SystemTrayEvent on macOS (fail to set tray menu & fail to get callback)
2 participants