mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-11 21:20:39 +02:00
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`.
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user