[macOS] Do not use NSApplication main loop for headless mode.

This commit is contained in:
Pāvels Nadtočajevs 2025-07-17 08:42:55 +03:00
parent 7826b6b13f
commit 8b045ca8fe
No known key found for this signature in database
GPG key ID: 8413210218EF35D2
3 changed files with 69 additions and 0 deletions

View file

@ -1171,6 +1171,59 @@ OS_MacOS_NSApp::OS_MacOS_NSApp(const char *p_execpath, int p_argc, char **p_argv
sigaction(SIGINT, &action, nullptr);
}
// MARK: - OS_MacOS_Headless
void OS_MacOS_Headless::run() {
CFRunLoopGetCurrent();
@autoreleasepool {
Error err = Main::setup(execpath, argc, argv);
if (err != OK) {
if (err == ERR_HELP) {
return set_exit_code(EXIT_SUCCESS);
}
return set_exit_code(EXIT_FAILURE);
}
}
int ret;
@autoreleasepool {
ret = Main::start();
}
if (ret == EXIT_SUCCESS && main_loop) {
@autoreleasepool {
main_loop->initialize();
}
while (true) {
@autoreleasepool {
@try {
if (Input::get_singleton()) {
Input::get_singleton()->flush_buffered_events();
}
if (Main::iteration()) {
break;
}
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, 0);
} @catch (NSException *exception) {
ERR_PRINT("NSException: " + String::utf8([exception reason].UTF8String));
}
}
}
main_loop->finalize();
}
Main::cleanup();
}
OS_MacOS_Headless::OS_MacOS_Headless(const char *p_execpath, int p_argc, char **p_argv) :
OS_MacOS(p_execpath, p_argc, p_argv) {
}
// MARK: - OS_MacOS_Embedded
#ifdef DEBUG_ENABLED