Repository navigation
Description
Context
Today when `fastled` is run on a sketch, the user waits at the terminal while compilation streams out, and only then does the browser/Tauri viewer open onto the finished artifacts. Streaming compile output to the browser is already wired (#49 / #43), as is the Rust HTTP server (#45) and the SSE-based build broadcast (`crates/fastled-cli/src/compile_stream.rs` — `send_sse`, `emit_build_log`, `emit_build_result_logs`, `write_build_status`). The viewer launch happens after compilation is far enough along to have HTML to render, so the streamed output never reaches a user who doesn't already have the page open.
The current launch site is `commands.rs::compile_and_serve` / `commands.rs::serve_directory` (`launch_viewer: bool`), and `viewer.rs` spawns the Tauri viewer pointed at the served frontend dir.
Proposal
"Instant launch" — when `fastled` starts:
- Start the HTTP server immediately at a known port (already happens) and open the Tauri viewer / browser on it before the first compile begins.
- The initial page is a live build view: streams stdout/stderr from the compile via the existing SSE channel, shows current status (queued / compiling / linking / packaging), and shows any errors with the same coloring as the terminal.
- When the HTML artifacts are ready (build status flips to success and `index.html` is available at the served path), the viewer automatically transitions to the sketch view and starts the sketch like a normal launch today.
- If the compile fails, the viewer stays on the build-output view showing the full streamed log and the error — it does not switch, does not crash, and does not auto-close. The next successful incremental rebuild can then transition it forward.
- On every subsequent watcher-triggered rebuild, the same flow applies: if the rebuild succeeds the sketch reloads as today; if it fails the viewer drops back to the build view with the failing log.
This collapses the "wait at terminal → switch to browser" handoff into a single visual flow and gives non-terminal users feedback during the slowest part of the first run (cold cache).
Acceptance criteria
- On `fastled `, the viewer window opens within ~1s of process start (before `emcc` has produced any HTML).
- The initial viewer page subscribes to the existing SSE build stream and renders log lines as they arrive, in compile order.
- The initial page shows a compact status header (current phase + elapsed time).
- When `/build/status` reports success and `index.html` is present at the served root, the viewer transitions to the sketch view without manual reload.
- When the build reports failure, the viewer remains on the build view; the failing error is visible at the top; the page does not navigate to a 404 or to a stale prior sketch.
- On a subsequent rebuild after a failed build: a successful rebuild transitions to the sketch view; a second failure replaces the prior log with the new failing log.
- Behavior is on by default; existing `--just-compile` and `--serve-dir` paths are unaffected.
- At least one Rust test covers the "build fails → stays on build view" branch via the SSE / build-status surface; manual smoke covers the visual transition.
Decisions
- Default vs. flag: on by default. Reason: the streaming-to-browser infra already exists from feat: stream compilation output to browser in real time #49/feat: stream live compilation output to Tauri viewer #43 and the legacy "wait at terminal" UX is strictly worse for cold-cache first runs. Triage can re-route to a flag if there's a use case for the old behavior (e.g. `--no-instant-launch`).
- Scope: viewer launch site: change at `crates/fastled-cli/src/commands.rs::compile_and_serve` — start server + spawn viewer before `run_native_compile_streaming` rather than after. `serve_directory` (which already launches the viewer up-front for a pre-built dir) is the reference flow.
- Initial-page implementation: serve a small Rust-hosted "build console" page at `/` (or `/build`) that subscribes to the existing SSE endpoint; transition is a client-side redirect to `/index.html` once `build/status` flips. Avoids touching the frontend bundle until the artifacts are in place.
- Failure UX: "stay on build view" is explicit per the user; do not treat compile failure as a fatal viewer error. Process should remain alive on the watcher loop.
- Priority: P2 — UX improvement, not blocking work. Bump if it's needed for a demo/release.
- Fix location guess: `crates/fastled-cli/src/{commands.rs, compile_stream.rs, server.rs, viewer.rs}` + a tiny HTML template in `src/fastled/frontend/` or co-located near `server.rs`. Triage may re-route.
Related issues
- feat: stream compilation output to browser in real time #49 (closed) — `feat: stream compilation output to browser in real time` (this builds on the SSE channel it added).
- feat: stream live compilation output to Tauri viewer #43 (closed) — `feat: stream live compilation output to Tauri viewer` (this re-uses that viewer-side stream).
- feat: replace Flask with Rust HTTP server in fastled-cli #45 (closed) — `feat: replace Flask with Rust HTTP server in fastled-cli` (server side).
Activity