// The first-frame script (`boot.js`, a classic script in the shell page's ): the chrome // colors the global theme had last time (themeStore.ts writes them under BOOT_CACHE_KEY), so a light // theme never starts on the dark default while the shell's modules and the persisted theme load. // Shell webview only: other local webviews of the app (e.g. a popover) share the page and paint // their own background. The app serves `bootScript()` as `/boot.js` (see the README: a Vite // plugin or a build step writes it; nothing is copied by hand). /** localStorage key of the last chrome variables (`--wb-*` name → value). */ export const BOOT_CACHE_KEY = 'bt.chrome.vars'; /** The page ground before any theme (Night Ink), as shell.css paints it. */ export const BOOT_GROUND = '#07080c'; /** The boot script's source. `label`: the shell webview's label (waybetter-host `policy::SHELL_LABEL`). */ export function bootScript(options: { label?: string } = {}): string { const label = JSON.stringify(options.label ?? 'shell'); return `// Generated from waybetter/shell/frame/boot (bootScript): runs before the shell's first frame and // paints the chrome colors the global theme had last time (${BOOT_CACHE_KEY}). (() => { try { const label = window.__TAURI_INTERNALS__?.metadata?.currentWebview?.label; if (label !== ${label}) return; const vars = JSON.parse(localStorage.getItem(${JSON.stringify(BOOT_CACHE_KEY)}) || 'null'); if (!vars || typeof vars !== 'object') return; const root = document.documentElement; for (const [name, value] of Object.entries(vars)) { if (/^--wb-[a-z]-[a-z0-9-]+$/.test(name) && typeof value === 'string' && value.length < 400) root.style.setProperty(name, value); } // shell.css (loaded with the shell's modules) paints the same ground; this rule only covers // the frames before it, and \`html.bt-raised\` (more specific) still clears it. const style = document.createElement('style'); style.textContent = 'html{background:var(--wb-c-ground,${BOOT_GROUND})}'; document.head.appendChild(style); } catch { /* No cache yet or blocked storage: the default ground. */ } })(); `; }