waybetter/packages/shell/src/frame/boot.ts
CRT 60faed66be shell: the shell frame, createShell(site) (moved from wayBetter for X)
packages/shell/src/frame (waybetter/shell/frame): the whole shell of an app. An app describes its
site (ShellSite: names and pages, account rules, search, address chips and completions, its panel
tab, the new-tab page, palette items, deck column kinds and flags and an optional compose dock, the
media panel's composer rule, a theme store, overlays, the native features it serves) and passes
its Tauri API and i18n instance; createShell returns the root component.

- Shell.tsx: dockview host (tabs in the titlebar row, splits, drag-link drops, shortcuts, context
  menu, deck back-and-forth, session restore, workspace on start, overlay raise); state.ts (pane
  placeholders, tabs_sync one-in-flight via syncGate, shell_raise layer, profiles, layout).
- WebPanel (address bar), NewTabPage, CommandPalette + paletteModel (frame groups; site items),
  DeckView + AddColumnDialog + deckStore (site column kinds), PaneTheme + themeStore
  (createThemeStore over the app's ThemeAdapter) + chromeTheme (ChromeTheme input) + themeScopes,
  Titlebar + TitlebarExtras + icons + brand (wB mark data URI), AccountSwitcher + accountModel,
  workspaces + workspaceModel, backupModel, syncHost, devHost + devModel, pluginCommandStore,
  MediaPanel + mediaModel, searchInput, hooks, bridge (installPreviewMocks), i18n, boot.ts
  (bootScript: the first-frame boot.js), CSS themed with --wb-* tokens.
- paneModel: paneVisibility, raiseSupported, cssRgb; deckModel: isSourcePage.
- Includes the live-QA titlebar fix (dock ResizeObserver + rAF titlebar marks, dock sized by its
  insets).
- tests/frame.test.ts: every frame key has English and is used, palette order with a site,
  address fallback, layout gate, boot script, chrome variables, switcher rules, workspaces,
  deck settings with site flags.
- npm package 0.4.0: exports ./shell/frame, ./shell/frame/*, ./shell/frame/*.css (copied by the
  build); dockview and acorn optional peers; root devDependencies dockview, acorn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 12:47:10 +07:00

37 lines
2.1 KiB
TypeScript

// The first-frame script (`boot.js`, a classic script in the shell page's <head>): 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. */ }
})();
`;
}