diff --git a/manage.sh b/manage.sh index cb24688..016111d 100755 --- a/manage.sh +++ b/manage.sh @@ -52,17 +52,33 @@ case "$cmd" in start) # Start Robin in the background (daemonised via nohup). + # Also starts the Vite dev server if a release binary is not available + # and Node/nvm is present, so the webview has something to connect to. if pgrep -x "$APP_NAME" > /dev/null 2>&1; then echo "Robin is already running (PID $(pgrep -x "$APP_NAME"))" exit 0 fi bin="$(_require_binary)" - echo "Starting Robin in background..." export DISPLAY="${DISPLAY:-:0}" export RUST_LOG="${RUST_LOG:-robin_lib=info,warn}" mkdir -p "$(dirname "$LOG_FILE")" + + # If using the debug binary and no Vite server is running, start one. + if [[ "$bin" == *"target/debug"* ]] && ! curl -sf http://localhost:1420 > /dev/null 2>&1; then + NVM_DIR="${NVM_DIR:-$HOME/.nvm}" + if [[ -s "$NVM_DIR/nvm.sh" ]] && command -v npm > /dev/null 2>&1 || { source "$NVM_DIR/nvm.sh" 2>/dev/null && command -v npm > /dev/null 2>&1; }; then + echo "Starting Vite dev server on :1420..." + nohup npm --prefix "$SCRIPT_DIR" run dev >> /tmp/robin-vite.log 2>&1 & + echo "Vite PID $! — logs: /tmp/robin-vite.log" + sleep 2 # give Vite time to bind before Robin connects + else + echo "Note: no release binary and Node not found — webview will show connection error." + echo "Run 'npm install && npm run dev' in $SCRIPT_DIR to fix this." + fi + fi + nohup "$bin" >> "$LOG_FILE" 2>&1 & - echo "Started (PID $!). Logs: $LOG_FILE" + echo "Robin started (PID $!). Logs: $LOG_FILE" ;; stop) @@ -72,6 +88,11 @@ case "$cmd" in else echo "Robin is not running." fi + # Stop Vite dev server if we started it. + if pgrep -f "vite" > /dev/null 2>&1; then + pkill -f "node.*vite" 2>/dev/null || true + echo "Vite dev server stopped." + fi ;; restart) diff --git a/vite.config.ts b/vite.config.ts index bbcf80c..b2776bc 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,4 +4,9 @@ import vue from '@vitejs/plugin-vue' // https://vite.dev/config/ export default defineConfig({ plugins: [vue()], + server: { + port: 1420, + strictPort: true, // fail loudly if 1420 is taken rather than silently shifting + }, + clearScreen: false, // keep terminal output readable alongside cargo/Tauri logs })