Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions frontend/electron/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ describe("Electron launcher detail controls", () => {
});
});

describe("Electron file watching", () => {
it("disables backend reload and Vite watching for Electron development", () => {
expect(devScriptSource).not.toContain("--reload");
expect(devScriptSource).not.toContain("--reload-dir");
expect(devScriptSource).toContain('ELECTRON_DEV="1"');
expect(readFileSync(path.join(__dirname, "../vite.config.ts"), "utf8")).toContain("watch: null");
});
});

describe("Electron launcher paths", () => {
it("resolves the repository from the script location when launched elsewhere", () => {
const output = execFileSync("bash", [devScriptPath], {
Expand Down
8 changes: 7 additions & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import tailwindcss from "@tailwindcss/vite";
// Which backend the dev proxy forwards /api to: `make dev`'s backend on 8000 by default, or
// whatever port electron-dev.sh's dedicated Electron backend is actually listening on.
const backendPort = process.env.VITE_BACKEND_PORT || "8000";
const isElectronDev = process.env.ELECTRON_DEV === "1";

export default defineConfig({
plugins: [react(), tailwindcss()],
server: { proxy: { "/api": { target: `http://127.0.0.1:${backendPort}`, changeOrigin: true } } },
server: {
// Electron development is intentionally restart-to-update: Vite's watcher can consume
// enough resources during repository changes to freeze the UI while sending messages.
...(isElectronDev ? { watch: null } : {}),
proxy: { "/api": { target: `http://127.0.0.1:${backendPort}`, changeOrigin: true } },
},
test: { environment: "node" },
} as any);
19 changes: 7 additions & 12 deletions scripts/electron-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ kill_process_group() {
local pid="$1"
[[ -z "$pid" ]] && return 0

# uvicorn --reload and Vite each create children. Kill the process group so
# those children do not outlive the launcher, then escalate if necessary.
# Backend and Vite each create children. Kill the process group so those children do not
# outlive the launcher, then escalate if necessary.
kill -TERM -- "-${pid}" 2>/dev/null || true
for _ in {1..20}; do
kill -0 "$pid" 2>/dev/null || return 0
Expand Down Expand Up @@ -74,20 +74,15 @@ os.execvp(sys.argv[1], sys.argv[1:])
PY
}

# Use the same root-relative commands as the Makefile targets. OPENBOT_API_URL is passed to
# Electron/preload so packaged-style absolute API requests use this dedicated backend, and
# VITE_BACKEND_PORT points Vite's own dev proxy (relative /api/* fetches from the loaded page)
# at the same port, so both request paths reach the one backend actually running here.
# Use the same root-relative commands as the Makefile targets. Electron intentionally runs
# without backend reload or Vite file watching: changes take effect after an app restart,
# avoiding watcher activity that can freeze the UI while messages are being sent.
echo "Starting Electron backend on ${BACKEND_URL}"
# --reload-dir scopes the file watcher to actual source: without it, uvicorn watches this whole
# repo root recursively -- .venv, node_modules, and every git worktree checked out under it -- which
# can exceed 100k files and has wedged the reload watcher outright during unrelated git activity
# elsewhere in the tree.
run_in_process_group uv run --project backend python -m openbot.cli "$DETAILS_FLAG" --reload --reload-dir backend/openbot --reload-dir tools --port "$ELECTRON_BACKEND_PORT" &
run_in_process_group uv run --project backend python -m openbot.cli "$DETAILS_FLAG" --port "$ELECTRON_BACKEND_PORT" &
backend_pid=$!

echo "Starting Vite frontend on ${FRONTEND_URL}"
run_in_process_group env FRONTEND_PORT="$FRONTEND_PORT" VITE_BACKEND_PORT="$ELECTRON_BACKEND_PORT" bash -c '
run_in_process_group env FRONTEND_PORT="$FRONTEND_PORT" VITE_BACKEND_PORT="$ELECTRON_BACKEND_PORT" ELECTRON_DEV="1" bash -c '
cd frontend
pnpm dev --host localhost --port "$FRONTEND_PORT"
' &
Expand Down
Loading