-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestore-studio-margin.sh
More file actions
executable file
·41 lines (36 loc) · 1.35 KB
/
Copy pathrestore-studio-margin.sh
File metadata and controls
executable file
·41 lines (36 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INJECTOR="$SCRIPT_DIR/injector.mjs"
STATE_ROOT="$HOME/Library/Application Support/StudioMarginCodex"
STATE_PATH="$STATE_ROOT/state.json"
PLIST_PATH="$HOME/Library/LaunchAgents/com.studiomargin.apply.plist"
LAUNCH_LABEL="com.studiomargin.apply"
PORT=""
while [[ $# -gt 0 ]]; do
case "$1" in
--port) PORT="$2"; shift 2 ;;
*) echo "Unknown argument: $1" >&2; exit 2 ;;
esac
done
launchctl bootout "gui/$(id -u)/$LAUNCH_LABEL" >/dev/null 2>&1 || true
safe_stop_injector() {
local pid="$1" command
[[ "$pid" =~ ^[0-9]+$ ]] || return 0
command="$(ps -p "$pid" -o command= 2>/dev/null || true)"
if [[ "$command" == *"$INJECTOR"* && "$command" == *"--watch"* ]]; then
kill "$pid" 2>/dev/null || true
fi
}
if [[ -f "$STATE_PATH" ]]; then
STATE_VALUES="$(node -e 'try { const s=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")); console.log(`${s.port || ""}\t${s.injectorPid || ""}`) } catch {}' "$STATE_PATH")"
STATE_PORT="${STATE_VALUES%%$'\t'*}"
STATE_PID="${STATE_VALUES#*$'\t'}"
[[ -z "$PORT" ]] && PORT="$STATE_PORT"
[[ -n "$STATE_PID" ]] && safe_stop_injector "$STATE_PID"
fi
PORT="${PORT:-9335}"
sleep 0.25
node "$INJECTOR" --remove --port "$PORT" --timeout-ms 3000 >/dev/null 2>&1 || true
rm -f "$PLIST_PATH"
echo "The live Studio Margin theme was removed."