2014-02-10 02:10:30 +01:00
|
|
|
/**************************************************************************/
|
2022-07-20 08:28:22 +02:00
|
|
|
/* os_macos.mm */
|
2014-02-10 02:10:30 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
#include "os_macos.h"
|
2017-04-09 14:18:49 +02:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
#include "dir_access_macos.h"
|
|
|
|
#include "display_server_macos.h"
|
2022-01-26 10:01:27 +01:00
|
|
|
#include "godot_application.h"
|
|
|
|
#include "godot_application_delegate.h"
|
2022-07-20 08:28:22 +02:00
|
|
|
#include "macos_terminal_logger.h"
|
2019-06-22 18:34:26 +02:00
|
|
|
|
2023-06-08 14:51:32 +02:00
|
|
|
#include "core/crypto/crypto_core.h"
|
|
|
|
#include "core/version_generated.gen.h"
|
|
|
|
#include "main/main.h"
|
|
|
|
|
2018-01-04 20:36:44 +01:00
|
|
|
#include <dlfcn.h>
|
2017-04-09 14:18:49 +02:00
|
|
|
#include <libproc.h>
|
2020-03-07 17:02:54 +01:00
|
|
|
#include <mach-o/dyld.h>
|
2020-12-27 01:50:21 +01:00
|
|
|
#include <os/log.h>
|
|
|
|
#include <sys/sysctl.h>
|
2021-07-22 18:23:48 +02:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::pre_wait_observer_cb(CFRunLoopObserverRef p_observer, CFRunLoopActivity p_activiy, void *p_context) {
|
2022-06-10 13:02:51 +02:00
|
|
|
// Prevent main loop from sleeping and redraw window during modal popup display.
|
|
|
|
// Do not redraw when rendering is done from the separate thread, it will conflict with the OpenGL context updates.
|
2015-04-02 06:32:02 +02:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
2022-06-10 13:02:51 +02:00
|
|
|
if (get_singleton()->get_main_loop() && ds && (get_singleton()->get_render_thread_mode() != RENDER_SEPARATE_THREAD) && !ds->get_is_resizing()) {
|
2022-01-26 10:01:27 +01:00
|
|
|
Main::force_redraw();
|
|
|
|
if (!Main::is_iterating()) { // Avoid cyclic loop.
|
|
|
|
Main::iteration();
|
2020-03-07 17:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-01-26 10:01:27 +01:00
|
|
|
CFRunLoopWakeUp(CFRunLoopGetCurrent()); // Prevent main loop from sleeping.
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::initialize() {
|
2022-01-26 10:01:27 +01:00
|
|
|
crash_handler.initialize();
|
2021-07-22 18:23:48 +02:00
|
|
|
|
2022-01-26 10:01:27 +01:00
|
|
|
initialize_core();
|
2021-07-22 18:23:48 +02:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_processor_name() const {
|
2020-12-27 01:50:21 +01:00
|
|
|
char buffer[256];
|
|
|
|
size_t buffer_len = 256;
|
|
|
|
if (sysctlbyname("machdep.cpu.brand_string", &buffer, &buffer_len, NULL, 0) == 0) {
|
|
|
|
return String::utf8(buffer, buffer_len);
|
|
|
|
}
|
|
|
|
ERR_FAIL_V_MSG("", String("Couldn't get the CPU model name. Returning an empty string."));
|
|
|
|
}
|
|
|
|
|
2021-03-30 14:42:50 +02:00
|
|
|
bool OS_MacOS::is_sandboxed() const {
|
|
|
|
return has_environment("APP_SANDBOX_CONTAINER_ID");
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<String> OS_MacOS::get_granted_permissions() const {
|
|
|
|
Vector<String> ret;
|
|
|
|
|
|
|
|
if (is_sandboxed()) {
|
|
|
|
NSArray *bookmarks = [[NSUserDefaults standardUserDefaults] arrayForKey:@"sec_bookmarks"];
|
|
|
|
for (id bookmark in bookmarks) {
|
|
|
|
NSError *error = nil;
|
|
|
|
BOOL isStale = NO;
|
|
|
|
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];
|
|
|
|
if (!error && !isStale) {
|
|
|
|
String url_string;
|
|
|
|
url_string.parse_utf8([[url path] UTF8String]);
|
|
|
|
ret.push_back(url_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OS_MacOS::revoke_granted_permissions() {
|
|
|
|
if (is_sandboxed()) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"sec_bookmarks"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::initialize_core() {
|
2020-03-07 17:02:54 +01:00
|
|
|
OS_Unix::initialize_core();
|
2018-01-30 20:39:53 +01:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
DirAccess::make_default<DirAccessMacOS>(DirAccess::ACCESS_RESOURCES);
|
|
|
|
DirAccess::make_default<DirAccessMacOS>(DirAccess::ACCESS_USERDATA);
|
|
|
|
DirAccess::make_default<DirAccessMacOS>(DirAccess::ACCESS_FILESYSTEM);
|
2018-01-30 20:39:53 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::finalize() {
|
2021-03-30 14:42:50 +02:00
|
|
|
if (is_sandboxed()) {
|
|
|
|
NSArray *bookmarks = [[NSUserDefaults standardUserDefaults] arrayForKey:@"sec_bookmarks"];
|
|
|
|
for (id bookmark in bookmarks) {
|
|
|
|
NSError *error = nil;
|
|
|
|
BOOL isStale = NO;
|
|
|
|
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];
|
|
|
|
if (!error && !isStale) {
|
|
|
|
[url stopAccessingSecurityScopedResource];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
#ifdef COREMIDI_ENABLED
|
|
|
|
midi_driver.close();
|
|
|
|
#endif
|
2016-07-21 17:30:20 +02:00
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
delete_main_loop();
|
2017-12-10 19:38:26 +01:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
if (joypad_macos) {
|
|
|
|
memdelete(joypad_macos);
|
2020-08-02 20:30:56 +02:00
|
|
|
}
|
2017-12-10 19:38:26 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::initialize_joypads() {
|
|
|
|
joypad_macos = memnew(JoypadMacOS(Input::get_singleton()));
|
2022-01-26 10:01:27 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::set_main_loop(MainLoop *p_main_loop) {
|
2020-03-07 17:02:54 +01:00
|
|
|
main_loop = p_main_loop;
|
2017-12-10 19:38:26 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::delete_main_loop() {
|
2022-01-26 10:01:27 +01:00
|
|
|
if (!main_loop) {
|
2020-03-07 17:02:54 +01:00
|
|
|
return;
|
2022-01-26 10:01:27 +01:00
|
|
|
}
|
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
memdelete(main_loop);
|
2021-04-29 11:47:24 +02:00
|
|
|
main_loop = nullptr;
|
2020-03-07 17:02:54 +01:00
|
|
|
}
|
2017-12-10 19:38:26 +01:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::set_cmdline_platform_args(const List<String> &p_args) {
|
2022-07-07 09:57:22 +02:00
|
|
|
launch_service_args = p_args;
|
2022-01-26 10:01:27 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
List<String> OS_MacOS::get_cmdline_platform_args() const {
|
2022-07-07 09:57:22 +02:00
|
|
|
return launch_service_args;
|
2022-01-26 10:01:27 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_name() const {
|
2020-03-07 17:02:54 +01:00
|
|
|
return "macOS";
|
|
|
|
}
|
2017-06-27 18:13:03 +02:00
|
|
|
|
2022-09-16 11:14:14 +02:00
|
|
|
String OS_MacOS::get_distribution_name() const {
|
|
|
|
return get_name();
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_MacOS::get_version() const {
|
|
|
|
NSOperatingSystemVersion ver = [NSProcessInfo processInfo].operatingSystemVersion;
|
|
|
|
return vformat("%d.%d.%d", (int64_t)ver.majorVersion, (int64_t)ver.minorVersion, (int64_t)ver.patchVersion);
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::alert(const String &p_alert, const String &p_title) {
|
2022-01-26 10:01:27 +01:00
|
|
|
NSAlert *window = [[NSAlert alloc] init];
|
|
|
|
NSString *ns_title = [NSString stringWithUTF8String:p_title.utf8().get_data()];
|
|
|
|
NSString *ns_alert = [NSString stringWithUTF8String:p_alert.utf8().get_data()];
|
|
|
|
|
2022-10-18 11:11:39 +02:00
|
|
|
NSTextField *text_field = [NSTextField labelWithString:ns_alert];
|
|
|
|
[text_field setAlignment:NSTextAlignmentCenter];
|
2022-01-26 10:01:27 +01:00
|
|
|
[window addButtonWithTitle:@"OK"];
|
|
|
|
[window setMessageText:ns_title];
|
2022-10-18 11:11:39 +02:00
|
|
|
[window setAccessoryView:text_field];
|
2022-01-26 10:01:27 +01:00
|
|
|
[window setAlertStyle:NSAlertStyleWarning];
|
|
|
|
|
|
|
|
id key_window = [[NSApplication sharedApplication] keyWindow];
|
|
|
|
[window runModal];
|
|
|
|
if (key_window) {
|
|
|
|
[key_window makeKeyAndOrderFront:nil];
|
2021-08-27 23:19:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 22:36:15 +01:00
|
|
|
_FORCE_INLINE_ String OS_MacOS::get_framework_executable(const String &p_path) {
|
|
|
|
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
|
|
|
|
// Read framework bundle to get executable name.
|
|
|
|
NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())];
|
|
|
|
NSBundle *bundle = [NSBundle bundleWithURL:url];
|
|
|
|
if (bundle) {
|
|
|
|
String exe_path = String::utf8([[bundle executablePath] UTF8String]);
|
|
|
|
if (da->file_exists(exe_path)) {
|
|
|
|
return exe_path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try default executable name (invalid framework).
|
|
|
|
if (da->dir_exists(p_path) && da->file_exists(p_path.path_join(p_path.get_file().get_basename()))) {
|
|
|
|
return p_path.path_join(p_path.get_file().get_basename());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not a framework, try loading as .dylib.
|
|
|
|
return p_path;
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
Error OS_MacOS::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path) {
|
2022-01-26 10:01:27 +01:00
|
|
|
String path = get_framework_executable(p_path);
|
2017-06-27 18:13:03 +02:00
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
if (!FileAccess::exists(path)) {
|
2022-01-26 10:01:27 +01:00
|
|
|
// Load .dylib or framework from within the executable path.
|
2022-08-30 02:34:01 +02:00
|
|
|
path = get_framework_executable(get_executable_path().get_base_dir().path_join(p_path.get_file()));
|
2017-06-27 18:13:03 +02:00
|
|
|
}
|
2017-07-03 03:44:42 +02:00
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
if (!FileAccess::exists(path)) {
|
2022-01-26 10:01:27 +01:00
|
|
|
// Load .dylib or framework from a standard macOS location.
|
2022-08-30 02:34:01 +02:00
|
|
|
path = get_framework_executable(get_executable_path().get_base_dir().path_join("../Frameworks").path_join(p_path.get_file()));
|
2020-03-07 17:02:54 +01:00
|
|
|
}
|
2017-07-03 03:44:42 +02:00
|
|
|
|
2024-01-01 12:48:28 +01:00
|
|
|
ERR_FAIL_COND_V(!FileAccess::exists(path), ERR_FILE_NOT_FOUND);
|
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW);
|
2023-09-09 17:46:44 +02:00
|
|
|
ERR_FAIL_NULL_V_MSG(p_library_handle, ERR_CANT_OPEN, vformat("Can't open dynamic library: %s. Error: %s.", p_path, dlerror()));
|
2022-04-29 00:51:04 +02:00
|
|
|
|
|
|
|
if (r_resolved_path != nullptr) {
|
|
|
|
*r_resolved_path = path;
|
|
|
|
}
|
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
return OK;
|
2017-06-27 18:13:03 +02:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
MainLoop *OS_MacOS::get_main_loop() const {
|
2020-03-07 17:02:54 +01:00
|
|
|
return main_loop;
|
2017-06-27 18:13:03 +02:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_config_path() const {
|
2021-05-21 12:48:12 +02:00
|
|
|
if (has_environment("HOME")) {
|
2022-08-30 02:34:01 +02:00
|
|
|
return get_environment("HOME").path_join("Library/Application Support");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2021-05-21 12:48:12 +02:00
|
|
|
return ".";
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_data_path() const {
|
2021-05-21 12:48:12 +02:00
|
|
|
return get_config_path();
|
2015-01-08 08:26:27 +01:00
|
|
|
}
|
2017-04-09 13:22:40 +02:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_cache_path() const {
|
2021-05-21 12:48:12 +02:00
|
|
|
if (has_environment("HOME")) {
|
2022-08-30 02:34:01 +02:00
|
|
|
return get_environment("HOME").path_join("Library/Caches");
|
2015-01-08 08:26:27 +01:00
|
|
|
}
|
2021-05-21 12:48:12 +02:00
|
|
|
return get_config_path();
|
2015-01-08 08:26:27 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_bundle_resource_dir() const {
|
2021-05-13 08:25:09 +02:00
|
|
|
String ret;
|
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
NSBundle *main = [NSBundle mainBundle];
|
2021-05-13 08:25:09 +02:00
|
|
|
if (main) {
|
2022-01-26 10:01:27 +01:00
|
|
|
NSString *resource_path = [main resourcePath];
|
|
|
|
ret.parse_utf8([resource_path UTF8String]);
|
2021-05-13 08:25:09 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_bundle_icon_path() const {
|
2020-03-07 17:02:54 +01:00
|
|
|
String ret;
|
2019-03-03 23:52:18 +01:00
|
|
|
|
2021-05-13 08:25:09 +02:00
|
|
|
NSBundle *main = [NSBundle mainBundle];
|
|
|
|
if (main) {
|
2022-01-26 10:01:27 +01:00
|
|
|
NSString *icon_path = [[main infoDictionary] objectForKey:@"CFBundleIconFile"];
|
|
|
|
if (icon_path) {
|
|
|
|
ret.parse_utf8([icon_path UTF8String]);
|
2021-05-13 08:25:09 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-07 17:02:54 +01:00
|
|
|
return ret;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
// Get properly capitalized engine name for system paths
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_godot_dir_name() const {
|
2020-03-07 17:02:54 +01:00
|
|
|
return String(VERSION_SHORT_NAME).capitalize();
|
|
|
|
}
|
2018-01-10 12:22:28 +01:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
|
2020-03-07 17:02:54 +01:00
|
|
|
NSSearchPathDirectory id;
|
|
|
|
bool found = true;
|
2018-01-10 12:22:28 +01:00
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
switch (p_dir) {
|
|
|
|
case SYSTEM_DIR_DESKTOP: {
|
|
|
|
id = NSDesktopDirectory;
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DOCUMENTS: {
|
|
|
|
id = NSDocumentDirectory;
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_DOWNLOADS: {
|
|
|
|
id = NSDownloadsDirectory;
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_MOVIES: {
|
|
|
|
id = NSMoviesDirectory;
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_MUSIC: {
|
|
|
|
id = NSMusicDirectory;
|
|
|
|
} break;
|
|
|
|
case SYSTEM_DIR_PICTURES: {
|
|
|
|
id = NSPicturesDirectory;
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
found = false;
|
|
|
|
}
|
|
|
|
}
|
2018-01-10 12:22:28 +01:00
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
String ret;
|
|
|
|
if (found) {
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(id, NSUserDomainMask, YES);
|
|
|
|
if (paths && [paths count] >= 1) {
|
2022-01-26 10:01:27 +01:00
|
|
|
ret.parse_utf8([[paths firstObject] UTF8String]);
|
2018-01-10 12:22:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
return ret;
|
2018-01-10 12:22:28 +01:00
|
|
|
}
|
|
|
|
|
2023-04-25 10:15:38 +02:00
|
|
|
Error OS_MacOS::shell_show_in_file_manager(String p_path, bool p_open_folder) {
|
|
|
|
bool open_folder = false;
|
|
|
|
if (DirAccess::dir_exists_absolute(p_path) && p_open_folder) {
|
|
|
|
open_folder = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p_path.begins_with("file://")) {
|
|
|
|
p_path = String("file://") + p_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *string = [NSString stringWithUTF8String:p_path.utf8().get_data()];
|
|
|
|
NSURL *uri = [[NSURL alloc] initWithString:[string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];
|
|
|
|
|
|
|
|
if (open_folder) {
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL:uri];
|
|
|
|
} else {
|
|
|
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[ uri ]];
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
Error OS_MacOS::shell_open(String p_uri) {
|
2020-07-04 06:00:48 +02:00
|
|
|
NSString *string = [NSString stringWithUTF8String:p_uri.utf8().get_data()];
|
|
|
|
NSURL *uri = [[NSURL alloc] initWithString:string];
|
|
|
|
// Escape special characters in filenames
|
|
|
|
if (!uri || !uri.scheme || [uri.scheme isEqual:@"file"]) {
|
|
|
|
uri = [[NSURL alloc] initWithString:[string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];
|
|
|
|
}
|
|
|
|
[[NSWorkspace sharedWorkspace] openURL:uri];
|
2020-03-07 17:02:54 +01:00
|
|
|
return OK;
|
|
|
|
}
|
2017-05-22 11:17:14 +02:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_locale() const {
|
2020-03-07 17:02:54 +01:00
|
|
|
NSString *locale_code = [[NSLocale preferredLanguages] objectAtIndex:0];
|
2020-07-25 22:42:11 +02:00
|
|
|
return String([locale_code UTF8String]).replace("-", "_");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-07-08 14:38:30 +02:00
|
|
|
Vector<String> OS_MacOS::get_system_fonts() const {
|
|
|
|
HashSet<String> font_names;
|
|
|
|
CFArrayRef fonts = CTFontManagerCopyAvailableFontFamilyNames();
|
|
|
|
if (fonts) {
|
|
|
|
for (CFIndex i = 0; i < CFArrayGetCount(fonts); i++) {
|
|
|
|
CFStringRef cf_name = (CFStringRef)CFArrayGetValueAtIndex(fonts, i);
|
|
|
|
if (cf_name && (CFStringGetLength(cf_name) > 0) && (CFStringCompare(cf_name, CFSTR("LastResort"), kCFCompareCaseInsensitive) != kCFCompareEqualTo) && (CFStringGetCharacterAtIndex(cf_name, 0) != '.')) {
|
|
|
|
NSString *ns_name = (__bridge NSString *)cf_name;
|
|
|
|
font_names.insert(String::utf8([ns_name UTF8String]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CFRelease(fonts);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<String> ret;
|
|
|
|
for (const String &E : font_names) {
|
|
|
|
ret.push_back(E);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:04:01 +01:00
|
|
|
String OS_MacOS::_get_default_fontname(const String &p_font_name) const {
|
2022-07-08 14:38:30 +02:00
|
|
|
String font_name = p_font_name;
|
|
|
|
if (font_name.to_lower() == "sans-serif") {
|
|
|
|
font_name = "Helvetica";
|
|
|
|
} else if (font_name.to_lower() == "serif") {
|
|
|
|
font_name = "Times";
|
|
|
|
} else if (font_name.to_lower() == "monospace") {
|
|
|
|
font_name = "Courier";
|
|
|
|
} else if (font_name.to_lower() == "fantasy") {
|
|
|
|
font_name = "Papyrus";
|
|
|
|
} else if (font_name.to_lower() == "cursive") {
|
|
|
|
font_name = "Apple Chancery";
|
|
|
|
};
|
2022-11-21 14:04:01 +01:00
|
|
|
return font_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGFloat OS_MacOS::_weight_to_ct(int p_weight) const {
|
|
|
|
if (p_weight < 150) {
|
|
|
|
return -0.80;
|
|
|
|
} else if (p_weight < 250) {
|
|
|
|
return -0.60;
|
|
|
|
} else if (p_weight < 350) {
|
|
|
|
return -0.40;
|
|
|
|
} else if (p_weight < 450) {
|
|
|
|
return 0.0;
|
|
|
|
} else if (p_weight < 550) {
|
|
|
|
return 0.23;
|
|
|
|
} else if (p_weight < 650) {
|
|
|
|
return 0.30;
|
|
|
|
} else if (p_weight < 750) {
|
|
|
|
return 0.40;
|
|
|
|
} else if (p_weight < 850) {
|
|
|
|
return 0.56;
|
|
|
|
} else if (p_weight < 925) {
|
|
|
|
return 0.62;
|
|
|
|
} else {
|
|
|
|
return 1.00;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CGFloat OS_MacOS::_stretch_to_ct(int p_stretch) const {
|
|
|
|
if (p_stretch < 56) {
|
|
|
|
return -0.5;
|
|
|
|
} else if (p_stretch < 69) {
|
|
|
|
return -0.37;
|
|
|
|
} else if (p_stretch < 81) {
|
|
|
|
return -0.25;
|
|
|
|
} else if (p_stretch < 93) {
|
|
|
|
return -0.13;
|
|
|
|
} else if (p_stretch < 106) {
|
|
|
|
return 0.0;
|
|
|
|
} else if (p_stretch < 137) {
|
|
|
|
return 0.13;
|
|
|
|
} else if (p_stretch < 144) {
|
|
|
|
return 0.25;
|
|
|
|
} else if (p_stretch < 162) {
|
|
|
|
return 0.37;
|
|
|
|
} else {
|
|
|
|
return 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<String> OS_MacOS::get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale, const String &p_script, int p_weight, int p_stretch, bool p_italic) const {
|
|
|
|
Vector<String> ret;
|
|
|
|
String font_name = _get_default_fontname(p_font_name);
|
|
|
|
|
|
|
|
CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, font_name.utf8().get_data(), kCFStringEncodingUTF8);
|
|
|
|
CTFontSymbolicTraits traits = 0;
|
|
|
|
if (p_weight >= 700) {
|
|
|
|
traits |= kCTFontBoldTrait;
|
|
|
|
}
|
|
|
|
if (p_italic) {
|
|
|
|
traits |= kCTFontItalicTrait;
|
|
|
|
}
|
|
|
|
if (p_stretch < 100) {
|
|
|
|
traits |= kCTFontCondensedTrait;
|
|
|
|
} else if (p_stretch > 100) {
|
|
|
|
traits |= kCTFontExpandedTrait;
|
|
|
|
}
|
|
|
|
|
|
|
|
CFNumberRef sym_traits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &traits);
|
|
|
|
CFMutableDictionaryRef traits_dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
|
|
|
|
CFDictionaryAddValue(traits_dict, kCTFontSymbolicTrait, sym_traits);
|
|
|
|
|
|
|
|
CGFloat weight = _weight_to_ct(p_weight);
|
|
|
|
CFNumberRef font_weight = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &weight);
|
|
|
|
CFDictionaryAddValue(traits_dict, kCTFontWeightTrait, font_weight);
|
|
|
|
|
|
|
|
CGFloat stretch = _stretch_to_ct(p_stretch);
|
|
|
|
CFNumberRef font_stretch = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &stretch);
|
|
|
|
CFDictionaryAddValue(traits_dict, kCTFontWidthTrait, font_stretch);
|
|
|
|
|
|
|
|
CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
|
|
|
|
CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, name);
|
|
|
|
CFDictionaryAddValue(attributes, kCTFontTraitsAttribute, traits_dict);
|
|
|
|
|
|
|
|
CTFontDescriptorRef font = CTFontDescriptorCreateWithAttributes(attributes);
|
|
|
|
if (font) {
|
|
|
|
CTFontRef family = CTFontCreateWithFontDescriptor(font, 0, nullptr);
|
|
|
|
CFStringRef string = CFStringCreateWithCString(kCFAllocatorDefault, p_text.utf8().get_data(), kCFStringEncodingUTF8);
|
|
|
|
CFRange range = CFRangeMake(0, CFStringGetLength(string));
|
|
|
|
CTFontRef fallback_family = CTFontCreateForString(family, string, range);
|
|
|
|
if (fallback_family) {
|
|
|
|
CTFontDescriptorRef fallback_font = CTFontCopyFontDescriptor(fallback_family);
|
|
|
|
if (fallback_font) {
|
|
|
|
CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(fallback_font, kCTFontURLAttribute);
|
|
|
|
if (url) {
|
|
|
|
NSString *font_path = [NSString stringWithString:[(__bridge NSURL *)url path]];
|
|
|
|
ret.push_back(String::utf8([font_path UTF8String]));
|
|
|
|
CFRelease(url);
|
|
|
|
}
|
|
|
|
CFRelease(fallback_font);
|
|
|
|
}
|
|
|
|
CFRelease(fallback_family);
|
|
|
|
}
|
|
|
|
CFRelease(string);
|
|
|
|
CFRelease(font);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(attributes);
|
|
|
|
CFRelease(traits_dict);
|
|
|
|
CFRelease(sym_traits);
|
|
|
|
CFRelease(font_stretch);
|
|
|
|
CFRelease(font_weight);
|
|
|
|
CFRelease(name);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
String OS_MacOS::get_system_font_path(const String &p_font_name, int p_weight, int p_stretch, bool p_italic) const {
|
|
|
|
String ret;
|
|
|
|
String font_name = _get_default_fontname(p_font_name);
|
2022-07-08 14:38:30 +02:00
|
|
|
|
|
|
|
CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, font_name.utf8().get_data(), kCFStringEncodingUTF8);
|
|
|
|
|
|
|
|
CTFontSymbolicTraits traits = 0;
|
2022-11-21 14:04:01 +01:00
|
|
|
if (p_weight > 700) {
|
2022-07-08 14:38:30 +02:00
|
|
|
traits |= kCTFontBoldTrait;
|
|
|
|
}
|
|
|
|
if (p_italic) {
|
|
|
|
traits |= kCTFontItalicTrait;
|
|
|
|
}
|
2022-11-21 14:04:01 +01:00
|
|
|
if (p_stretch < 100) {
|
|
|
|
traits |= kCTFontCondensedTrait;
|
|
|
|
} else if (p_stretch > 100) {
|
|
|
|
traits |= kCTFontExpandedTrait;
|
|
|
|
}
|
2022-07-08 14:38:30 +02:00
|
|
|
|
|
|
|
CFNumberRef sym_traits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &traits);
|
|
|
|
CFMutableDictionaryRef traits_dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
|
|
|
|
CFDictionaryAddValue(traits_dict, kCTFontSymbolicTrait, sym_traits);
|
|
|
|
|
2022-11-21 14:04:01 +01:00
|
|
|
CGFloat weight = _weight_to_ct(p_weight);
|
|
|
|
CFNumberRef font_weight = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &weight);
|
|
|
|
CFDictionaryAddValue(traits_dict, kCTFontWeightTrait, font_weight);
|
|
|
|
|
|
|
|
CGFloat stretch = _stretch_to_ct(p_stretch);
|
|
|
|
CFNumberRef font_stretch = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &stretch);
|
|
|
|
CFDictionaryAddValue(traits_dict, kCTFontWidthTrait, font_stretch);
|
|
|
|
|
2022-07-08 14:38:30 +02:00
|
|
|
CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
|
|
|
|
CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, name);
|
|
|
|
CFDictionaryAddValue(attributes, kCTFontTraitsAttribute, traits_dict);
|
|
|
|
|
|
|
|
CTFontDescriptorRef font = CTFontDescriptorCreateWithAttributes(attributes);
|
|
|
|
if (font) {
|
|
|
|
CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(font, kCTFontURLAttribute);
|
|
|
|
if (url) {
|
|
|
|
NSString *font_path = [NSString stringWithString:[(__bridge NSURL *)url path]];
|
|
|
|
ret = String::utf8([font_path UTF8String]);
|
|
|
|
CFRelease(url);
|
|
|
|
}
|
|
|
|
CFRelease(font);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(attributes);
|
|
|
|
CFRelease(traits_dict);
|
|
|
|
CFRelease(sym_traits);
|
2022-11-21 14:04:01 +01:00
|
|
|
CFRelease(font_stretch);
|
|
|
|
CFRelease(font_weight);
|
2022-07-08 14:38:30 +02:00
|
|
|
CFRelease(name);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_executable_path() const {
|
2020-03-07 17:02:54 +01:00
|
|
|
char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
|
2022-01-26 10:01:27 +01:00
|
|
|
int pid = getpid();
|
|
|
|
pid_t ret = proc_pidpath(pid, pathbuf, sizeof(pathbuf));
|
2020-03-07 17:02:54 +01:00
|
|
|
if (ret <= 0) {
|
|
|
|
return OS::get_executable_path();
|
|
|
|
} else {
|
|
|
|
String path;
|
|
|
|
path.parse_utf8(pathbuf);
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2020-03-07 17:02:54 +01:00
|
|
|
return path;
|
|
|
|
}
|
2017-12-14 12:59:46 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
Error OS_MacOS::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id, bool p_open_console) {
|
2022-04-01 20:52:15 +02:00
|
|
|
// Use NSWorkspace if path is an .app bundle.
|
|
|
|
NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())];
|
|
|
|
NSBundle *bundle = [NSBundle bundleWithURL:url];
|
|
|
|
if (bundle) {
|
|
|
|
NSMutableArray *arguments = [[NSMutableArray alloc] init];
|
|
|
|
for (const String &arg : p_arguments) {
|
|
|
|
[arguments addObject:[NSString stringWithUTF8String:arg.utf8().get_data()]];
|
|
|
|
}
|
|
|
|
if (@available(macOS 10.15, *)) {
|
2021-11-01 10:12:52 +01:00
|
|
|
NSWorkspaceOpenConfiguration *configuration = [[NSWorkspaceOpenConfiguration alloc] init];
|
|
|
|
[configuration setArguments:arguments];
|
|
|
|
[configuration setCreatesNewApplicationInstance:YES];
|
|
|
|
__block dispatch_semaphore_t lock = dispatch_semaphore_create(0);
|
|
|
|
__block Error err = ERR_TIMEOUT;
|
|
|
|
__block pid_t pid = 0;
|
2022-04-01 20:52:15 +02:00
|
|
|
|
2021-11-01 10:12:52 +01:00
|
|
|
[[NSWorkspace sharedWorkspace] openApplicationAtURL:url
|
|
|
|
configuration:configuration
|
|
|
|
completionHandler:^(NSRunningApplication *app, NSError *error) {
|
|
|
|
if (error) {
|
|
|
|
err = ERR_CANT_FORK;
|
|
|
|
NSLog(@"Failed to execute: %@", error.localizedDescription);
|
|
|
|
} else {
|
|
|
|
pid = [app processIdentifier];
|
|
|
|
err = OK;
|
|
|
|
}
|
|
|
|
dispatch_semaphore_signal(lock);
|
|
|
|
}];
|
|
|
|
dispatch_semaphore_wait(lock, dispatch_time(DISPATCH_TIME_NOW, 20000000000)); // 20 sec timeout, wait for app to launch.
|
|
|
|
|
|
|
|
if (err == OK) {
|
|
|
|
if (r_child_id) {
|
|
|
|
*r_child_id = (ProcessID)pid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
} else {
|
2022-04-01 20:52:15 +02:00
|
|
|
Error err = ERR_TIMEOUT;
|
|
|
|
NSError *error = nullptr;
|
|
|
|
NSRunningApplication *app = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url options:NSWorkspaceLaunchNewInstance configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:&error];
|
|
|
|
if (error) {
|
|
|
|
err = ERR_CANT_FORK;
|
|
|
|
NSLog(@"Failed to execute: %@", error.localizedDescription);
|
|
|
|
} else {
|
|
|
|
if (r_child_id) {
|
|
|
|
*r_child_id = (ProcessID)[app processIdentifier];
|
|
|
|
}
|
|
|
|
err = OK;
|
|
|
|
}
|
|
|
|
return err;
|
2021-11-01 10:12:52 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-12-16 14:00:55 +01:00
|
|
|
return OS_Unix::create_process(p_path, p_arguments, r_child_id, p_open_console);
|
2021-11-01 10:12:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
Error OS_MacOS::create_instance(const List<String> &p_arguments, ProcessID *r_child_id) {
|
2022-01-26 10:01:27 +01:00
|
|
|
// 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"];
|
|
|
|
if (nsappname != nil) {
|
|
|
|
String path;
|
|
|
|
path.parse_utf8([[[NSBundle mainBundle] bundlePath] UTF8String]);
|
|
|
|
return create_process(path, p_arguments, r_child_id, false);
|
|
|
|
} else {
|
|
|
|
return create_process(get_executable_path(), p_arguments, r_child_id, false);
|
|
|
|
}
|
|
|
|
}
|
2021-11-08 11:35:13 +01:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
String OS_MacOS::get_unique_id() const {
|
2022-01-26 10:01:27 +01:00
|
|
|
static String serial_number;
|
|
|
|
|
|
|
|
if (serial_number.is_empty()) {
|
|
|
|
io_service_t platform_expert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
|
|
|
|
CFStringRef serial_number_cf_string = nullptr;
|
|
|
|
if (platform_expert) {
|
|
|
|
serial_number_cf_string = (CFStringRef)IORegistryEntryCreateCFProperty(platform_expert, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0);
|
|
|
|
IOObjectRelease(platform_expert);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *serial_number_ns_string = nil;
|
|
|
|
if (serial_number_cf_string) {
|
|
|
|
serial_number_ns_string = [NSString stringWithString:(__bridge NSString *)serial_number_cf_string];
|
|
|
|
CFRelease(serial_number_cf_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serial_number_ns_string) {
|
|
|
|
serial_number.parse_utf8([serial_number_ns_string UTF8String]);
|
2021-11-08 11:35:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-26 10:01:27 +01:00
|
|
|
return serial_number;
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
bool OS_MacOS::_check_internal_feature_support(const String &p_feature) {
|
2022-10-31 18:12:18 +01:00
|
|
|
if (p_feature == "system_fonts") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (p_feature == "pc") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2022-01-26 10:01:27 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::disable_crash_handler() {
|
2022-01-26 10:01:27 +01:00
|
|
|
crash_handler.disable();
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
bool OS_MacOS::is_disable_crash_handler() const {
|
2022-01-26 10:01:27 +01:00
|
|
|
return crash_handler.is_disabled();
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
Error OS_MacOS::move_to_trash(const String &p_path) {
|
2022-01-26 10:01:27 +01:00
|
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
|
|
NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())];
|
|
|
|
NSError *err;
|
|
|
|
|
|
|
|
if (![fm trashItemAtURL:url resultingItemURL:nil error:&err]) {
|
|
|
|
ERR_PRINT("trashItemAtURL error: " + String::utf8(err.localizedDescription.UTF8String));
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
2021-11-08 11:35:13 +01:00
|
|
|
}
|
|
|
|
|
2023-04-13 21:17:55 +02:00
|
|
|
String OS_MacOS::get_system_ca_certificates() {
|
|
|
|
CFArrayRef result;
|
|
|
|
SecCertificateRef item;
|
|
|
|
CFDataRef der;
|
|
|
|
|
|
|
|
OSStatus ret = SecTrustCopyAnchorCertificates(&result);
|
|
|
|
ERR_FAIL_COND_V(ret != noErr, "");
|
|
|
|
|
|
|
|
CFIndex l = CFArrayGetCount(result);
|
|
|
|
String certs;
|
|
|
|
PackedByteArray pba;
|
|
|
|
for (CFIndex i = 0; i < l; i++) {
|
|
|
|
item = (SecCertificateRef)CFArrayGetValueAtIndex(result, i);
|
|
|
|
der = SecCertificateCopyData(item);
|
|
|
|
int derlen = CFDataGetLength(der);
|
|
|
|
if (pba.size() < derlen * 3) {
|
|
|
|
pba.resize(derlen * 3);
|
|
|
|
}
|
|
|
|
size_t b64len = 0;
|
|
|
|
Error err = CryptoCore::b64_encode(pba.ptrw(), pba.size(), &b64len, (unsigned char *)CFDataGetBytePtr(der), derlen);
|
|
|
|
CFRelease(der);
|
|
|
|
ERR_CONTINUE(err != OK);
|
|
|
|
certs += "-----BEGIN CERTIFICATE-----\n" + String((char *)pba.ptr(), b64len) + "\n-----END CERTIFICATE-----\n";
|
|
|
|
}
|
|
|
|
CFRelease(result);
|
|
|
|
return certs;
|
|
|
|
}
|
|
|
|
|
2023-05-15 18:04:49 +02:00
|
|
|
OS::PreferredTextureFormat OS_MacOS::get_preferred_texture_format() const {
|
|
|
|
// macOS supports both formats on ARM. Prefer S3TC/BPTC
|
|
|
|
// for better compatibility with x86 platforms.
|
|
|
|
return PREFERRED_TEXTURE_FORMAT_S3TC_BPTC;
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
void OS_MacOS::run() {
|
2021-11-08 11:35:13 +01:00
|
|
|
if (!main_loop) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2021-11-08 11:35:13 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2024-02-01 21:06:53 +01:00
|
|
|
@autoreleasepool {
|
|
|
|
main_loop->initialize();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-01-15 09:20:45 +01:00
|
|
|
bool quit = false;
|
2022-08-16 20:29:55 +02:00
|
|
|
while (!quit) {
|
2024-02-01 21:06:53 +01:00
|
|
|
@autoreleasepool {
|
|
|
|
@try {
|
|
|
|
if (DisplayServer::get_singleton()) {
|
|
|
|
DisplayServer::get_singleton()->process_events(); // Get rid of pending events.
|
|
|
|
}
|
|
|
|
joypad_macos->process_joypads();
|
2018-01-15 09:20:45 +01:00
|
|
|
|
2024-02-01 21:06:53 +01:00
|
|
|
if (Main::iteration()) {
|
|
|
|
quit = true;
|
|
|
|
}
|
|
|
|
} @catch (NSException *exception) {
|
|
|
|
ERR_PRINT("NSException: " + String::utf8([exception reason].UTF8String));
|
2018-01-15 09:20:45 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2021-11-08 11:35:13 +01:00
|
|
|
|
2020-12-22 10:50:29 +01:00
|
|
|
main_loop->finalize();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
OS_MacOS::OS_MacOS() {
|
2021-03-30 14:42:50 +02:00
|
|
|
if (is_sandboxed()) {
|
|
|
|
// Load security-scoped bookmarks, request access, remove stale or invalid bookmarks.
|
|
|
|
NSArray *bookmarks = [[NSUserDefaults standardUserDefaults] arrayForKey:@"sec_bookmarks"];
|
|
|
|
NSMutableArray *new_bookmarks = [[NSMutableArray alloc] init];
|
|
|
|
for (id bookmark in bookmarks) {
|
|
|
|
NSError *error = nil;
|
|
|
|
BOOL isStale = NO;
|
|
|
|
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];
|
|
|
|
if (!error && !isStale) {
|
|
|
|
if ([url startAccessingSecurityScopedResource]) {
|
|
|
|
[new_bookmarks addObject:bookmark];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:new_bookmarks forKey:@"sec_bookmarks"];
|
|
|
|
}
|
|
|
|
|
2021-04-29 11:47:24 +02:00
|
|
|
main_loop = nullptr;
|
2017-09-22 07:56:02 +02:00
|
|
|
|
2017-11-21 10:35:01 +01:00
|
|
|
Vector<Logger *> loggers;
|
2022-07-20 08:28:22 +02:00
|
|
|
loggers.push_back(memnew(MacOSTerminalLogger));
|
2017-11-21 10:35:01 +01:00
|
|
|
_set_logger(memnew(CompositeLogger(loggers)));
|
2018-01-12 15:38:19 +01:00
|
|
|
|
2018-10-25 15:59:26 +02:00
|
|
|
#ifdef COREAUDIO_ENABLED
|
2018-03-04 18:18:05 +01:00
|
|
|
AudioDriverManager::add_driver(&audio_driver);
|
2018-10-25 15:59:26 +02:00
|
|
|
#endif
|
2020-03-07 17:02:54 +01:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
DisplayServerMacOS::register_macos_driver();
|
2021-07-22 18:23:48 +02:00
|
|
|
|
2022-01-26 10:01:27 +01:00
|
|
|
// Implicitly create shared NSApplication instance.
|
2021-07-22 18:23:48 +02:00
|
|
|
[GodotApplication sharedApplication];
|
|
|
|
|
2022-01-26 10:01:27 +01:00
|
|
|
// In case we are unbundled, make us a proper UI application.
|
2021-07-22 18:23:48 +02:00
|
|
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
|
|
|
|
// Menu bar setup must go between sharedApplication above and
|
|
|
|
// finishLaunching below, in order to properly emulate the behavior
|
2022-01-26 10:01:27 +01:00
|
|
|
// of NSApplicationMain.
|
2021-07-22 18:23:48 +02:00
|
|
|
|
2022-01-25 09:07:01 +01:00
|
|
|
NSMenu *main_menu = [[NSMenu alloc] initWithTitle:@""];
|
2021-07-22 18:23:48 +02:00
|
|
|
[NSApp setMainMenu:main_menu];
|
|
|
|
[NSApp finishLaunching];
|
|
|
|
|
|
|
|
id delegate = [[GodotApplicationDelegate alloc] init];
|
2023-09-28 11:40:18 +02:00
|
|
|
ERR_FAIL_NULL(delegate);
|
2021-07-22 18:23:48 +02:00
|
|
|
[NSApp setDelegate:delegate];
|
|
|
|
|
2022-01-26 10:01:27 +01:00
|
|
|
pre_wait_observer = CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, true, 0, &pre_wait_observer_cb, nullptr);
|
|
|
|
CFRunLoopAddObserver(CFRunLoopGetCurrent(), pre_wait_observer, kCFRunLoopCommonModes);
|
|
|
|
|
|
|
|
// Process application:openFile: event.
|
2021-07-22 18:23:48 +02:00
|
|
|
while (true) {
|
|
|
|
NSEvent *event = [NSApp
|
|
|
|
nextEventMatchingMask:NSEventMaskAny
|
|
|
|
untilDate:[NSDate distantPast]
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
|
|
|
|
if (event == nil) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-07-19 22:00:46 +02:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
OS_MacOS::~OS_MacOS() {
|
2022-01-26 10:01:27 +01:00
|
|
|
CFRunLoopRemoveObserver(CFRunLoopGetCurrent(), pre_wait_observer, kCFRunLoopCommonModes);
|
|
|
|
CFRelease(pre_wait_observer);
|
2017-09-08 03:01:49 +02:00
|
|
|
}
|