import { motion, AnimatePresence, useReducedMotion } from "framer-motion"; import { useState, useEffect, useCallback, useRef } from "react"; import waggleLogoDark from "@/assets/waggle-logo.jpeg"; import waggleLogoLight from "@/assets/waggle-logo.png"; import { useIsLightTheme } from "@/hooks/useIsLightTheme"; import { DUR, EASE_OUT } from "@/lib/motion/tokens"; const PHASES = [ "Initializing core systems…", "Loading agent kernel…", "Connecting to hive network…", "Mounting workspaces…", "Ready.", ]; const PHASE_DURATION = 400; // Wave U Lane D (item 1): perceptual boot floor. The boot screen shows for at // least this long — enough for the brand moment — then exits the instant the // shell's data dependencies are ready (`ready` prop). Replaces the old fixed // ~2.3s choreography floor that made returning users sit through dead air. const MIN_BRAND_MS = 850; // Lane H item 5: with cache-first paint there is real content waiting behind the // boot screen for a WARM session, so the brand moment drops to a ≤500ms flash — // no reason to dwell over content that's already there. COLD / day-0 keeps the // full 850ms floor (nothing to paint, so the brand moment earns its beat). const WARM_BRAND_MS = 500; const SKIP_HINT_DELAY = 1000; const BootScreen = ({ onComplete, ready = true, warm = false }: { onComplete: () => void; ready?: boolean; warm?: boolean }) => { const floorMs = warm ? WARM_BRAND_MS : MIN_BRAND_MS; const [phase, setPhase] = useState(0); const [floorElapsed, setFloorElapsed] = useState(false); const [showSkipHint, setShowSkipHint] = useState(false); const completedRef = useRef(false); const reduceMotion = useReducedMotion(); // Logo asset varies by theme: jpeg (solid dark backing, honey W) reads well // on the hive-950 dark background; png (transparent, black "WAGGLE" text) // reads well on the cream light background. const isLight = useIsLightTheme(); const waggleLogo = isLight ? waggleLogoLight : waggleLogoDark; // Fire onComplete at most once — the floor+ready path and the manual skip // (click / any key) both race to exit; whichever wins, the other is a no-op. const finish = useCallback(() => { if (completedRef.current) return; completedRef.current = true; onComplete(); }, [onComplete]); const handleSkip = useCallback(() => { finish(); }, [finish]); // Perceptual floor: hold the boot screen for at least floorMs (WARM_BRAND_MS // for a cache-first warm session, MIN_BRAND_MS cold) so the brand moment lands, // no matter how fast deps resolve. useEffect(() => { const t = setTimeout(() => setFloorElapsed(true), floorMs); return () => clearTimeout(t); }, [floorMs]); // Exit once the floor has elapsed AND the shell's deps are ready. While deps // are genuinely unresolved (ready=false) the boot holds past the floor — the // phase choreography below settles on "Ready." and waits (item 1). useEffect(() => { if (floorElapsed && ready) finish(); }, [floorElapsed, ready, finish]); // Visual phase choreography — advances on its own cadence, decoupled from the // exit trigger so shortening the floor never truncates it mid-transition. useEffect(() => { if (phase < PHASES.length - 1) { const t = setTimeout(() => setPhase(p => p + 1), PHASE_DURATION); return () => clearTimeout(t); } }, [phase]); useEffect(() => { const handleKeyDown = () => handleSkip(); window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, [handleSkip]); useEffect(() => { const t = setTimeout(() => setShowSkipHint(true), SKIP_HINT_DELAY); return () => clearTimeout(t); }, []); const progress = ((phase + 1) / PHASES.length) * 100; return ( {/* Subtle radial glow */}
{/* Logo */} Waggle AI {/* Title */} Waggle AI Autonomous Agent OS {/* Progress bar */} {/* Phase text */}
{PHASES[phase]}
{/* Phase dots */}
{PHASES.map((_, i) => ( ))}
{/* Skip hint */} {showSkipHint && ( Click or press any key to skip )}
); }; export default BootScreen;