Compare commits

...
Author SHA1 Message Date
Cursor AgentandTheo Browne 8a815adc8b Add user theme palette settings
Co-authored-by: Theo Browne <[email protected]>
2026-05-05 20:31:38 +00:00
13 changed files with 441 additions and 41 deletions

No files matched your search

@@ -3,6 +3,7 @@ import * as os from "node:os";
import * as path from "node:path";
import {
DEFAULT_THEME_PALETTE,
EnvironmentId,
type ClientSettings,
type PersistedSavedEnvironmentRecord,
@@ -63,6 +64,7 @@ const clientSettings: ClientSettings = {
sidebarProjectSortOrder: "manual",
sidebarThreadSortOrder: "created_at",
timestampFormat: "24-hour",
themePalette: DEFAULT_THEME_PALETTE,
};
const savedRegistryRecord: PersistedSavedEnvironmentRecord = {
+14
View File
@@ -25,6 +25,20 @@
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
const isDark = theme === "dark" || (theme === "system" && prefersDark);
document.documentElement.classList.toggle("dark", isDark);
const rawSettings = window.localStorage.getItem("t3code:client-settings:v1");
const palette = rawSettings ? JSON.parse(rawSettings).themePalette : null;
if (palette && /^#[0-9a-fA-F]{6}$/.test(palette.primaryColor)) {
document.documentElement.style.setProperty(
"--theme-primary-seed",
palette.primaryColor.toLowerCase(),
);
}
if (palette && /^#[0-9a-fA-F]{6}$/.test(palette.neutralColor)) {
document.documentElement.style.setProperty(
"--theme-neutral-seed",
palette.neutralColor.toLowerCase(),
);
}
const chromeColor = isDark ? DARK_BACKGROUND : LIGHT_BACKGROUND;
document.documentElement.style.backgroundColor = chromeColor;
themeColorMeta?.setAttribute("content", chromeColor);
+46 -1
View File
@@ -1,4 +1,9 @@
import { EnvironmentId, type PersistedSavedEnvironmentRecord } from "@t3tools/contracts";
import {
DEFAULT_CLIENT_SETTINGS,
DEFAULT_THEME_PALETTE,
EnvironmentId,
type PersistedSavedEnvironmentRecord,
} from "@t3tools/contracts";
import { afterEach, describe, expect, it, vi } from "vitest";
const testEnvironmentId = EnvironmentId.make("environment-1");
@@ -55,6 +60,46 @@ afterEach(() => {
});
describe("clientPersistenceStorage", () => {
it("reads the persisted theme palette for boot-time theme application", async () => {
const testWindow = getTestWindow();
const { CLIENT_SETTINGS_STORAGE_KEY, readBootThemePalette } =
await import("./clientPersistenceStorage");
testWindow.localStorage.setItem(
CLIENT_SETTINGS_STORAGE_KEY,
JSON.stringify({
...DEFAULT_CLIENT_SETTINGS,
themePalette: {
primaryColor: "#db2777",
neutralColor: "#0f172a",
},
}),
);
expect(readBootThemePalette()).toEqual({
primaryColor: "#db2777",
neutralColor: "#0f172a",
});
});
it("falls back to the default theme palette when persisted data is invalid", async () => {
const testWindow = getTestWindow();
const { CLIENT_SETTINGS_STORAGE_KEY, readBootThemePalette } =
await import("./clientPersistenceStorage");
testWindow.localStorage.setItem(
CLIENT_SETTINGS_STORAGE_KEY,
JSON.stringify({
themePalette: {
primaryColor: "pink",
neutralColor: "#0f172a",
},
}),
);
expect(readBootThemePalette()).toEqual(DEFAULT_THEME_PALETTE);
});
it("stores browser secrets inline with the saved environment record", async () => {
const testWindow = getTestWindow();
const {
+14
View File
@@ -1,5 +1,6 @@
import {
ClientSettingsSchema,
DEFAULT_THEME_PALETTE,
EnvironmentId,
type ClientSettings,
type EnvironmentId as EnvironmentIdValue,
@@ -12,6 +13,19 @@ import { getLocalStorageItem, setLocalStorageItem } from "./hooks/useLocalStorag
export const CLIENT_SETTINGS_STORAGE_KEY = "t3code:client-settings:v1";
export const SAVED_ENVIRONMENT_REGISTRY_STORAGE_KEY = "t3code:saved-environment-registry:v1";
export function readBootThemePalette(): ClientSettings["themePalette"] {
if (!hasWindow()) {
return DEFAULT_THEME_PALETTE;
}
try {
const parsed = getLocalStorageItem(CLIENT_SETTINGS_STORAGE_KEY, ClientSettingsSchema);
return parsed?.themePalette ?? DEFAULT_THEME_PALETTE;
} catch {
return DEFAULT_THEME_PALETTE;
}
}
const BrowserSavedEnvironmentRecordSchema = Schema.Struct({
environmentId: EnvironmentId,
label: Schema.String,
@@ -1,6 +1,6 @@
import { ArchiveIcon, ArchiveX, LoaderIcon, PlusIcon, RefreshCwIcon } from "lucide-react";
import { useQueryClient } from "@tanstack/react-query";
import { useCallback, useMemo, useRef, useState } from "react";
import { type CSSProperties, useCallback, useMemo, useRef, useState } from "react";
import {
defaultInstanceIdForDriver,
type DesktopUpdateChannel,
@@ -10,7 +10,11 @@ import {
type ScopedThreadRef,
} from "@t3tools/contracts";
import { scopeThreadRef } from "@t3tools/client-runtime";
import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
import {
DEFAULT_THEME_PALETTE,
DEFAULT_UNIFIED_SETTINGS,
type ThemePaletteSettings,
} from "@t3tools/contracts/settings";
import { createModelSelection } from "@t3tools/shared/model";
import { Equal } from "effect";
import { APP_VERSION } from "../../branding";
@@ -40,7 +44,14 @@ import {
deriveProviderInstanceEntries,
sortProviderInstanceEntries,
} from "../../providerInstances";
import {
getThemePaletteCustomProperties,
normalizeThemePaletteColor,
THEME_PALETTE_PREVIEW_SWATCHES,
THEME_PALETTE_SWATCHES,
} from "../../themePalette";
import { ensureLocalApi, readLocalApi } from "../../localApi";
import { cn } from "../../lib/utils";
import { useShallow } from "zustand/react/shallow";
import {
selectProjectsAcrossEnvironments,
@@ -117,6 +128,91 @@ const PROVIDER_SETTINGS = DRIVER_OPTIONS.map((definition) => ({
provider: definition.value,
}));
function ThemePaletteColorControl({
label,
value,
fallbackColor,
onChange,
}: {
label: string;
value: string;
fallbackColor: string;
onChange: (value: string) => void;
}) {
const normalizedValue = normalizeThemePaletteColor(value) ?? fallbackColor;
return (
<div className="grid min-w-0 gap-2">
<span className="text-xs font-medium text-foreground">{label}</span>
<div className="flex min-w-0 flex-wrap items-center gap-2">
<input
type="color"
value={normalizedValue}
onChange={(event) => onChange(event.target.value)}
aria-label={`${label} theme color`}
className="h-8 w-10 cursor-pointer rounded-xl border border-input bg-background p-0.5"
/>
<div className="flex flex-wrap gap-1.5">
{THEME_PALETTE_SWATCHES.map((swatch) => {
const selected = normalizedValue === swatch;
return (
<button
key={swatch}
type="button"
className={cn(
"size-6 cursor-pointer rounded-full border transition",
selected
? "scale-110 border-foreground ring-2 ring-ring ring-offset-1 ring-offset-background"
: "border-black/10 hover:scale-105 dark:border-white/20",
)}
style={{ backgroundColor: swatch }}
onClick={() => onChange(swatch)}
aria-label={`Use ${swatch} ${label.toLowerCase()} theme color`}
/>
);
})}
</div>
</div>
</div>
);
}
function ThemePalettePreview({ palette }: { palette: ThemePaletteSettings }) {
const previewStyle = getThemePaletteCustomProperties(palette) as CSSProperties;
return (
<div
className="mt-4 rounded-xl border bg-background p-3 text-foreground"
style={previewStyle}
aria-label="Generated theme palette preview"
>
<div className="grid gap-2 sm:grid-cols-4">
{THEME_PALETTE_PREVIEW_SWATCHES.map((swatch) => (
<div key={swatch.variable} className="grid gap-1.5">
<span
className="h-9 rounded-lg border border-border shadow-xs"
style={{ backgroundColor: `var(${swatch.variable})` }}
aria-hidden
/>
<span className="text-[11px] text-muted-foreground">{swatch.label}</span>
</div>
))}
</div>
<div className="mt-3 flex flex-wrap items-center gap-2">
<span className="rounded-full bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground">
Primary
</span>
<span className="rounded-full bg-accent px-2.5 py-1 text-xs font-medium text-accent-foreground">
Accent
</span>
<span className="rounded-full bg-muted px-2.5 py-1 text-xs font-medium text-muted-foreground">
Muted
</span>
</div>
</div>
);
}
function ProviderLastChecked({ lastCheckedAt }: { lastCheckedAt: string | null }) {
useRelativeTimeTick();
const lastCheckedRelative = lastCheckedAt ? formatRelativeTime(lastCheckedAt) : null;
@@ -347,6 +443,10 @@ export function useSettingsRestore(onRestored?: () => void) {
const settings = useSettings();
const { resetSettings } = useUpdateSettings();
const themePaletteDirty = !Equal.equals(
settings.themePalette,
DEFAULT_UNIFIED_SETTINGS.themePalette,
);
const isGitWritingModelDirty = !Equal.equals(
settings.textGenerationModelSelection ?? null,
DEFAULT_UNIFIED_SETTINGS.textGenerationModelSelection ?? null,
@@ -380,6 +480,7 @@ export function useSettingsRestore(onRestored?: () => void) {
const changedSettingLabels = useMemo(
() => [
...(theme !== "system" ? ["Theme"] : []),
...(themePaletteDirty ? ["Theme colors"] : []),
...(settings.timestampFormat !== DEFAULT_UNIFIED_SETTINGS.timestampFormat
? ["Time format"]
: []),
@@ -413,6 +514,7 @@ export function useSettingsRestore(onRestored?: () => void) {
[
areProviderSettingsDirty,
isGitWritingModelDirty,
themePaletteDirty,
settings.autoOpenPlanSidebar,
settings.confirmThreadArchive,
settings.confirmThreadDelete,
@@ -827,6 +929,53 @@ export function GeneralSettingsPanel() {
}
/>
<SettingsRow
title="Theme colors"
description="Choose brand and surface colors. T3 Code generates the palette from them."
resetAction={
!Equal.equals(settings.themePalette, DEFAULT_UNIFIED_SETTINGS.themePalette) ? (
<SettingResetButton
label="theme colors"
onClick={() =>
updateSettings({
themePalette: DEFAULT_UNIFIED_SETTINGS.themePalette,
})
}
/>
) : null
}
>
<div className="mt-4 grid gap-4 sm:grid-cols-2">
<ThemePaletteColorControl
label="Primary color"
value={settings.themePalette.primaryColor}
fallbackColor={DEFAULT_THEME_PALETTE.primaryColor}
onChange={(primaryColor) =>
updateSettings({
themePalette: {
...settings.themePalette,
primaryColor,
},
})
}
/>
<ThemePaletteColorControl
label="Neutral color"
value={settings.themePalette.neutralColor}
fallbackColor={DEFAULT_THEME_PALETTE.neutralColor}
onChange={(neutralColor) =>
updateSettings({
themePalette: {
...settings.themePalette,
neutralColor,
},
})
}
/>
</div>
<ThemePalettePreview palette={settings.themePalette} />
</SettingsRow>
<SettingsRow
title="Time format"
description="System default follows your browser or OS clock preference."
+5 -1
View File
@@ -22,6 +22,7 @@ import { ensureLocalApi } from "~/localApi";
import { Struct } from "effect";
import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
import { applySettingsUpdated, getServerConfig, useServerSettings } from "~/rpc/serverState";
import { applyThemePalette } from "~/themePalette";
const CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE = "[CLIENT_SETTINGS]";
@@ -65,7 +66,9 @@ async function hydrateClientSettings(): Promise<void> {
try {
const persistedSettings = await ensureLocalApi().persistence.getClientSettings();
if (persistedSettings) {
replaceClientSettingsSnapshot({ ...DEFAULT_CLIENT_SETTINGS, ...persistedSettings });
const nextSettings = { ...DEFAULT_CLIENT_SETTINGS, ...persistedSettings };
replaceClientSettingsSnapshot(nextSettings);
applyThemePalette(nextSettings.themePalette);
}
} catch (error) {
console.error(`${CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE} hydrate failed`, error);
@@ -86,6 +89,7 @@ async function hydrateClientSettings(): Promise<void> {
function persistClientSettings(settings: ClientSettings): void {
replaceClientSettingsSnapshot(settings);
applyThemePalette(settings.themePalette);
void ensureLocalApi()
.persistence.setClientSettings(settings)
.catch((error) => {
+38 -36
View File
@@ -86,28 +86,30 @@
:root {
color-scheme: light;
--radius: 0.625rem;
--background: var(--color-white);
--theme-primary-seed: #3b5bdb;
--theme-neutral-seed: #737373;
--background: color-mix(in srgb, var(--theme-neutral-seed) 3%, var(--color-white));
--app-chrome-background: var(--background);
--foreground: var(--color-neutral-800);
--card: var(--color-white);
--card-foreground: var(--color-neutral-800);
--popover: var(--color-white);
--popover-foreground: var(--color-neutral-800);
--primary: oklch(0.488 0.217 264);
--foreground: color-mix(in srgb, var(--theme-neutral-seed) 35%, var(--color-neutral-950));
--card: color-mix(in srgb, var(--theme-neutral-seed) 1.5%, var(--color-white));
--card-foreground: var(--foreground);
--popover: var(--card);
--popover-foreground: var(--foreground);
--primary: color-mix(in oklch, var(--theme-primary-seed) 88%, var(--color-black));
--primary-foreground: var(--color-white);
--secondary: --alpha(var(--color-black) / 4%);
--secondary-foreground: var(--color-neutral-800);
--muted: --alpha(var(--color-black) / 4%);
--muted-foreground: color-mix(in srgb, var(--color-neutral-500) 90%, var(--color-black));
--accent: --alpha(var(--color-black) / 4%);
--accent-foreground: var(--color-neutral-800);
--secondary: color-mix(in srgb, var(--theme-neutral-seed) 7%, transparent);
--secondary-foreground: var(--foreground);
--muted: color-mix(in srgb, var(--theme-neutral-seed) 7%, transparent);
--muted-foreground: color-mix(in srgb, var(--theme-neutral-seed) 72%, var(--color-black));
--accent: color-mix(in srgb, var(--theme-primary-seed) 8%, transparent);
--accent-foreground: color-mix(in srgb, var(--theme-primary-seed) 38%, var(--foreground));
--destructive: var(--color-red-500);
--border: --alpha(var(--color-black) / 8%);
--input: --alpha(var(--color-black) / 10%);
--ring: oklch(0.488 0.217 264);
--border: color-mix(in srgb, var(--theme-neutral-seed) 16%, transparent);
--input: color-mix(in srgb, var(--theme-neutral-seed) 19%, transparent);
--ring: color-mix(in oklch, var(--theme-primary-seed) 88%, var(--color-black));
--destructive-foreground: var(--color-red-700);
--info: var(--color-blue-500);
--info-foreground: var(--color-blue-700);
--info: color-mix(in oklch, var(--theme-primary-seed) 84%, var(--color-blue-500));
--info-foreground: color-mix(in oklch, var(--theme-primary-seed) 80%, var(--color-blue-700));
--success: var(--color-emerald-500);
--success-foreground: var(--color-emerald-700);
--warning: var(--color-amber-500);
@@ -115,28 +117,28 @@
@variant dark {
color-scheme: dark;
--background: color-mix(in srgb, var(--color-neutral-950) 95%, var(--color-white));
--background: color-mix(in srgb, var(--theme-neutral-seed) 10%, var(--color-neutral-950));
--app-chrome-background: var(--background);
--foreground: var(--color-neutral-100);
--card: color-mix(in srgb, var(--background) 98%, var(--color-white));
--card-foreground: var(--color-neutral-100);
--popover: color-mix(in srgb, var(--background) 98%, var(--color-white));
--popover-foreground: var(--color-neutral-100);
--primary: oklch(0.588 0.217 264);
--foreground: color-mix(in srgb, var(--theme-neutral-seed) 10%, var(--color-neutral-100));
--card: color-mix(in srgb, var(--theme-neutral-seed) 14%, var(--background));
--card-foreground: var(--foreground);
--popover: var(--card);
--popover-foreground: var(--foreground);
--primary: color-mix(in oklch, var(--theme-primary-seed) 86%, var(--color-white));
--primary-foreground: var(--color-white);
--secondary: --alpha(var(--color-white) / 4%);
--secondary-foreground: var(--color-neutral-100);
--muted: --alpha(var(--color-white) / 4%);
--muted-foreground: color-mix(in srgb, var(--color-neutral-500) 90%, var(--color-white));
--accent: --alpha(var(--color-white) / 4%);
--accent-foreground: var(--color-neutral-100);
--secondary: color-mix(in srgb, var(--theme-neutral-seed) 13%, transparent);
--secondary-foreground: var(--foreground);
--muted: color-mix(in srgb, var(--theme-neutral-seed) 13%, transparent);
--muted-foreground: color-mix(in srgb, var(--theme-neutral-seed) 58%, var(--color-neutral-100));
--accent: color-mix(in srgb, var(--theme-primary-seed) 16%, transparent);
--accent-foreground: color-mix(in srgb, var(--theme-primary-seed) 20%, var(--foreground));
--destructive: color-mix(in srgb, var(--color-red-500) 90%, var(--color-white));
--border: --alpha(var(--color-white) / 6%);
--input: --alpha(var(--color-white) / 8%);
--ring: oklch(0.588 0.217 264);
--border: color-mix(in srgb, var(--theme-neutral-seed) 16%, transparent);
--input: color-mix(in srgb, var(--theme-neutral-seed) 20%, transparent);
--ring: color-mix(in oklch, var(--theme-primary-seed) 86%, var(--color-white));
--destructive-foreground: var(--color-red-400);
--info: var(--color-blue-500);
--info-foreground: var(--color-blue-400);
--info: color-mix(in oklch, var(--theme-primary-seed) 84%, var(--color-blue-400));
--info-foreground: color-mix(in oklch, var(--theme-primary-seed) 70%, var(--color-blue-300));
--success: var(--color-emerald-500);
--success-foreground: var(--color-emerald-400);
--warning: var(--color-amber-500);
+3
View File
@@ -1,6 +1,7 @@
import {
CommandId,
DEFAULT_SERVER_SETTINGS,
DEFAULT_THEME_PALETTE,
type DesktopBridge,
EnvironmentId,
type VcsStatusResult,
@@ -584,6 +585,7 @@ describe("wsApi", () => {
sidebarProjectSortOrder: "manual" as const,
sidebarThreadSortOrder: "created_at" as const,
timestampFormat: "24-hour" as const,
themePalette: DEFAULT_THEME_PALETTE,
};
const getClientSettings = vi.fn().mockResolvedValue({
...clientSettings,
@@ -645,6 +647,7 @@ describe("wsApi", () => {
sidebarProjectSortOrder: "manual" as const,
sidebarThreadSortOrder: "created_at" as const,
timestampFormat: "24-hour" as const,
themePalette: DEFAULT_THEME_PALETTE,
};
await api.persistence.setClientSettings(clientSettings);
+3
View File
@@ -10,12 +10,15 @@ import { isElectron } from "./env";
import { getRouter } from "./router";
import { APP_DISPLAY_NAME } from "./branding";
import { syncDocumentWindowControlsOverlayClass } from "./lib/windowControlsOverlay";
import { applyStoredThemePalette } from "./themePalette";
// Electron loads the app from a file-backed shell, so hash history avoids path resolution issues.
const history = isElectron ? createHashHistory() : createBrowserHistory();
const router = getRouter(history);
applyStoredThemePalette();
if (isElectron) {
syncDocumentWindowControlsOverlayClass();
}
+37
View File
@@ -0,0 +1,37 @@
import { describe, expect, it } from "vitest";
import { DEFAULT_THEME_PALETTE } from "@t3tools/contracts/settings";
import {
getThemePaletteCustomProperties,
normalizeThemePalette,
normalizeThemePaletteColor,
} from "./themePalette";
describe("themePalette", () => {
it("normalizes valid hex colors and rejects invalid input", () => {
expect(normalizeThemePaletteColor(" #Aa33f0 ")).toBe("#aa33f0");
expect(normalizeThemePaletteColor("#abc")).toBeUndefined();
expect(normalizeThemePaletteColor("rebeccapurple")).toBeUndefined();
});
it("generates CSS seed variables from selected colors", () => {
const properties = getThemePaletteCustomProperties({
primaryColor: "#ff0000",
neutralColor: "#336699",
});
expect(properties).toEqual({
"--theme-primary-seed": "#ff0000",
"--theme-neutral-seed": "#336699",
});
});
it("falls back to the default palette when persisted values are malformed", () => {
const palette = normalizeThemePalette({
primaryColor: "bad",
neutralColor: "also-bad",
});
expect(palette).toEqual(DEFAULT_THEME_PALETTE);
});
});
+82
View File
@@ -0,0 +1,82 @@
import { DEFAULT_THEME_PALETTE, type ThemePaletteSettings } from "@t3tools/contracts/settings";
export const THEME_PALETTE_STORAGE_KEY = "t3code:client-settings:v1";
export const THEME_PALETTE_SWATCHES = [
"#3b5bdb",
"#7c3aed",
"#db2777",
"#dc2626",
"#ea580c",
"#ca8a04",
"#16a34a",
"#0891b2",
] as const;
export const THEME_PALETTE_PREVIEW_SWATCHES = [
{ label: "Primary", variable: "--primary" },
{ label: "Surface", variable: "--background" },
{ label: "Card", variable: "--card" },
{ label: "Muted", variable: "--muted" },
] as const;
const THEME_HEX_COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/u;
const THEME_PALETTE_CUSTOM_PROPERTIES = ["--theme-primary-seed", "--theme-neutral-seed"] as const;
export function normalizeThemePaletteColor(value: string | undefined | null): string | undefined {
const trimmed = value?.trim();
if (!trimmed || !THEME_HEX_COLOR_PATTERN.test(trimmed)) {
return undefined;
}
return trimmed.toLowerCase();
}
export function normalizeThemePalette(
value: Partial<ThemePaletteSettings> | null | undefined,
): ThemePaletteSettings {
return {
primaryColor:
normalizeThemePaletteColor(value?.primaryColor) ?? DEFAULT_THEME_PALETTE.primaryColor,
neutralColor:
normalizeThemePaletteColor(value?.neutralColor) ?? DEFAULT_THEME_PALETTE.neutralColor,
};
}
export function getThemePaletteCustomProperties(
value: Partial<ThemePaletteSettings> | null | undefined,
) {
const palette = normalizeThemePalette(value);
return {
"--theme-primary-seed": palette.primaryColor,
"--theme-neutral-seed": palette.neutralColor,
} as const;
}
export function applyThemePalette(value: Partial<ThemePaletteSettings> | null | undefined) {
if (typeof document === "undefined") return;
const properties = getThemePaletteCustomProperties(value);
for (const propertyName of THEME_PALETTE_CUSTOM_PROPERTIES) {
document.documentElement.style.setProperty(propertyName, properties[propertyName]);
}
}
export function readStoredThemePalette(): ThemePaletteSettings {
if (typeof window === "undefined" || typeof localStorage === "undefined") {
return DEFAULT_THEME_PALETTE;
}
try {
const raw = localStorage.getItem(THEME_PALETTE_STORAGE_KEY);
if (!raw) {
return DEFAULT_THEME_PALETTE;
}
const parsed = JSON.parse(raw) as { themePalette?: Partial<ThemePaletteSettings> };
return normalizeThemePalette(parsed.themePalette);
} catch {
return DEFAULT_THEME_PALETTE;
}
}
export function applyStoredThemePalette() {
applyThemePalette(readStoredThemePalette());
}
+27 -1
View File
@@ -2,10 +2,36 @@ import { describe, expect, it } from "vitest";
import { Schema } from "effect";
import { ProviderInstanceId } from "./providerInstance.ts";
import { DEFAULT_SERVER_SETTINGS, ServerSettings, ServerSettingsPatch } from "./settings.ts";
import {
ClientSettingsSchema,
DEFAULT_CLIENT_SETTINGS,
DEFAULT_SERVER_SETTINGS,
DEFAULT_THEME_PALETTE,
ServerSettings,
ServerSettingsPatch,
} from "./settings.ts";
const decodeServerSettings = Schema.decodeUnknownSync(ServerSettings);
const decodeServerSettingsPatch = Schema.decodeUnknownSync(ServerSettingsPatch);
const decodeClientSettings = Schema.decodeUnknownSync(ClientSettingsSchema);
describe("ClientSettings.themePalette", () => {
it("defaults theme palette colors for existing client settings", () => {
expect(DEFAULT_CLIENT_SETTINGS.themePalette).toEqual(DEFAULT_THEME_PALETTE);
expect(decodeClientSettings({}).themePalette).toEqual(DEFAULT_THEME_PALETTE);
});
it("rejects invalid theme palette colors", () => {
expect(() =>
decodeClientSettings({
themePalette: {
primaryColor: "rebeccapurple",
neutralColor: "#737373",
},
}),
).toThrow();
});
});
describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
it("defaults to an empty record so legacy configs without the key still decode", () => {
+19
View File
@@ -28,6 +28,23 @@ export const SidebarProjectGroupingMode = Schema.Literals([
export type SidebarProjectGroupingMode = typeof SidebarProjectGroupingMode.Type;
export const DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE: SidebarProjectGroupingMode = "repository";
const ThemeColor = TrimmedNonEmptyString.check(Schema.isPattern(/^#[0-9a-fA-F]{6}$/u));
export const DEFAULT_THEME_PALETTE = {
primaryColor: "#3b5bdb",
neutralColor: "#737373",
} as const;
export const ThemePaletteSettings = Schema.Struct({
primaryColor: ThemeColor.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_THEME_PALETTE.primaryColor)),
),
neutralColor: ThemeColor.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_THEME_PALETTE.neutralColor)),
),
}).pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_THEME_PALETTE)));
export type ThemePaletteSettings = typeof ThemePaletteSettings.Type;
export const ClientSettingsSchema = Schema.Struct({
autoOpenPlanSidebar: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
confirmThreadArchive: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
@@ -75,6 +92,7 @@ export const ClientSettingsSchema = Schema.Struct({
timestampFormat: TimestampFormat.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
),
themePalette: ThemePaletteSettings,
});
export type ClientSettings = typeof ClientSettingsSchema.Type;
@@ -482,5 +500,6 @@ export const ClientSettingsPatch = Schema.Struct({
sidebarProjectSortOrder: Schema.optionalKey(SidebarProjectSortOrder),
sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
timestampFormat: Schema.optionalKey(TimestampFormat),
themePalette: Schema.optionalKey(ThemePaletteSettings),
});
export type ClientSettingsPatch = typeof ClientSettingsPatch.Type;