chore(mac): rebuild and relaunch like trimmy

This commit is contained in:
Peter Steinberger
2025-12-06 01:15:01 +01:00
parent 26e939c1eb
commit 12e5b8124e

View File

@@ -1,40 +1,55 @@
#!/usr/bin/env bash
# Kill any running Clawdis, rebuild/package, relaunch packaged app, and verify it is alive.
# Reset Clawdis like Trimmy: kill running instances, rebuild, repackage, relaunch, verify.
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
APP_BUNDLE="${ROOT_DIR}/dist/Clawdis.app"
APP_PROCESS_PATTERN="Clawdis.app/Contents/MacOS/Clawdis"
DEBUG_PROCESS_PATTERN="${ROOT_DIR}/apps/macos/.build-local/debug/Clawdis"
RELEASE_PROCESS_PATTERN="${ROOT_DIR}/apps/macos/.build-local/release/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"
log() { printf '%s\n' "$*"; }
fail() { printf 'ERROR: %s\n' "$*" >&2; exit 1; }
run_step() {
local label="$1"; shift
log "==> ${label}"
if ! "$@"; then
fail "${label} failed"
fi
}
kill_all_clawdis() {
for _ in {1..10}; do
pkill -f "${APP_PROCESS_PATTERN}" 2>/dev/null || true
pkill -f "${DEBUG_PROCESS_PATTERN}" 2>/dev/null || true
pkill -f "${LOCAL_PROCESS_PATTERN}" 2>/dev/null || true
pkill -f "${RELEASE_PROCESS_PATTERN}" 2>/dev/null || true
pkill -x "Clawdis" 2>/dev/null || true
if ! pgrep -f "${APP_PROCESS_PATTERN}" >/dev/null 2>&1 \
&& ! pgrep -f "${DEBUG_PROCESS_PATTERN}" >/dev/null 2>&1 \
&& ! pgrep -f "${LOCAL_PROCESS_PATTERN}" >/dev/null 2>&1 \
&& ! pgrep -f "${RELEASE_PROCESS_PATTERN}" >/dev/null 2>&1 \
&& ! pgrep -x "Clawdis" >/dev/null 2>&1; then
return 0
fi
sleep 0.25
sleep 0.3
done
}
# 1) Kill all running instances first.
log "==> Killing existing Clawdis instances"
kill_all_clawdis
log "==> Packaging + launching app"
"${ROOT_DIR}/scripts/package-mac-app.sh"
# 2) Rebuild (and optionally extend to tests later if desired).
run_step "swift build" bash -lc "cd '${ROOT_DIR}/apps/macos' && swift build -q"
log "==> Verifying app is running"
# 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.
sleep 1
if pgrep -f "${APP_PROCESS_PATTERN}" >/dev/null 2>&1; then
log "OK: Clawdis is running."