From 919bef434e2f2c49a48a213bca1379574c20ce55 Mon Sep 17 00:00:00 2001 From: scheffle Date: Fri, 6 Oct 2023 14:42:53 +0200 Subject: [PATCH] fix standalone menubar on macOS 14 --- .../source/platform/mac/macapplication.mm | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/vstgui/standalone/source/platform/mac/macapplication.mm b/vstgui/standalone/source/platform/mac/macapplication.mm index acbc2ec3a..f8dabcbbf 100644 --- a/vstgui/standalone/source/platform/mac/macapplication.mm +++ b/vstgui/standalone/source/platform/mac/macapplication.mm @@ -308,13 +308,15 @@ - (void)setupMainMenu { NSMenu* mainMenu = [NSApp mainMenu]; NSMenuItem* appMenuItem = nil; - if (mainMenu == nil) + if (mainMenu == nil || mainMenu.itemArray.count == 1) { - mainMenu = [NSMenu new]; - [NSApp setMainMenu:mainMenu]; - - appMenuItem = [[NSMenuItem alloc] initWithTitle:@"App" action:nil keyEquivalent:@""]; - [mainMenu addItem:appMenuItem]; + if (mainMenu == nil) + { + mainMenu = [NSMenu new]; + [NSApp setMainMenu:mainMenu]; + appMenuItem = [[NSMenuItem alloc] initWithTitle:@"App" action:nil keyEquivalent:@""]; + [mainMenu addItem:appMenuItem]; + } NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString (@"Window", "Menu Name") @@ -423,14 +425,17 @@ - (void)setupMainMenu } // move Windows menu to the end - NSMenuItem* windowsMenuItem = - [mainMenu itemWithTitle:NSLocalizedString (@"Window", "Menu Name")]; - [mainMenu removeItem:windowsMenuItem]; - [mainMenu addItem:windowsMenuItem]; + if (auto* windowsMenuItem = [mainMenu itemWithTitle:NSLocalizedString (@"Window", "Menu Name")]) + { + [mainMenu removeItem:windowsMenuItem]; + [mainMenu addItem:windowsMenuItem]; + } // move Help menu to the end - NSMenuItem* helpMenuItem = [mainMenu itemWithTitle:NSLocalizedString (@"Help", "Menu Name")]; - [mainMenu removeItem:helpMenuItem]; - [mainMenu addItem:helpMenuItem]; + if (auto* helpMenuItem = [mainMenu itemWithTitle:NSLocalizedString (@"Help", "Menu Name")]) + { + [mainMenu removeItem:helpMenuItem]; + [mainMenu addItem:helpMenuItem]; + } } //------------------------------------------------------------------------