-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart-electron-dev.sh
More file actions
executable file
·136 lines (116 loc) · 4.67 KB
/
start-electron-dev.sh
File metadata and controls
executable file
·136 lines (116 loc) · 4.67 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
#!/bin/bash
# Electron Development Mode - One-click Startup Script
# Usage: ./start-electron-dev.sh
set -e
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
BACKEND_DIR="$PROJECT_DIR/backend"
FRONTEND_DIR="$PROJECT_DIR/frontend"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Electron Development Mode Launcher ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
echo ""
# Function to cleanup on exit
cleanup() {
echo -e "\n${YELLOW}Shutting down all services...${NC}"
if [ -n "$BACKEND_PID" ]; then
kill $BACKEND_PID 2>/dev/null || true
fi
if [ -n "$FRONTEND_PID" ]; then
kill $FRONTEND_PID 2>/dev/null || true
fi
if [ -n "$ELECTRON_PID" ]; then
kill $ELECTRON_PID 2>/dev/null || true
fi
exit 0
}
trap cleanup SIGINT SIGTERM
# Kill stale processes on our ports
for PORT in 19528 3000; do
PID=$(lsof -ti :$PORT 2>/dev/null || true)
if [ -n "$PID" ]; then
echo -e "${YELLOW}Killing stale process on port $PORT (pid $PID)${NC}"
kill $PID 2>/dev/null || true
fi
done
# Check if backend venv exists
if [ ! -d "$BACKEND_DIR/venv" ]; then
echo -e "${YELLOW}Creating Python virtual environment...${NC}"
python3 -m venv "$BACKEND_DIR/venv"
echo -e "${YELLOW}Installing backend dependencies...${NC}"
"$BACKEND_DIR/venv/bin/pip" install -q -r "$BACKEND_DIR/requirements.txt"
fi
# Check if .env exists
if [ ! -f "$BACKEND_DIR/.env" ]; then
echo -e "${RED}Warning: .env file not found!${NC}"
if [ -f "$BACKEND_DIR/.env.example" ]; then
cp "$BACKEND_DIR/.env.example" "$BACKEND_DIR/.env"
echo -e "${YELLOW}Created .env from .env.example. Please add your API keys.${NC}"
fi
fi
# Check frontend node_modules (verify next binary exists, not just directory)
if [ ! -x "$FRONTEND_DIR/node_modules/.bin/next" ]; then
echo -e "${YELLOW}Installing frontend dependencies...${NC}"
cd "$FRONTEND_DIR"
npm install
fi
# Backend port (use a less common port to avoid conflicts)
BACKEND_PORT=19528
# Start backend and frontend in parallel
echo -e "${GREEN}[1/3] Starting backend + frontend in parallel${NC}"
cd "$BACKEND_DIR"
source venv/bin/activate
python -m uvicorn app.main:app --host 127.0.0.1 --port ${BACKEND_PORT} --reload &
BACKEND_PID=$!
cd "$FRONTEND_DIR"
npm run dev &
FRONTEND_PID=$!
# Wait for both services concurrently (0.5s polling)
echo -e "${YELLOW}Waiting for services to start...${NC}"
BACKEND_READY=0
FRONTEND_READY=0
for i in $(seq 1 60); do
if [ $BACKEND_READY -eq 0 ] && curl -s http://localhost:${BACKEND_PORT}/health > /dev/null 2>&1; then
echo -e "${GREEN} ✓ Backend ready (http://localhost:${BACKEND_PORT})${NC}"
BACKEND_READY=1
fi
if [ $FRONTEND_READY -eq 0 ] && curl -s http://localhost:3000 > /dev/null 2>&1; then
echo -e "${GREEN} ✓ Frontend ready (http://localhost:3000)${NC}"
FRONTEND_READY=1
fi
if [ $BACKEND_READY -eq 1 ] && [ $FRONTEND_READY -eq 1 ]; then
break
fi
sleep 0.5
done
if [ $BACKEND_READY -eq 0 ]; then
echo -e "${RED}Backend failed to start within 30s!${NC}"
cleanup
fi
if [ $FRONTEND_READY -eq 0 ]; then
echo -e "${RED}Frontend failed to start within 30s!${NC}"
cleanup
fi
# Start Electron in development mode
echo -e "${GREEN}[2/3] Starting Electron app...${NC}"
cd "$FRONTEND_DIR"
NODE_ENV=development npx electron ./electron/main.js &
ELECTRON_PID=$!
echo ""
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Electron Dev Mode Started! ║${NC}"
echo -e "${GREEN}╠════════════════════════════════════════╣${NC}"
echo -e "${GREEN}║ Frontend: http://localhost:3000 ║${NC}"
echo -e "${GREEN}║ Backend: http://localhost:${BACKEND_PORT} ║${NC}"
echo -e "${GREEN}║ DevTools: Auto-opened in Electron ║${NC}"
echo -e "${GREEN}╠════════════════════════════════════════╣${NC}"
echo -e "${GREEN}║ Press Ctrl+C to stop all services ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════╝${NC}"
echo ""
# Wait for all processes
wait