-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·173 lines (154 loc) · 6 KB
/
dev.sh
File metadata and controls
executable file
·173 lines (154 loc) · 6 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
168
169
170
171
172
173
#!/bin/bash
set -e
BINARY_NAME="Omi Computer" # Package.swift target — binary paths, pkill, CFBundleExecutable
APP_NAME="Omi Dev"
BUNDLE_ID="com.omi.desktop-dev"
BUILD_DIR="build"
APP_BUNDLE="$BUILD_DIR/$APP_NAME.app"
BACKEND_DIR="$(dirname "$0")/Backend"
BACKEND_PID=""
TUNNEL_PID=""
TUNNEL_URL="${TUNNEL_URL:-}"
# Cleanup function to stop backend and tunnel on exit
cleanup() {
if [ -n "$TUNNEL_PID" ] && kill -0 "$TUNNEL_PID" 2>/dev/null; then
echo "Stopping tunnel (PID: $TUNNEL_PID)..."
kill "$TUNNEL_PID" 2>/dev/null || true
fi
if [ -n "$BACKEND_PID" ] && kill -0 "$BACKEND_PID" 2>/dev/null; then
echo "Stopping backend (PID: $BACKEND_PID)..."
kill "$BACKEND_PID" 2>/dev/null || true
fi
}
trap cleanup EXIT
# Kill existing instances
pkill "$BINARY_NAME" 2>/dev/null || true
lsof -ti:8080 | xargs kill -9 2>/dev/null || true
# Start Cloudflare quick tunnel (auto-generates a *.trycloudflare.com URL)
if command -v cloudflared >/dev/null 2>&1; then
echo "Starting Cloudflare quick tunnel..."
TUNNEL_LOG=$(mktemp /tmp/cloudflared-XXXXXX.log)
cloudflared tunnel --url http://localhost:8080 > "$TUNNEL_LOG" 2>&1 &
TUNNEL_PID=$!
for i in {1..20}; do
TUNNEL_URL=$(grep -o 'https://[a-z0-9-]*\.trycloudflare\.com' "$TUNNEL_LOG" 2>/dev/null | head -1)
if [ -n "$TUNNEL_URL" ]; then break; fi
sleep 0.5
done
if [ -n "$TUNNEL_URL" ]; then
rm -f "$TUNNEL_LOG"
else
echo "Warning: Could not get tunnel URL — using localhost (see $TUNNEL_LOG for details)"
TUNNEL_URL="http://localhost:8080"
fi
else
echo "cloudflared not found — skipping tunnel"
TUNNEL_URL="http://localhost:8080"
fi
# Start backend
echo "Starting backend..."
cd "$BACKEND_DIR"
if [ ! -d "venv" ]; then
echo "Creating Python virtual environment..."
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
else
source venv/bin/activate
fi
python main.py &
BACKEND_PID=$!
cd - > /dev/null
# Wait for backend to be ready
echo "Waiting for backend to start..."
for i in {1..30}; do
if curl -s http://localhost:8080 > /dev/null 2>&1; then
echo "Backend is ready!"
break
fi
if ! kill -0 "$BACKEND_PID" 2>/dev/null; then
echo "Backend failed to start"
exit 1
fi
sleep 0.5
done
# Build debug
swift build -c debug --package-path Desktop
# Clean old app bundles from build dir
rm -rf "$BUILD_DIR/Omi Computer.app" "$BUILD_DIR/Omi Beta.app" 2>/dev/null
# Create app bundle
mkdir -p "$APP_BUNDLE/Contents/MacOS"
mkdir -p "$APP_BUNDLE/Contents/Resources"
# Copy binary
cp "Desktop/.build/debug/$BINARY_NAME" "$APP_BUNDLE/Contents/MacOS/$BINARY_NAME"
# Copy and fix Info.plist
cp Desktop/Info.plist "$APP_BUNDLE/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleExecutable $BINARY_NAME" "$APP_BUNDLE/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $BUNDLE_ID" "$APP_BUNDLE/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleName $APP_NAME" "$APP_BUNDLE/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $APP_NAME" "$APP_BUNDLE/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleURLTypes:0:CFBundleURLSchemes:0 omi-computer-dev" "$APP_BUNDLE/Contents/Info.plist"
# Copy GoogleService-Info.plist for Firebase
cp Desktop/Sources/GoogleService-Info.plist "$APP_BUNDLE/Contents/Resources/"
# Copy resource bundle (contains app assets like herologo.png, omi-with-rope-no-padding.webp, etc.)
SWIFT_BUILD_DIR="Desktop/.build/debug"
if [ -d "$SWIFT_BUILD_DIR/Omi Computer_Omi Computer.bundle" ]; then
cp -R "$SWIFT_BUILD_DIR/Omi Computer_Omi Computer.bundle" "$APP_BUNDLE/Contents/Resources/"
echo "Copied resource bundle"
else
echo "Warning: Resource bundle not found at $SWIFT_BUILD_DIR/Omi Computer_Omi Computer.bundle"
fi
# Copy .env.app (app runtime secrets only) and add API URL
if [ -f ".env.app" ]; then
cp .env.app "$APP_BUNDLE/Contents/Resources/.env"
else
touch "$APP_BUNDLE/Contents/Resources/.env"
fi
# Set API URL to tunnel for development (overrides production default)
if grep -q "^OMI_API_URL=" "$APP_BUNDLE/Contents/Resources/.env"; then
sed -i '' "s|^OMI_API_URL=.*|OMI_API_URL=$TUNNEL_URL|" "$APP_BUNDLE/Contents/Resources/.env"
else
echo "OMI_API_URL=$TUNNEL_URL" >> "$APP_BUNDLE/Contents/Resources/.env"
fi
echo "Using backend: $TUNNEL_URL"
# Copy app icon
cp -f omi_icon.icns "$APP_BUNDLE/Contents/Resources/OmiIcon.icns"
# Create PkgInfo
echo -n "APPL????" > "$APP_BUNDLE/Contents/PkgInfo"
# Sign app with a stable identity so TCC permissions persist across rebuilds.
# Auto-detect: Developer ID > Apple Development > ad-hoc fallback.
SIGN_IDENTITY="${OMI_SIGN_IDENTITY:-}"
if [ -z "$SIGN_IDENTITY" ]; then
SIGN_IDENTITY=$(security find-identity -v -p codesigning | grep "Developer ID Application" | head -1 | sed 's/.*"\(.*\)"/\1/')
if [ -z "$SIGN_IDENTITY" ]; then
SIGN_IDENTITY=$(security find-identity -v -p codesigning | grep "Apple Development" | head -1 | sed 's/.*"\(.*\)"/\1/')
fi
fi
if [ -n "$SIGN_IDENTITY" ]; then
echo "Signing with: $SIGN_IDENTITY"
codesign --force --options runtime --entitlements Desktop/Omi.entitlements --sign "$SIGN_IDENTITY" "$APP_BUNDLE"
else
echo ""
echo "ERROR: No signing identity found. Ad-hoc signing causes macOS to reset"
echo " Screen Recording permissions for ALL Omi apps (including prod/beta)."
echo ""
echo " Fix: Install an Apple Development certificate in Keychain Access,"
echo " or set OMI_SIGN_IDENTITY to a valid identity."
echo ""
exit 1
fi
echo "Dev build complete: $APP_BUNDLE"
echo ""
echo "=== Services Running ==="
echo "Backend: http://localhost:8080 (PID: $BACKEND_PID)"
if [ -n "$TUNNEL_PID" ]; then
echo "Tunnel: $TUNNEL_URL (PID: $TUNNEL_PID)"
else
echo "Tunnel: not running (using $TUNNEL_URL)"
fi
echo "========================"
echo ""
open "$APP_BUNDLE"
# Wait for backend process (keeps script running and shows logs)
echo "Press Ctrl+C to stop..."
wait "$BACKEND_PID"