Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(shell): recognize decoded startup video before frame timeout
Linuxdazhao9192883746fa
diff --git a/apps/desktop/src/components/StartupAnimation.tsx b/apps/desktop/src/components/StartupAnimation.tsxindex 012d6c92a..d5ee984f5 100644--- a/apps/desktop/src/components/StartupAnimation.tsx+++ b/apps/desktop/src/components/StartupAnimation.tsx@@ -1,3 +1,4 @@+import type { RefObject } from "react";import { useTranslation } from "react-i18next";import { STARTUP_ANIMATION_URL } from "@pi-desktop/shared";import type { StartupAnimationEndReason } from "../lib/startup-animation";@@ -18,12 +19,14 @@ import { cx } from "./ui";*/export function StartupAnimation({playing,+ videoRef,revealing,holdingLong,onFirstFrame,onAnimationEnd,}: {playing: boolean;+ videoRef?: RefObject<HTMLVideoElement | null>;revealing: boolean;holdingLong: boolean;onFirstFrame: () => void;@@ -41,6 +44,7 @@ export function StartupAnimation({>{playing ? (<video+ ref={videoRef}className="startup-animation-video"src={STARTUP_ANIMATION_URL}autoPlay@@ -52,6 +56,7 @@ export function StartupAnimation({tabIndex={-1}aria-hiddenonLoadedData={onFirstFrame}+ onPlaying={onFirstFrame}onEnded={() => onAnimationEnd("ended")}onError={() => onAnimationEnd("error")}/>diff --git a/apps/desktop/src/features/app/useAppShellRuntime.tsx b/apps/desktop/src/features/app/useAppShellRuntime.tsxindex 236fc447d..362a792c9 100644--- a/apps/desktop/src/features/app/useAppShellRuntime.tsx+++ b/apps/desktop/src/features/app/useAppShellRuntime.tsx@@ -1041,6 +1041,7 @@ export function useAppShellRuntime() {? (<StartupAnimationplaying={startupAnimation.playing}+ videoRef={startupAnimation.videoRef}revealing={startupAnimation.phase === "reveal"}holdingLong={startupAnimation.holdingLong}onFirstFrame={startupAnimation.onFirstFrame}diff --git a/apps/desktop/src/features/app/useStartupAnimation.ts b/apps/desktop/src/features/app/useStartupAnimation.tsindex bba54471b..8acd94ca3 100644--- a/apps/desktop/src/features/app/useStartupAnimation.ts+++ b/apps/desktop/src/features/app/useStartupAnimation.ts@@ -1,4 +1,4 @@-import { useCallback, useEffect, useMemo, useRef, useState } from "react";+import { useCallback, useEffect, useMemo, useRef, useState, type RefObject } from "react";import {STARTUP_ANIMATION_FIRST_FRAME_TIMEOUT_MS,STARTUP_ANIMATION_HOLD_HINT_MS,@@ -30,6 +30,7 @@ export type StartupAnimationState = {phase: StartupAnimationPhase;/** True while the `<video>` should be mounted and playing. */playing: boolean;+ videoRef: RefObject<HTMLVideoElement | null>;/** The hold has outlasted its quiet bound; show the progress affordance. */holdingLong: boolean;/** Attach to the element: the first decoded frame cancels its own bound. */@@ -138,6 +139,7 @@ export function useStartupAnimation(ready: boolean): StartupAnimationState {// The first decoded frame retires the only bound that can fire before the// animation is visible at all.+ const videoRef = useRef<HTMLVideoElement>(null);const firstFrameRef = useRef(false);const onFirstFrame = useCallback(() => {firstFrameRef.current = true;@@ -150,7 +152,10 @@ export function useStartupAnimation(ready: boolean): StartupAnimationState {useEffect(() => {if (!active || state.phase !== "video") return;const firstFrame = window.setTimeout(() => {- if (!firstFrameRef.current) onAnimationEnd("no-first-frame");+ // Media events can precede their React handlers; inspect the decoded frame too.+ if (!firstFrameRef.current && (videoRef.current?.readyState ?? 0) < HTMLMediaElement.HAVE_CURRENT_DATA) {+ onAnimationEnd("no-first-frame");+ }}, STARTUP_ANIMATION_FIRST_FRAME_TIMEOUT_MS);const maxDuration = window.setTimeout(() => {onAnimationEnd("max-duration");@@ -207,6 +212,7 @@ export function useStartupAnimation(ready: boolean): StartupAnimationState {active: active && state.phase !== "done",phase: state.phase,playing: active && state.phase === "video",+ videoRef,holdingLong,onFirstFrame,onAnimationEnd,diff --git a/apps/desktop/test/startup-animation.test.mjs b/apps/desktop/test/startup-animation.test.mjsindex 7c5d2abb0..e7646080b 100644--- a/apps/desktop/test/startup-animation.test.mjs+++ b/apps/desktop/test/startup-animation.test.mjs@@ -426,6 +426,9 @@ test("the surface is opaque black and the video is inert and silent", () => {// Muted: an unmuted autoplay is blocked by Chromium and hostile besides.assert.match(surface, /\bmuted\b/);assert.match(surface, /\bplaysInline\b/);+ assert.match(surface, /onPlaying=\{onFirstFrame\}/);+ assert.match(surface, /ref=\{videoRef\}/);+ assert.match(shell, /videoRef=\{startupAnimation.videoRef\}/);assert.match(surface, /controls=\{false\}/);assert.match(surface, /tabIndex=\{-1\}/);assert.match(surface, /data-testid="startup-animation"/);diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex 46e3671e9..82a832603 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -739,6 +739,11 @@ may be retained while exactly one workspace supplies the visible shell context.second rather than after it.- A boot that outlasts the video shows the splash's indeterminate bar after 3sof black, so an opaque mask is not mistaken for a hang.+- Either `loadeddata` or `playing` acknowledges a decoded first frame; a+ playing video must not hit the missing-first-frame timeout when `loadeddata`+ was missed. The first-frame timeout also checks the actual video ref for+ HAVE_CURRENT_DATA in case both initial events raced their handlers. The total+ playback bound remains active.- Four bounds end the animation, and each runs the same reveal: no first framewithin 2s, 15s of total playback, a `<video>` `error`, or `Escape`. Thestartup watchdog's bounds are unchanged and outrank it — at 30s the bootdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 0d7e3406f..e0f4cb22e 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -7086,6 +7086,13 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.- After ready: splash exits with a short fade (or instantly under reduced motion) and the main shell (or settings page) is interactive underneath.- If the initial state never arrives, the splash is replaced rather than held: the boot surface gains logs, diagnostics, and quit at 30s (`STARTUP_SLOW_HINT_MS`) without reporting a failure, and at 180s (`STARTUP_STALLED_MS`) becomes the recovery surface, which also offers a retry (`data-testid="startup-recovery"`); every action works without a backend, the renderer-drawn window controls stay above the surface on Windows/Linux, and quit goes through `pi-desktop/app/quit`.- On macOS the splash uses the same glass tint and sheen as the sidebar over native `sidebar` vibrancy; the mounted shell stays hidden until the splash exit fade, then cross-fades in. Other platforms keep the opaque `--ds-bg-primary` fill.+ - Use a six-second playable fixture with skip-when-ready off. Observe advancing+ playback beyond the two-second first-frame bound and through at least 5.75s+ before reveal. A `playing` event must retire the first-frame timeout even+ if `loadeddata` was missed. The native fixture also suppresses that event+ in a fresh test renderer to exercise this path deterministically; it resets+ only the temporary window’s one-play mark before that test reload. Keep+ corrupt-media recovery coverage.- With a video in `<dataDir>/startup/` (D679): `data-testid="startup-animation"` replaces the splash in the first painted frame, plays over opaque black with no controls and no audio, then holds the same black until bootstrap finishes, then fades out over about a second with the shell already clickable during the fade. A boot slower than the video shows an indeterminate bar after 3s of black. `Escape` jumps straight to that fade.- An unplayable file never holds the launch: the animation ends within 2s (no first frame) or on `error`, and the reveal runs exactly as it does after a clean finish.- The animation is not played under reduced motion, on a renderer reload, or on a window reopened from the tray or Dock; the brand splash is used instead. Settings → General → Appearance names the resolved file, offers the folder, and applies a toggled switch on the next launch only.diff --git a/scripts/e2e-startup-animation.mjs b/scripts/e2e-startup-animation.mjsindex fe89feff8..8b463882c 100644--- a/scripts/e2e-startup-animation.mjs+++ b/scripts/e2e-startup-animation.mjs@@ -44,7 +44,7 @@ function writePlayableVideo(target) {["-v", "error","-f", "lavfi",- "-i", "testsrc=size=640x360:rate=24:duration=1.5",+ "-i", "testsrc=size=640x360:rate=24:duration=6","-c:v", "libvpx-vp9","-b:v", "300k","-an",@@ -72,7 +72,14 @@ function writeUnplayableVideo(target) {const PROBE = `(() => {const surface = document.querySelector('[data-testid="startup-animation"]');const video = surface?.querySelector("video") ?? null;+ if (video && !video.dataset.completionObserved) {+ video.dataset.completionObserved = "true";+ video.addEventListener("ended", () => {+ window.__startupAnimationEnd = { time: video.currentTime, duration: video.duration };+ }, { once: true });+ }return {+ ended: window.__startupAnimationEnd ?? null,surface: !!surface,splash: !!document.querySelector('[data-testid="startup-splash"]'),recovery: !!document.querySelector('[data-testid="startup-recovery"]'),@@ -101,7 +108,7 @@ function waitFor(check, timeoutMs, label) {* Boot the app against a throwaway data directory holding one animation, and* hand `run` a renderer probe. Everything is torn down on either outcome.*/-async function withLaunch(writeFixture, run) {+async function withLaunch(writeFixture, run, { missLoadedData = false } = {}) {const dataDir = createTempDataDir("pi-desktop-startup-animation-");const userDataDir = join(dataDir, "user-data");mkdirSync(userDataDir, { recursive: true });@@ -170,6 +177,17 @@ async function withLaunch(writeFixture, run) {pending.set(id, { resolve, reject, timer });ws.send(JSON.stringify({ id, method, params }));});+ if (missLoadedData) {+ await send("Page.enable");+ await send("Page.addScriptToEvaluateOnNewDocument", {+ // Reset only this temporary window's one-play guard to inject the media event loss.+ source: `sessionStorage.removeItem("pi-desktop.startup-animation.played");+ document.addEventListener("loadeddata", (event) => {+ if (event.target instanceof HTMLVideoElement) event.stopImmediatePropagation();+ }, true);`,+ });+ await send("Page.reload");+ }const probe = async () => {const result = await send("Runtime.evaluate", {expression: PROBE,@@ -191,9 +209,9 @@ async function withLaunch(writeFixture, run) {}}-async function playableScenario() {+async function playableScenario(missLoadedData = false) {await withLaunch(writePlayableVideo, async ({ probe, byteLength }) => {- console.log(`playable fixture: ${byteLength} bytes`);+ console.log(`playable fixture: ${byteLength} bytes (missLoadedData=${missLoadedData})`);// `readyState >= 2` means Chromium has frames for the current position,// which is only true if `pi-startup:` served playable bytes under the CSP.@@ -226,13 +244,25 @@ async function playableScenario() {}, 10_000, "playback to advance");console.log("PASS playback — the stream advances");+ // A short clip can finish before the first-frame timeout and hide a false timeout.+ await waitFor(async () => {+ const state = await probe();+ if (state.ended?.time >= 5.75) return true;+ if (!state.surface || state.revealing || state.currentTime === null) {+ throw new Error(`playable animation ended before its six-second fixture finished: ${JSON.stringify(state)}`);+ }+ if (state.error) throw new Error(`playback error ${state.error}`);+ return state.currentTime >= 5.75;+ }, 15_000, "playback beyond the first-frame timeout and through the full clip");+ console.log("PASS completion — playback reaches the final quarter-second");+await waitFor(async () => {const state = await probe();if (state.recovery) throw new Error("the launch stalled into the recovery surface");return !state.surface && state.shell;}, 30_000, "the animation to reveal the shell");console.log("PASS reveal — the shell owns the window");- });+ }, { missLoadedData });}async function unplayableScenario() {@@ -252,6 +282,7 @@ async function unplayableScenario() {try {await playableScenario();+ await playableScenario(true);await unplayableScenario();} catch (error) {console.error("FAIL startup-animation —", error.message);