summaryrefslogtreecommitdiffstats
path: root/platform/macos
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2024-07-31 16:10:10 +0300
committerRémi Verschelde <rverschelde@gmail.com>2024-07-31 16:54:53 +0200
commit1dfcbccfe6607b6cf388538eae962cb334783c70 (patch)
treeafab7edcb7b6cfe7a74e25018715992d47af0768 /platform/macos
parent1d57b81d2610f8c104fcead874995a583274d12d (diff)
downloadredot-engine-1dfcbccfe6607b6cf388538eae962cb334783c70.tar.gz
[macOS] Fix `is_process_running` and `kill` for bundled apps.
Diffstat (limited to 'platform/macos')
-rw-r--r--platform/macos/os_macos.h2
-rw-r--r--platform/macos/os_macos.mm18
2 files changed, 20 insertions, 0 deletions
diff --git a/platform/macos/os_macos.h b/platform/macos/os_macos.h
index 912a682a6b..df3a4009a3 100644
--- a/platform/macos/os_macos.h
+++ b/platform/macos/os_macos.h
@@ -109,6 +109,8 @@ public:
virtual String get_executable_path() const override;
virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override;
+ virtual Error kill(const ProcessID &p_pid) override;
+ virtual bool is_process_running(const ProcessID &p_pid) const override;
virtual String get_unique_id() const override;
virtual String get_processor_name() const override;
diff --git a/platform/macos/os_macos.mm b/platform/macos/os_macos.mm
index 9f0bea5951..078be53a8d 100644
--- a/platform/macos/os_macos.mm
+++ b/platform/macos/os_macos.mm
@@ -666,6 +666,24 @@ Error OS_MacOS::create_instance(const List<String> &p_arguments, ProcessID *r_ch
}
}
+bool OS_MacOS::is_process_running(const ProcessID &p_pid) const {
+ NSRunningApplication *app = [NSRunningApplication runningApplicationWithProcessIdentifier:(pid_t)p_pid];
+ if (!app) {
+ return OS_Unix::is_process_running(p_pid);
+ }
+
+ return ![app isTerminated];
+}
+
+Error OS_MacOS::kill(const ProcessID &p_pid) {
+ NSRunningApplication *app = [NSRunningApplication runningApplicationWithProcessIdentifier:(pid_t)p_pid];
+ if (!app) {
+ return OS_Unix::kill(p_pid);
+ }
+
+ return [app forceTerminate] ? OK : ERR_INVALID_PARAMETER;
+}
+
String OS_MacOS::get_unique_id() const {
static String serial_number;