Mac: stabilize XPC and voice wake handling

This commit is contained in:
Peter Steinberger
2025-12-07 02:09:54 +00:00
parent ea37ee6cb3
commit 78c67ed53d
5 changed files with 81 additions and 85 deletions

View File

@@ -22,38 +22,6 @@ run_step() {
fi
}
write_launch_agent() {
cat > "${LAUNCH_AGENT}" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.steipete.clawdis</string>
<key>ProgramArguments</key>
<array>
<string>${APP_BUNDLE}/Contents/MacOS/Clawdis</string>
</array>
<key>WorkingDirectory</key>
<string>${ROOT_DIR}</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>MachServices</key>
<dict>
<key>com.steipete.clawdis.xpc</key>
<true/>
</dict>
<key>StandardOutPath</key>
<string>/tmp/clawdis.log</string>
<key>StandardErrorPath</key>
<string>/tmp/clawdis.log</string>
</dict>
</plist>
PLIST
}
kill_all_clawdis() {
for _ in {1..10}; do
pkill -f "${APP_PROCESS_PATTERN}" 2>/dev/null || true
@@ -72,9 +40,14 @@ kill_all_clawdis() {
done
}
stop_launch_agent() {
launchctl bootout gui/"$UID"/com.steipete.clawdis 2>/dev/null || true
}
# 1) Kill all running instances first.
log "==> Killing existing Clawdis instances"
kill_all_clawdis
stop_launch_agent
# 2) Rebuild into the same path the packager consumes (.build).
run_step "clean build cache" bash -lc "cd '${ROOT_DIR}/apps/macos' && rm -rf .build .build-swift .swiftpm 2>/dev/null || true"
@@ -83,16 +56,10 @@ 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) 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.
# 4) Verify the packaged app is alive.
sleep 1
if pgrep -f "${APP_PROCESS_PATTERN}" >/dev/null 2>&1; then
log "OK: Clawdis is running (launchd)."
log "OK: Clawdis is running."
else
fail "App exited immediately. Check /tmp/clawdis.log or Console.app (User Reports)."
fi