Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(theme): let Light or dark choice pick the mode for themes with both blocks
AdityaUmale4494a5e3ee9e
diff --git a/shared/theme.ts b/shared/theme.tsindex 0e6fb209d5..cd2c4668a3 100644--- a/shared/theme.ts+++ b/shared/theme.ts@@ -251,7 +251,7 @@ export function themeGuide(): string {"A theme restyles MausBot's desktop app and web app for the person who asked, in every window they have open. Phones keep their own look.","","Colours first. `canvas` (hex) is the base background and `accent` (hex) the highlight; the app derives its surfaces, lines and text from them.",- "`skin` picks the built-in skin underneath, so anything the theme leaves out comes from it. `colors` sets single roles; `light` and `dark` hold canvas, accent and colors used only in that mode.",+ "`skin` picks the built-in skin underneath, so anything the theme leaves out comes from it. `colors` sets single roles; `light` and `dark` hold canvas, accent and colors used only in that mode. With both `light` and `dark`, and `skin` left out or set to \"system\", \"daylight\" or \"midnight\", the person's Light or dark choice in Settings picks the mode; otherwise `skin` or a top-level `canvas` fixes it.",`Roles: ${THEME_COLOR_ROLES.map((role) => `${role} (${THEME_ROLE_HELP[role]})`).join("; ")}.`,"`font` is a font-family list. Bundled: \"Geist Variable\", \"Inter Variable\", \"Geist Mono Variable\". A font installed on the computer works by name, and a font file can be a theme file loaded with @font-face.","",diff --git a/src/lib/theme/runtime.dom.test.ts b/src/lib/theme/runtime.dom.test.tsnew file mode 100644index 0000000000..0ea84d8d08--- /dev/null+++ b/src/lib/theme/runtime.dom.test.ts@@ -0,0 +1,44 @@+// @vitest-environment happy-dom+import { afterEach, beforeEach, expect, it, vi } from "vitest";++import type { ThemeFile } from "../../../shared/theme";++const values = new Map<string, string>();++beforeEach(() => {+ values.clear();+ vi.stubGlobal("localStorage", {+ getItem: (key: string) => values.get(key) ?? null,+ setItem: (key: string, value: string) => { values.set(key, value); },+ removeItem: (key: string) => { values.delete(key); },+ });+ vi.stubGlobal("matchMedia", () => ({ matches: false, addEventListener: () => {}, removeEventListener: () => {} }));+ vi.resetModules();+});++afterEach(() => {+ vi.unstubAllGlobals();+ delete document.documentElement.dataset.skin;+});++async function wear(theme: ThemeFile, skinChoice: string) {+ values.set("omb-skin", skinChoice);+ const runtime = await import("./runtime");+ runtime.wearTheme({ id: "repro", theme });+ return document.documentElement.dataset.skin;+}++const bothModes = { light: { canvas: "#ffffff", accent: "#d97757" }, dark: { canvas: "#121212", accent: "#d97757" } };++it("follows the person's Light or dark choice when the theme has both a light and a dark block", async () => {+ expect(await wear({ name: "Repro", skin: "system", ...bothModes }, "midnight")).toBe("midnight");+ expect(await wear({ name: "Repro", skin: "midnight", ...bothModes }, "daylight")).toBe("daylight");+ expect(await wear({ name: "Repro", canvas: "#121212", ...bothModes }, "daylight")).toBe("daylight");+});++it("still wears the theme's own skin when it has no block for the other mode", async () => {+ expect(await wear({ name: "Night", skin: "midnight", dark: bothModes.dark }, "daylight")).toBe("midnight");+ expect(await wear({ name: "Night", canvas: "#121212" }, "daylight")).toBe("midnight");+ expect(await wear({ name: "Plain", accent: "#d97757" }, "midnight")).toBe("midnight");+ expect(await wear({ name: "Spooky", skin: "halloween", ...bothModes }, "daylight")).toBe("halloween");+});diff --git a/src/lib/theme/runtime.ts b/src/lib/theme/runtime.tsindex 109d19434c..c1ce9b0d3e 100644--- a/src/lib/theme/runtime.ts+++ b/src/lib/theme/runtime.ts@@ -63,7 +63,9 @@ function paint(): void {wearSkin(readSkin());return;}- const base: SkinChoice | undefined = theme.skin ?? (theme.canvas ? THEME_SKINS[modeOf(theme.canvas)] : undefined);+ const plainSkin = !theme.skin || theme.skin === "system" || theme.skin === THEME_SKINS.light || theme.skin === THEME_SKINS.dark;+ const followsChoice = Boolean(theme.light && theme.dark) && plainSkin;+ const base: SkinChoice | undefined = followsChoice ? undefined : theme.skin ?? (theme.canvas ? THEME_SKINS[modeOf(theme.canvas)] : undefined);wearSkin(base ? resolveSkin(base) : readSkin());const mode = readColorScheme(root);const variant = theme[mode];