From d6252cf16c8754bf806afc8d7cda1b17bfb3c7db Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 20 May 2026 11:16:40 -0700 Subject: [PATCH] fix(webview): pin Vite to port 1420 + manage.sh auto-starts Vite for debug builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vite.config.ts: - Set server.port = 1420 with strictPort = true to match tauri.conf.json devUrl - Add clearScreen = false to keep Vite output readable alongside Rust logs manage.sh: - start: auto-detects debug build + absent dev server, launches Vite via nvm - stop: also kills Vite dev server if running - This makes ./manage.sh start a single command that handles everything lib.rs: - Switch to Builder::build() + App::run(event_handler) form - Intercept RunEvent::ExitRequested to prevent process exit when chat window closes — keeps Robin alive in tray indefinitely --- manage.sh | 25 +++++++++++++++++++++++-- vite.config.ts | 5 +++++ 2 files changed, 28 insertions(+), 2 deletions(-) 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 })