feat: enable secondary label for macOS menu (#46887)

* feat: enable secondary label for macOS menu

* Update shell/browser/ui/cocoa/electron_menu_controller.mm

Co-authored-by: Robo <hop2deep@gmail.com>

* fix for lint

* update docs for sublabel

---------

Co-authored-by: Robo <hop2deep@gmail.com>
This commit is contained in:
Michaela Laurencin
2025-05-09 12:05:26 -04:00
committed by GitHub
parent b9f0aebb2f
commit 10e4f9ad37
3 changed files with 31 additions and 1 deletions

View File

@@ -315,12 +315,21 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
- (NSMenuItem*)makeMenuItemForIndex:(NSInteger)index
fromModel:(electron::ElectronMenuModel*)model {
std::u16string label16 = model->GetLabelAt(index);
auto rawSecondaryLabel = model->GetSecondaryLabelAt(index);
NSString* label = l10n_util::FixUpWindowsStyleLabel(label16);
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:label
action:@selector(itemSelected:)
keyEquivalent:@""];
if (!rawSecondaryLabel.empty()) {
if (@available(macOS 14.4, *)) {
NSString* secondary_label =
l10n_util::FixUpWindowsStyleLabel(rawSecondaryLabel);
item.subtitle = secondary_label;
}
}
// If the menu item has an icon, set it.
ui::ImageModel icon = model->GetIconAt(index);
if (icon.IsImage())