Extract the wayBetter framework core from wayBetter for X

Site-agnostic parts of the X app, behind a small site adapter:

- crates/waybetter-host: webview-label security policy and tab rect
  clamp, account profiles with native-owned accounts (AccountRules),
  plugin store with bundled-plugin upgrades (PluginHost), signed
  data-only hotfix channel, update scheduling and crash handshake, tab
  payloads/link routing/tab-chrome validation, and (feature "tauri")
  webview helpers and the Windows system menu.
- packages/runtime: DOM hub, request hub, plugin API core, OKLab theme
  color model, split-view rail hiding, link routing and account
  reporting, each configured by a SiteAdapter.
- packages/shell: address bar, pane, link-drop, profile, palette and
  update-chip models, and window controls with the Tauri API injected.

Tests moved/adapted from the app: 45 Rust (headless), 40 TypeScript.
This commit is contained in:
CRTkafa 2026-09-28 03:01:33 +07:00
commit 43a9e2e1a7
48 changed files with 9768 additions and 0 deletions

View file

@ -0,0 +1,50 @@
// The page side of a site adapter. A wayBetter app for one site is mostly this object (plus the
// native `SiteSpec` in Rust and its Tauri capability files); every runtime module takes its piece.
import { configureDomHub } from './domHub.ts';
import { configureNetHub } from './netHub.ts';
import type { AccountSite } from './accountReport.ts';
import type { LinkSite } from './linkRouting.ts';
import type { RailSite } from './paneNav.ts';
import type { PluginApiSite } from './pluginApi.ts';
import type { SourceAxis } from './themeTokens.ts';
export type SiteAdapter = {
/** e.g. "wayBetter for X"; console prefixes and toasts. */
product: string;
/** Exact hosts of the site's origin (must match the native `SiteSpec.hosts`). */
hosts: readonly string[];
/** The runtime's window global (`window.<runtimeGlobal>`), plugins included. */
runtimeGlobal: string;
/** Pages where heavy-page-sensitive DOM features pause (e.g. a WASM chat); null = none. */
heavyPath: RegExp | null;
/** Request URL substrings that are the site's API calls; only these reach the net hub stages. */
apiMarks: string[];
/** Extra URL substrings that reach XHR gates only. */
xhrMarks: string[];
plugins: PluginApiSite;
/** Split-view rail hiding; omit when the site has no navigation rail. */
rail?: RailSite;
/** Signed-in account reader for the account switcher. */
account?: AccountSite;
/** Which in-page clicks the "links to site pages" setting may divert. */
links?: LinkSite;
/** The site's own palette per color mode, the source the theme engine maps from. */
themeSources?: Record<string, SourceAxis>;
};
/** Applies the adapter's global knobs (DOM hub, net hub). Call once, before features start. */
export function configureRuntime(site: SiteAdapter): void {
configureDomHub({ label: site.product, heavyPath: site.heavyPath });
configureNetHub({ apiMarks: site.apiMarks, xhrMarks: site.xhrMarks });
}
/** Whether `href` is on the site's origin (https, one of `hosts`). */
export function isSiteUrl(site: Pick<SiteAdapter, 'hosts'>, href: string): boolean {
try {
const url = new URL(href);
return url.protocol === 'https:' && site.hosts.includes(url.hostname) && !url.username && !url.password;
} catch {
return false;
}
}