diff --git a/BUILDING-WINDOWS.md b/BUILDING-WINDOWS.md index 0224ce6..549898a 100644 --- a/BUILDING-WINDOWS.md +++ b/BUILDING-WINDOWS.md @@ -33,6 +33,18 @@ npm install cd .. ``` +## Develop (no build) + +```powershell +.\dev.ps1 # backend on :8000 + Vite on :5173, both reloading; Ctrl-C stops both +``` + +Then open in a browser. This is `dev.sh` for Windows. +It runs the Python source, not the frozen sidecar, so it cannot show +desktop-shell behaviour (startup screen, quit prompt, WebView2). For that, use +`npx tauri dev` in `frontend` — but note it still spawns the FROZEN sidecar from +`src-tauri\binaries\`, so backend changes need `build_sidecar.ps1` first. + ## Build ```powershell diff --git a/CLAUDE.md b/CLAUDE.md index ecf43f8..c79cfea 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1098,6 +1098,7 @@ Two independent apps that talk over HTTP: ```bash ./dev.sh # start both servers (see README for one-time setup) +.\dev.ps1 # the same on Windows (BUILDING-WINDOWS.md) # Backend cd backend && source .venv/bin/activate diff --git a/backend/build_sidecar.ps1 b/backend/build_sidecar.ps1 index c5196ec..7cf8282 100644 --- a/backend/build_sidecar.ps1 +++ b/backend/build_sidecar.ps1 @@ -16,7 +16,12 @@ Set-Location $Root $Py = Join-Path $Root ".venv\Scripts\python.exe" if (-not (Test-Path $Py)) { $Py = "python" } -& $Py -m PyInstaller --noconfirm --clean konduktor-sidecar.spec +# PyInstaller logs to stderr. Windows PowerShell 5.1 (unlike pwsh 7) turns a +# native command's stderr into an error record, which "Stop" makes fatal on the +# first INFO line — so relax it for this call and judge by the exit code. +$ErrorActionPreference = "Continue" +& $Py -m PyInstaller --noconfirm --clean konduktor-sidecar.spec 2>&1 | ForEach-Object { "$_" } +$ErrorActionPreference = "Stop" if ($LASTEXITCODE -ne 0) { throw "PyInstaller failed ($LASTEXITCODE)" } Write-Host "Built: $Root\dist\konduktor-sidecar\" diff --git a/backend/konduktor/main.py b/backend/konduktor/main.py index 199b0ec..a62c56b 100644 --- a/backend/konduktor/main.py +++ b/backend/konduktor/main.py @@ -120,8 +120,12 @@ app.add_middleware( "http://localhost:5173", "http://127.0.0.1:5173", # Packaged desktop app: the webview's origin when Tauri loads the built - # frontend (macOS uses tauri://, Windows/Linux use https://tauri.localhost). + # frontend. macOS uses tauri://; Windows/Linux default to + # https://tauri.localhost, but lib.rs forces the http scheme + # (use_https_scheme(false)) so the sidecar is not mixed content — + # without the http origin here, the Windows app reaches no API at all. "tauri://localhost", + "http://tauri.localhost", "https://tauri.localhost", ], allow_methods=["*"], diff --git a/dev.ps1 b/dev.ps1 new file mode 100644 index 0000000..eaee385 --- /dev/null +++ b/dev.ps1 @@ -0,0 +1,42 @@ +# Start both Konduktor servers (backend + frontend) together - the Windows +# counterpart of dev.sh. Ctrl-C stops both. First run? See one-time setup in +# BUILDING-WINDOWS.md (the backend venv and `npm install`). +# +# .\dev.ps1 +# (if scripts are blocked: powershell -ExecutionPolicy Bypass -File .\dev.ps1) +$ErrorActionPreference = "Stop" +$Root = $PSScriptRoot + +$Py = Join-Path $Root "backend\.venv\Scripts\python.exe" +if (-not (Test-Path $Py)) { throw "No backend venv at backend\.venv - see BUILDING-WINDOWS.md for setup." } +# Vite through node, not `npm run dev`: npm is a .cmd batch file, and Ctrl-C in a +# shared console makes cmd ask "Terminate batch job (Y/N)?" instead of exiting. +$Vite = Join-Path $Root "frontend\node_modules\vite\bin\vite.js" +if (-not (Test-Path $Vite)) { throw "No frontend\node_modules - run ``npm install`` in frontend first." } + +# Backend (FastAPI on :8000) +$Backend = Start-Process -FilePath $Py -NoNewWindow -PassThru ` + -ArgumentList "-m", "uvicorn", "konduktor.main:app", "--reload", "--port", "8000", "--app-dir", "`"$Root\backend`"" + +# Frontend (Vite on :5173, proxies /api -> :8000) +$Frontend = Start-Process -FilePath "node" -NoNewWindow -PassThru ` + -WorkingDirectory (Join-Path $Root "frontend") -ArgumentList "`"$Vite`"" + +Write-Host "" +Write-Host " Konduktor is starting..." +Write-Host " -> App: http://localhost:5173" +Write-Host " -> API docs: http://localhost:8000/docs" +Write-Host " (Ctrl-C to stop both)" +Write-Host "" + +try { + # If either one dies, stop the other rather than leave half a dev setup. + while (-not $Backend.HasExited -and -not $Frontend.HasExited) { Start-Sleep -Milliseconds 500 } +} +finally { + # Kill the whole tree: uvicorn --reload runs the server in a child process, + # which would otherwise keep :8000 bound after the reloader has gone. + foreach ($p in $Backend, $Frontend) { + if ($p -and -not $p.HasExited) { & taskkill /PID $p.Id /T /F 2>&1 | Out-Null } + } +}