macOS support (code only, no build yet)

This commit is contained in:
sarah committed 2026-10-14 13:18:20 +02:00
1 parent 1feb6d4336
commit ca04dcd4a7
17 files changed
+572 -126

No files matched your search

+9 -2
View File
@@ -1,9 +1,10 @@
"""Background services SaraSuite runs itself, where there's no systemd --user
to do it: Windows, and Linux with another init system (runit on Void, OpenRC,
to do it: Windows, macOS, and Linux with another init system (runit on Void, OpenRC,
s6, dinit, ...). Each runs as Programs/ServiceRun.py <Name> <Script>
<WorkingDir>, which keeps it going (restarts it if it fails), logs its output
and records its PID, all in ServicesDir. At login it's started by
- Windows: a shortcut in the Startup folder;
- macOS: a LaunchAgent (~/Library/LaunchAgents/srhtnin.<Name>.plist);
- Linux: an XDG autostart entry (~/.config/autostart/<Name>.desktop), which
desktop sessions start whatever the init system is.
The installer places those (Installer._ApplyStandInServices); this starts,
@@ -18,7 +19,7 @@ import time
from pathlib import Path
from typing import Callable, Optional
from Core import ChildEnvironment, IsWindows, ServicesDir
from Core import ChildEnvironment, IsMac, IsWindows, ServicesDir
LogFn = Callable[[str], None]
@@ -41,6 +42,12 @@ def ServicePid(Name: str) -> Optional[int]:
Pid = int(_PidFile(Name).read_text().strip())
except (OSError, ValueError):
return None
if IsMac: # no /proc: ask ps for its command line
try:
Output = subprocess.run(["ps", "-o", "command=", "-p", str(Pid)], capture_output=True, text=True, timeout=15).stdout
except (OSError, subprocess.SubprocessError):
return None
return Pid if "ServiceRun.py" in Output else None
if not IsWindows:
try:
return Pid if b"ServiceRun.py" in Path(f"/proc/{Pid}/cmdline").read_bytes() else None