Commit aa5c926
committed
ui_cocoa: runtime-guard setHelpMenu: for pre-10.6 Leopard
On 10.5 Leopard, the app crashes at menu-bar construction:
NSApplication setHelpMenu:]: unrecognized selector sent to
instance 0x6311b50
An uncaught exception was raised
-[NSApplication setHelpMenu:] is annotated NS_AVAILABLE_MAC(10_6)
and was added in Snow Leopard. On 10.5 the selector doesn't exist
in AppKit, so the Obj-C runtime throws NSInvalidArgumentException.
This is a runtime issue, not a compile issue - the code builds
cleanly against the 10.5 SDK because the selector is just a name
the runtime resolves at dispatch time. Can't use @available
(clang-only, Xcode 7+), so use the pre-Obj-C-2.0 idiom:
if ([NSApp respondsToSelector:@selector(setHelpMenu:)])
[NSApp setHelpMenu:menu];
Works on every Obj-C compiler back to 1.0, zero overhead on modern
builds.
The other NSApplication menu-setters in this file
(setMainMenu:, setServicesMenu:, setWindowsMenu:) are all 10.0-era
and need no guard. Only setHelpMenu: is the 10.6 addition.
What Leopard loses: setHelpMenu: tells AppKit which menu to inject
Spotlight-for-Help into. The Help menu itself still appears via
setMainMenu: in cocoa_create_menu_bar(). Spotlight-for-Help was
also a 10.6 addition, so there's nothing to inject on Leopard
anyway. No regression for modern macOS.1 parent d69251d commit aa5c926
1 file changed
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1328 | 1328 | | |
1329 | 1329 | | |
1330 | 1330 | | |
1331 | | - | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
1332 | 1338 | | |
1333 | 1339 | | |
1334 | 1340 | | |
| |||
0 commit comments