Skip to content

Commit

Permalink
fix(menus): fix macOS Services menu not working, closes #243 (#569)
Browse files Browse the repository at this point in the history
* fix(menus): macOS Services menu not working

* chore(menus): add changefile
  • Loading branch information
caesar committed Sep 25, 2022
1 parent dbbfd97 commit d343abf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/macos-menus-services.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": "patch"
---

Fix the native Services menu on macOS.
2 changes: 2 additions & 0 deletions examples/custom_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ fn main() {
},
));

first_menu.add_native_item(MenuItem::Services);

// Create custom Copy menu with our clipboard object
let custom_insert_clipboard = first_menu.add_item(MenuItemAttributes::new("Insert clipboard"));
let custom_read_clipboard = first_menu.add_item(MenuItemAttributes::new("Read clipboard"));
Expand Down
6 changes: 4 additions & 2 deletions src/platform_impl/macos/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,12 @@ impl Menu {
)),
MenuItem::Services => unsafe {
let item = make_menu_item("Services", None, None, MenuType::MenuBar);
// we have to assign an empty menu as the app's services menu, and macOS will populate it
let services_menu = NSMenu::alloc(nil).autorelease();
let app_class = class!(NSApplication);
let app: id = msg_send![app_class, sharedApplication];
let services: id = msg_send![app, servicesMenu];
let _: () = msg_send![&*item, setSubmenu: services];
let () = msg_send![app, setServicesMenu: services_menu];
let () = msg_send![&*item, setSubmenu: services_menu];
Some((None, item))
},
};
Expand Down

0 comments on commit d343abf

Please sign in to comment.