mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-05 14:51:40 +00:00
* refactor(matrix): retire pre-2026.4 legacy crypto and flat-storage migrations * refactor(cli): drop pre-tsdown daemon-cli dist compat shim from the build * refactor(diffs): remove deprecated image*/format tool params and output aliases * refactor(ui): drop pre-gateway-scoped localStorage readers and legacy theme map * refactor: remove assorted pre-2026.4 compat shims and deprecated aliases * fix(discord): map legacy thread-binding fields in the doctor JSON import * fix(msteams): keep bot read fallback for legacy imported conversation rows * test(msteams): cover legacy bot-only imported conversation references * fix(ui): keep channel-prefixed session key display fallback * chore: refresh native i18n inventory and build-docker step count * chore(matrix): drop now-unused migration-config module * chore: re-pin plugin SDK public export budget after compat removals * chore: refresh native i18n inventory after rebase * chore: re-pin plugin SDK callable budget and refresh i18n inventory after rebase
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
// Control UI module implements theme behavior.
|
|
export type ThemeName = "claw" | "knot" | "dash" | "custom";
|
|
export type ThemeMode = "system" | "light" | "dark";
|
|
export type ResolvedTheme =
|
|
| "dark"
|
|
| "light"
|
|
| "openknot"
|
|
| "openknot-light"
|
|
| "dash"
|
|
| "dash-light"
|
|
| "custom"
|
|
| "custom-light";
|
|
|
|
const VALID_THEME_NAMES = new Set<ThemeName>(["claw", "knot", "dash", "custom"]);
|
|
const VALID_THEME_MODES = new Set<ThemeMode>(["system", "light", "dark"]);
|
|
|
|
function prefersLightScheme(): boolean {
|
|
if (typeof globalThis.matchMedia !== "function") {
|
|
return false;
|
|
}
|
|
return globalThis.matchMedia("(prefers-color-scheme: light)").matches;
|
|
}
|
|
|
|
export function parseThemeSelection(
|
|
themeRaw: unknown,
|
|
modeRaw: unknown,
|
|
): { theme: ThemeName; mode: ThemeMode } {
|
|
const theme = typeof themeRaw === "string" ? themeRaw : "";
|
|
const mode = typeof modeRaw === "string" ? modeRaw : "";
|
|
|
|
const normalizedTheme = VALID_THEME_NAMES.has(theme as ThemeName) ? (theme as ThemeName) : "claw";
|
|
const normalizedMode = VALID_THEME_MODES.has(mode as ThemeMode) ? (mode as ThemeMode) : "system";
|
|
|
|
return { theme: normalizedTheme, mode: normalizedMode };
|
|
}
|
|
|
|
function resolveMode(mode: ThemeMode): "light" | "dark" {
|
|
if (mode === "system") {
|
|
return prefersLightScheme() ? "light" : "dark";
|
|
}
|
|
return mode;
|
|
}
|
|
|
|
export function resolveTheme(theme: ThemeName, mode: ThemeMode): ResolvedTheme {
|
|
const resolvedMode = resolveMode(mode);
|
|
if (theme === "claw") {
|
|
return resolvedMode === "light" ? "light" : "dark";
|
|
}
|
|
if (theme === "knot") {
|
|
return resolvedMode === "light" ? "openknot-light" : "openknot";
|
|
}
|
|
if (theme === "dash") {
|
|
return resolvedMode === "light" ? "dash-light" : "dash";
|
|
}
|
|
return resolvedMode === "light" ? "custom-light" : "custom";
|
|
}
|