From 8099a177c30eb66e31c6f53ea9bfb45d8b7becc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Fri, 7 Feb 2025 16:01:14 -0300 Subject: [PATCH] [osx] Fix finishLaunching() call in CLI mode --- os/osx/app.mm | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/os/osx/app.mm b/os/osx/app.mm index 4ea6ac9fd..1db11c9be 100644 --- a/os/osx/app.mm +++ b/os/osx/app.mm @@ -52,13 +52,24 @@ void setAppMode(AppMode appMode) void finishLaunching() { - // [m_app run] can only be called once. - if (![[NSRunningApplication currentApplication] isFinishedLaunching]) - // Note that the [m_app run] call doesn't block because we are calling - // [NSApp stop] from [AppDelegateOSX applicationDidFinishLaunching]. We only - // need the application's initialization done inside run to prevent issues - // such as: https://github.com/aseprite/aseprite/issues/4795 - [m_app run]; + id runningApp = [NSRunningApplication currentApplication]; + // [m_app run] must be called once, if the app didn't finish launching yet. + if (![runningApp isFinishedLaunching]) { + // The run method must be called in GUI mode only, otherwise the + // [AppDelegateOSX applicationDidFinishLaunching] doesn't get called + // and [m_app run] ends up blocking the app. + if ([runningApp activationPolicy] == NSApplicationActivationPolicyRegular) { + // Note that the [m_app run] call doesn't block because we are calling + // [NSApp stop] from [AppDelegateOSX applicationDidFinishLaunching]. We only + // need the application's initialization done inside run to prevent issues + // such as: https://github.com/aseprite/aseprite/issues/4795 + [m_app run]; + } + else { + // The app is running in CLI mode, then we just call finishLaunching. + [m_app finishLaunching]; + } + } [m_appDelegate resetCliFiles]; }