-
Notifications
You must be signed in to change notification settings - Fork 17.1k
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem Description
I can't seem to create palette menus with Electron, which were made public API in macOS Sonoma (14). They are described here:
- WWDC23: What's new in AppKit
NSMenu.PresentationStyle.palette(also contains a code sample)
These allow for creating menus such as this one, from Messages:
From what I can see, Electron doesn't expose a way to create this kind of menu. You need to be able to specify the NSMenu's presentationStyle. You can seemingly embed a palette menu (NSMenu with a presentationStyle of .palette) within a larger menu by creating an NSMenuItem and setting its submenu to the palette menu.
Proposed Solution
I would like some way to create palette menus while also being able to populate the palette with images (NativeImages?) from JavaScript. This sounds a bit tricky, so I can take the time to design an API surface if wanted. However, I assume that the maintainers would do a better job than me.
My current use case doesn't involve maintaining a selection state for the items in the palette via selectionMode. In other words, I'd like to be able to use palette menus just so that I can present menu items arranged horizontally, with only images to represent the item - just like the menu in Messages. However, support for this may or may not be desired if this feature is to be added to Electron.
Alternatives Considered
You can use MenuItems with icons, but it doesn't provide the same look and feel of a palette menu. There doesn't seem to be any other way to achieve this without dropping down to the renderer and reimplementing menus there.
Additional Information
With the release of macOS Sonoma, menus (in general, across the system) were reimplemented in Cocoa and that new implementation is used within applications according to some runtime heuristics involving link checks.
A default controlling this is NSMenuEnableCarbonCompatibilityMode. The details around this are important because AIUI, Carbon menus involved a modal event-tracking loop that would run for the duration of the menu being on-screen. This would block the main AppKit thread. I believe that Cocoa menus don't use this and the main AppKit thread is able to run unencumbered with Cocoa menus visible. This is just a guess, though.