Keep menu item images visible when building against the macOS 27 SDK
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
While checking our app against macOS 27, I came across this in Apple's release notes: Apps built against the macOS 27 SDK get every image they put on a menu item hidden, symbol images and regular ones alike, unless they also set the new preferredImageVisibility on the NSMenuItem. With the 26 SDK, only symbol images are hidden.
Electron is still on the 26 SDK, so current releases are fine. But once it switches, every icon set on a MenuItem would disappear on macOS 27, and apps couldn't do anything about it. For some apps that's more than a cosmetic problem. The tray menu I'm working on, for example, shows each meeting's start time and color as the item's icon.
Chromium just fixed this for its own menus by setting preferredImageVisibility wherever it assigns a menu item image (crrev.com/c/8463164). Electron's menus don't go through that code though, because ElectronMenuController sets item.image itself.
I haven't been able to try this myself, since there's no Electron build on the 27 SDK yet.
Proposed Solution
Do the same as Chromium and set preferredImageVisibility to visible wherever Electron sets a menu item image. If an app sets an icon, it wants it shown, so I'd just keep the current behavior.
As far as I can tell, that's three places in electron_menu_controller.mm: makeMenuItemForIndex:, applyStateToMenuItem: and menuItemForService:. Chromium's new ui/base/cocoa/macos27_sdk.h already declares the property for builds against the 26 SDK.
Alternatives Considered
- Exposing
preferredImageVisibilityas aMenuItemoption instead: Existing apps would lose their icons on macOS 27 until they opt in. It could still be useful later as an override - Leaving AppKit's default in place: Apps would silently lose icons they set on purpose
Additional Information
- Apple's release notes (AppKit section, 170477566 and 179374305): https://developer.apple.com/documentation/macos-release-notes/macos-27-release-notes
- Chromium's switch to the macOS 27 SDK has already landed and been reverted three times in September, so this might come up soon
Source: electron/electron