Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(rail): apply the worn theme to the server switcher rail
Nekylle6ca7375530e
diff --git a/src/components/ChromeRail.skin.test.ts b/src/components/ChromeRail.skin.test.tsnew file mode 100644index 0000000000..17aabb7117--- /dev/null+++ b/src/components/ChromeRail.skin.test.ts@@ -0,0 +1,64 @@+// @vitest-environment happy-dom+import { act, createElement } from "react";+import { createRoot } from "react-dom/client";+import { afterEach, beforeEach, expect, it, vi } from "vitest";++const wearSkin = vi.fn();+const loadTheme = vi.fn(async () => {});+let worn: unknown = null;++vi.mock("@/lib/theme/runtime", () => ({ loadTheme, wornTheme: () => worn }));+vi.mock("@/lib/skins", () => ({ wearSkin }));+vi.mock("@/lib/language-preference", () => ({+ effectiveLanguage: (choice: string) => choice,+ useLanguageChoice: () => "en",+ usePageLanguage: () => {},+}));+vi.mock("./AccountMenu", () => ({ AccountsSheet: () => null, useAccountsSheet: () => ({ open: false, close: () => {} }) }));+vi.mock("./DesktopCapabilities", () => ({ DesktopCapabilitiesProvider: () => null }));+vi.mock("./PlacesRail", () => ({ PlacesRail: () => null }));++const { ChromeRail } = await import("./ChromeRail");++let onSkin: ((skin: string) => void) | null = null;++async function render(): Promise<() => void> {+ const host = document.createElement("div");+ document.body.append(host);+ const root = createRoot(host);+ await act(async () => { root.render(createElement(ChromeRail)); });+ return () => { root.unmount(); host.remove(); };+}++async function rail(): Promise<(skin: string) => void> {+ const done = await render();+ if (!onSkin) {+ done();+ throw new Error("the rail never asked for the skin of the page beside it");+ }+ return onSkin;+}++beforeEach(() => {+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;+ vi.clearAllMocks();+ worn = null;+ onSkin = null;+ (window as { ogb?: unknown }).ogb = { rail: { onSkin: (cb: (skin: string) => void) => { onSkin = cb; } } };+});++afterEach(() => { delete (window as { ogb?: unknown }).ogb; document.body.innerHTML = ""; });++it("wears the skin of the page beside it while no theme is worn", async () => {+ const told = await rail();+ await act(async () => { told("daylight"); });+ expect(wearSkin).toHaveBeenCalledWith("daylight");+});++it("keeps the theme's own skin when a theme is worn", async () => {+ worn = { id: "neon", theme: { name: "Neon" } };+ const told = await rail();+ await act(async () => { told("daylight"); });+ expect(loadTheme).toHaveBeenCalledTimes(1);+ expect(wearSkin).not.toHaveBeenCalled();+});diff --git a/src/components/ChromeRail.tsx b/src/components/ChromeRail.tsxindex 2d89d5f54d..a555859f10 100644--- a/src/components/ChromeRail.tsx+++ b/src/components/ChromeRail.tsx@@ -1,5 +1,6 @@import { useEffect } from "react";import { effectiveLanguage, useLanguageChoice, usePageLanguage } from "@/lib/language-preference";+import { loadTheme, wornTheme } from "@/lib/theme/runtime";import { wearSkin } from "@/lib/skins";import { AccountsSheet, useAccountsSheet } from "./AccountMenu";import { DesktopCapabilitiesProvider } from "./DesktopCapabilities";@@ -10,8 +11,11 @@ import { PlacesRail } from "./PlacesRail";* while open (main widens the view for them). */export function ChromeRail() {usePageLanguage(effectiveLanguage(useLanguageChoice(), undefined));- // The page beside the rail chose its skin: the rail wears the same one.- useEffect(() => window.ogb?.rail?.onSkin?.(wearSkin), []);+ // The page beside the rail chose its skin. A worn theme chooses its own skin, so ask the server what is worn now+ // rather than painting that page's skin over the theme's.+ useEffect(() => window.ogb?.rail?.onSkin?.((skin) => {+ void loadTheme().then(() => { if (!wornTheme()) wearSkin(skin); });+ }), []);const accounts = useAccountsSheet();return <DesktopCapabilitiesProvider><div data-chrome-rail className="h-full"><PlacesRail chrome /></div>{accounts.open && <AccountsSheet onClose={accounts.close} />}</DesktopCapabilitiesProvider>;}diff --git a/src/rail.theme.test.ts b/src/rail.theme.test.tsnew file mode 100644index 0000000000..8262ca1164--- /dev/null+++ b/src/rail.theme.test.ts@@ -0,0 +1,29 @@+// @vitest-environment happy-dom+import { afterEach, expect, it, vi } from "vitest";++const startTheme = vi.fn();+const loadTheme = vi.fn(async () => {});++// The window's own rail is a page of its own, beside the one main gives `theme` frames to.+vi.mock("./lib/theme/runtime", () => ({ loadTheme, startTheme }));+vi.mock("./lib/skins", () => ({ applySkinChoice: vi.fn(), readSkinChoice: () => "midnight" }));+vi.mock("./lib/fonts", () => ({ applyFont: vi.fn(), readFont: () => null }));+vi.mock("./lib/new-look", () => ({ settleInterfaceMode: vi.fn() }));+vi.mock("./lib/language-preference", () => ({ loadPageLanguage: vi.fn(async () => {}) }));+vi.mock("./lib/brand", () => ({ bootstrapBrand: vi.fn(async () => {}) }));+vi.mock("./components/ChromeRail", () => ({ ChromeRail: () => null }));+vi.mock("./components/PageBoundary", () => ({ PageBoundary: () => null }));+vi.mock("react-dom/client", () => ({ createRoot: () => ({ render: vi.fn() }) }));++afterEach(() => {+ delete (window as { ogb?: unknown }).ogb;+ document.body.innerHTML = "";+});++it("asks for the person's theme before it renders, so the theme reaches the window's own rail", async () => {+ (window as { ogb?: unknown }).ogb = { rail: { expand: true } };+ document.body.innerHTML = '<div id="root"></div>';+ await import("./rail");+ expect(startTheme, "the remembered theme is painted before first paint, as in every other window").toHaveBeenCalledTimes(1);+ expect(loadTheme, "the rail asks the server for the worn theme, which main's frames never reach").toHaveBeenCalledTimes(1);+});diff --git a/src/rail.tsx b/src/rail.tsxindex 27a66bac73..82cfbde03d 100644--- a/src/rail.tsx+++ b/src/rail.tsx@@ -7,16 +7,20 @@ import { applyFont, readFont } from "./lib/fonts";import { settleInterfaceMode } from "./lib/new-look";import { loadPageLanguage } from "./lib/language-preference";import { applySkinChoice, readSkinChoice } from "./lib/skins";+import { loadTheme, startTheme } from "./lib/theme/runtime";import "./styles.css";// The window's own rail of places (electron/chrome-rail.mjs): see-through but for the rail and its open sheets. Only// the desktop's preload gives this app's page a rail; anywhere else this address is the app.if (window.ogb?.rail?.expand) {+ // This page is a window of its own, beside the one main gives `theme` frames to, so it has to ask for the person's+ // theme itself: without that the rail keeps the built-in skin, and none of the theme's colours, font or CSS reach it.settleInterfaceMode();applySkinChoice(readSkinChoice());applyFont(readFont());+ startTheme();document.documentElement.style.background = document.body.style.background = "transparent";- void Promise.all([bootstrapBrand(), loadPageLanguage()]).then(() => {+ void Promise.all([bootstrapBrand(), loadPageLanguage(), loadTheme()]).then(() => {createRoot(document.getElementById("root")!).render(<StrictMode><PageBoundary><ChromeRail /></PageBoundary></StrictMode>);});} else {