[macOS] Do not use openApplicationAtURL for headless instances.

This commit is contained in:
Pāvels Nadtočajevs 2025-11-28 08:53:04 +02:00
parent 3a97723ff2
commit 17fa5219a9
No known key found for this signature in database
GPG key ID: 8413210218EF35D2
3 changed files with 26 additions and 17 deletions

View file

@ -61,21 +61,6 @@ int main(int argc, char **argv) {
bool is_embedded = false; bool is_embedded = false;
bool is_headless = false; bool is_headless = false;
const char *headless_args[] = {
"--headless",
"-h",
"--help",
"/?",
"--version",
"--dump-gdextension-interface",
"--dump-extension-api",
"--dump-extension-api-with-docs",
"--validate-extension-api",
"--convert-3to4",
"--validate-conversion-3to4",
"--doctool",
};
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
if (strcmp("-NSDocumentRevisionsDebugMode", argv[i]) == 0) { if (strcmp("-NSDocumentRevisionsDebugMode", argv[i]) == 0) {
// remove "-NSDocumentRevisionsDebugMode" and the next argument // remove "-NSDocumentRevisionsDebugMode" and the next argument
@ -94,8 +79,8 @@ int main(int argc, char **argv) {
if (strcmp("--embedded", argv[i]) == 0) { if (strcmp("--embedded", argv[i]) == 0) {
is_embedded = true; is_embedded = true;
} }
for (size_t j = 0; j < std::size(headless_args); j++) { for (size_t j = 0; j < std::size(OS_MacOS::headless_args); j++) {
if (strcmp(headless_args[j], argv[i]) == 0) { if (strcmp(OS_MacOS::headless_args[j], argv[i]) == 0) {
is_headless = true; is_headless = true;
break; break;
} }

View file

@ -79,6 +79,23 @@ protected:
virtual void delete_main_loop() override; virtual void delete_main_loop() override;
public: public:
static inline const char *headless_args[] = {
"--headless",
"-h",
"--help",
"/?",
"--version",
"--dump-gdextension-interface",
"--dump-extension-api",
"--dump-gdextension-interface-json",
"--dump-extension-api-with-docs",
"--validate-extension-api",
"--convert-3to4",
"--validate-conversion-3to4",
"--doctool",
"--test",
};
virtual void add_frame_delay(bool p_can_draw, bool p_wake_for_events) override; virtual void add_frame_delay(bool p_can_draw, bool p_wake_for_events) override;
virtual void set_cmdline_platform_args(const List<String> &p_args); virtual void set_cmdline_platform_args(const List<String> &p_args);

View file

@ -852,6 +852,13 @@ Error OS_MacOS::create_process(const String &p_path, const List<String> &p_argum
} }
Error OS_MacOS::create_instance(const List<String> &p_arguments, ProcessID *r_child_id) { Error OS_MacOS::create_instance(const List<String> &p_arguments, ProcessID *r_child_id) {
// Do not run headless instance as app bundle, since it will never send `applicationDidFinishLaunching` and register as failed start after timeout.
for (size_t i = 0; i < std::size(OS_MacOS::headless_args); i++) {
if (p_arguments.find(String(OS_MacOS::headless_args[i]))) {
return OS_Unix::create_process(get_executable_path(), p_arguments, r_child_id, false);
}
}
// If executable is bundled, always execute editor instances as an app bundle to ensure app window is registered and activated correctly. // If executable is bundled, always execute editor instances as an app bundle to ensure app window is registered and activated correctly.
NSString *nsappname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; NSString *nsappname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
if (nsappname != nil) { if (nsappname != nil) {