Skip to content

Commit

Permalink
[macOS] Fix is_process_running and kill for bundled apps.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruvzg committed Jul 31, 2024
1 parent 3e0c10d commit da0e4ee
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/classes/OS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@
<description>
Returns the exit code of a spawned process once it has finished running (see [method is_process_running]).
Returns [code]-1[/code] if the [param pid] is not a PID of a spawned child process, the process is still running, or the method is not implemented for the current platform.
[b]Note:[/b] Returns [code]-1[/code] if the [param pid] is macOS bundled app process.
[b]Note:[/b] This method is implemented on Android, Linux, macOS and Windows.
</description>
</method>
Expand Down
2 changes: 2 additions & 0 deletions platform/macos/os_macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class OS_MacOS : public OS_Unix {
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;
Expand Down
18 changes: 18 additions & 0 deletions platform/macos/os_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,24 @@
}
}

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;

Expand Down

0 comments on commit da0e4ee

Please sign in to comment.