- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
Latest commit
executable file
·167 lines (149 loc) · 4.24 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·167 lines (149 loc) · 4.24 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
set -euo pipefail
MODE="${1:-run}"
BUNDLE_ID="dev.codetwo.app.dev"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.."&& pwd)"
DESKTOP_DIR="$ROOT_DIR/apps/desktop"
case"$(uname -m)"in
arm64|aarch64) ELECTROBUN_ARCH="arm64" ;;
x86_64) ELECTROBUN_ARCH="x64" ;;
*)
echo"unsupported macOS architecture: $(uname -m)">&2
exit 1
;;
esac
APP_BUNDLE="$DESKTOP_DIR/build/dev-macos-$ELECTROBUN_ARCH/C2-dev.app"
APP_EXECUTABLE="$APP_BUNDLE/Contents/MacOS/launcher"
STATE_DIR="$ROOT_DIR/.codex/run"
PID_FILE="$STATE_DIR/codetwo-dev.pid"
APP_RUNNER_PID=""
mkdir -p "$STATE_DIR"
# Homebrew keeps versioned Zig formulae keg-only. Keep the project requirement
# local to this launcher rather than modifying the user's global shell setup.
if [[ -d /opt/homebrew/opt/zig@0.15/bin ]];then
export PATH="/opt/homebrew/opt/zig@0.15/bin:$PATH"
fi
require_command() {
if!command -v "$1">/dev/null 2>&1;then
echo"missing required command: $1">&2
exit 1
fi
}
require_command bun
require_command cargo
require_command zig
if [[ "$(zig version)"!="0.15.2" ]];then
echo"C2 requires Zig 0.15.2; found $(zig version).">&2
exit 1
fi
stop_existing() {
if [[ -f"$PID_FILE" ]];then
previous_pid="$(<"$PID_FILE")"
if [[ "$previous_pid"=~ ^[0-9]+$ ]] &&kill -0 "$previous_pid">/dev/null 2>&1;then
previous_command="$(ps -p "$previous_pid" -o command= 2>/dev/null || true)"
if [[ "$previous_command"==*"$DESKTOP_DIR/build/"*"/Contents/MacOS/launcher"* ]];then
kill"$previous_pid">/dev/null 2>&1||true
for_in {1..20};do
kill -0 "$previous_pid">/dev/null 2>&1||break
sleep 0.1
done
fi
fi
rm -f "$PID_FILE"
fi
}
cleanup() {
if [[ -n"$APP_RUNNER_PID" ]];then
kill"$APP_RUNNER_PID">/dev/null 2>&1||true
wait"$APP_RUNNER_PID">/dev/null 2>&1||true
fi
if [[ -f"$PID_FILE" ]] && [[ "$(<"$PID_FILE")"=="$APP_RUNNER_PID" ]];then
rm -f "$PID_FILE"
fi
}
build_app() {
cd"$DESKTOP_DIR"
if [[ !-d node_modules ]];then
bun install --frozen-lockfile
fi
# Always run from the generated bundle so macOS can attribute microphone and speech-recognition
# permission prompts to C2 instead of to a loose helper executable.
bun run build
if [[ !-x"$APP_EXECUTABLE" ]];then
echo"Electrobun did not create $APP_EXECUTABLE">&2
exit 1
fi
actual_bundle_id="$(/usr/bin/plutil -extract CFBundleIdentifier raw -- "$APP_BUNDLE/Contents/Info.plist")"
if [[ "$actual_bundle_id"!="$BUNDLE_ID" ]];then
echo"C2-dev.app has bundle identifier $actual_bundle_id; expected $BUNDLE_ID.">&2
exit 1
fi
forprivacy_keyin NSMicrophoneUsageDescription NSSpeechRecognitionUsageDescription;do
privacy_value="$(/usr/bin/plutil -extract "$privacy_key" raw -- "$APP_BUNDLE/Contents/Info.plist")"
if [[ -z"$privacy_value" ]];then
echo"C2-dev.app has an empty $privacy_key value.">&2
exit 1
fi
done
}
start_app() {
"$APP_EXECUTABLE"&
APP_RUNNER_PID=$!
echo"$APP_RUNNER_PID">"$PID_FILE"
}
wait_for_app() {
for_in {1..20};do
if!kill -0 "$APP_RUNNER_PID">/dev/null 2>&1;then
wait"$APP_RUNNER_PID"
return$?
fi
sleep 0.25
done
echo"C2 launched successfully (pid: $APP_RUNNER_PID)."
}
case"$MODE"in
run)
stop_existing
trap cleanup EXIT INT TERM
build_app
start_app
wait"$APP_RUNNER_PID"
;;
--verify|verify)
stop_existing
trap cleanup EXIT INT TERM
build_app
start_app
wait_for_app
wait"$APP_RUNNER_PID"
;;
--debug|debug)
stop_existing
export RUST_BACKTRACE=1
export RUST_LOG="${RUST_LOG:-debug}"
trap cleanup EXIT INT TERM
build_app
start_app
wait"$APP_RUNNER_PID"
;;
--logs|logs)
stop_existing
trap cleanup EXIT INT TERM
build_app
start_app
wait_for_app
/usr/bin/log stream --info --style compact --predicate "processID == $APP_RUNNER_PID"
;;
--telemetry|telemetry)
stop_existing
trap cleanup EXIT INT TERM
build_app
start_app
wait_for_app
/usr/bin/log stream --info --style compact --predicate "subsystem == \"$BUNDLE_ID\""
;;
*)
echo"usage: $0 [run|--verify|--debug|--logs|--telemetry]">&2
exit 2
;;
esac