From f4f4f2d31494407d9a53ea2d43601ad2d73d0efb Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 7 Dec 2025 01:05:05 +0000 Subject: [PATCH] Mac: run via launchd agent with mach service --- scripts/restart-mac.sh | 43 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/scripts/restart-mac.sh b/scripts/restart-mac.sh index 1521fd8bb..d47b9a762 100755 --- a/scripts/restart-mac.sh +++ b/scripts/restart-mac.sh @@ -9,6 +9,7 @@ APP_PROCESS_PATTERN="Clawdis.app/Contents/MacOS/Clawdis" DEBUG_PROCESS_PATTERN="${ROOT_DIR}/apps/macos/.build/debug/Clawdis" LOCAL_PROCESS_PATTERN="${ROOT_DIR}/apps/macos/.build-local/debug/Clawdis" RELEASE_PROCESS_PATTERN="${ROOT_DIR}/apps/macos/.build/release/Clawdis" +LAUNCH_AGENT="${HOME}/Library/LaunchAgents/com.steipete.clawdis.plist" log() { printf '%s\n' "$*"; } fail() { printf 'ERROR: %s\n' "$*" >&2; exit 1; } @@ -21,6 +22,38 @@ run_step() { fi } +write_launch_agent() { + cat > "${LAUNCH_AGENT}" < + + + + Label + com.steipete.clawdis + ProgramArguments + + ${APP_BUNDLE}/Contents/MacOS/Clawdis + + WorkingDirectory + ${ROOT_DIR} + RunAtLoad + + KeepAlive + + MachServices + + com.steipete.clawdis.xpc + + + StandardOutPath + /tmp/clawdis.log + StandardErrorPath + /tmp/clawdis.log + + +PLIST +} + kill_all_clawdis() { for _ in {1..10}; do pkill -f "${APP_PROCESS_PATTERN}" 2>/dev/null || true @@ -50,10 +83,16 @@ run_step "swift build" bash -lc "cd '${ROOT_DIR}/apps/macos' && swift build -q - # 3) Package + relaunch the app (script also stops any stragglers). run_step "package app" "${ROOT_DIR}/scripts/package-mac-app.sh" -# 4) Verify the packaged app is alive. +# 4) Install launch agent with Mach service and bootstrap it. +write_launch_agent +launchctl bootout gui/"$UID"/com.steipete.clawdis 2>/dev/null || true +run_step "bootstrap launch agent" launchctl bootstrap gui/"$UID" "${LAUNCH_AGENT}" +run_step "kickstart" launchctl kickstart -k gui/"$UID"/com.steipete.clawdis + +# 5) Verify the packaged app is alive. sleep 1 if pgrep -f "${APP_PROCESS_PATTERN}" >/dev/null 2>&1; then - log "OK: Clawdis is running." + log "OK: Clawdis is running (launchd)." else fail "App exited immediately. Check /tmp/clawdis.log or Console.app (User Reports)." fi