From c8b2aeb2263c50428e2a465aebc0103e73582ffc Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 20 Jul 2026 15:00:40 +0100 Subject: [PATCH] qt: Avoid implicit `NSApplication` instantiation `[NSApplication sharedApplication]` creates the shared application object if it does not yet exist. When running with the `minimal` or `offscreen` QPA plugins, which is common for testing purposes, the Cocoa platform plugin never creates it, so these call sites were instantiating `NSApplication` as a side effect. Use the `NSApp` global instead and return early when it is `nil`. --- src/qt/macdockiconhandler.mm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm index b7b1b98eef3..1b62032c1e6 100644 --- a/src/qt/macdockiconhandler.mm +++ b/src/qt/macdockiconhandler.mm @@ -20,7 +20,8 @@ bool dockClickHandler(id self, SEL _cmd, ...) { } void setupDockClickHandler() { - Class delClass = (Class)[[[NSApplication sharedApplication] delegate] class]; + if (NSApp == nil) return; + Class delClass = (Class)[[NSApp delegate] class]; SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:"); class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"); } @@ -49,5 +50,6 @@ void MacDockIconHandler::cleanup() */ void ForceActivation() { - [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; + if (NSApp == nil) return; + [NSApp activateIgnoringOtherApps:YES]; }