The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(store): add theme provider and theme slice
Steven Enamakeldbf770ac34ad
diff --git a/app/src/providers/ThemeProvider.tsx b/app/src/providers/ThemeProvider.tsxindex 3326d51a28..4a56c3adc5 100644--- a/app/src/providers/ThemeProvider.tsx+++ b/app/src/providers/ThemeProvider.tsx@@ -1,6 +1,7 @@import { ReactNode, useCallback, useEffect, useRef } from 'react';import { withDerivedChrome } from '../lib/theme/chrome';+import { applyBorderContrast, applyLayoutAttributes } from '../lib/theme/layout';import { findFamily, resolveFamilyVariant } from '../lib/theme/presets';import type { Theme } from '../lib/theme/types';import { useAppSelector } from '../store/hooks';@@ -8,6 +9,7 @@ import {selectActiveFamilyId,selectEffectiveTheme,selectRootFontSizePx,+ selectThemeLayout,selectThemeVariant,} from '../store/themeSlice';@@ -32,6 +34,12 @@ const ThemeProvider = ({ children }: { children: ReactNode }) => {const themeVariant = useAppSelector(selectThemeVariant);const activeFamilyId = useAppSelector(selectActiveFamilyId);const effectiveTheme = useAppSelector(selectEffectiveTheme);+ const layout = useAppSelector(selectThemeLayout);+ // Read inside `applyTheme` (a stable callback also fired by the OS+ // light/dark listener) so border contrast is re-derived on every theme apply.+ const layoutRef = useRef(layout);+ layoutRef.current = layout;+ const appliedColorsRef = useRef<Record<string, string>>({});// Track which inline vars we set last time so we can clear stale ones.const appliedRef = useRef<{ colors: string[]; fonts: string[] }>({ colors: [], fonts: [] });@@ -74,6 +82,10 @@ const ThemeProvider = ({ children }: { children: ReactNode }) => {root.style.removeProperty('--app-gradient');}+ // Border contrast derives from the colours just applied, so it runs last.+ applyBorderContrast(root, layoutRef.current.borderContrast, theme.colors);+ appliedColorsRef.current = theme.colors;+appliedRef.current = { colors: Object.keys(theme.colors), fonts: Object.keys(theme.fonts) };console.debug('[theme] applied', {id: theme.id,@@ -91,6 +103,15 @@ const ThemeProvider = ({ children }: { children: ReactNode }) => {document.documentElement.style.fontSize = rootFontSizePx;}, [rootFontSizePx]);+ // Apply Appearance → Layout (corners, border contrast, border areas).+ useEffect(() => {+ if (typeof document === 'undefined') return;+ const root = document.documentElement;+ console.debug('[theme] applying layout', layout);+ applyLayoutAttributes(root, layout);+ applyBorderContrast(root, layout.borderContrast, appliedColorsRef.current);+ }, [layout]);+// Apply the active theme whenever it changes.useEffect(() => {applyTheme(effectiveTheme);diff --git a/app/src/store/index.ts b/app/src/store/index.tsindex d2329d076f..c6669df98e 100644--- a/app/src/store/index.ts+++ b/app/src/store/index.ts@@ -112,6 +112,7 @@ const themePersistConfig = {'activeThemeId','themeVariant','customThemes',+ 'layout',],};const persistedThemeReducer = persistReducer(themePersistConfig, themeReducer);diff --git a/app/src/store/themeSlice.ts b/app/src/store/themeSlice.tsindex 8e7279458a..6656b52103 100644--- a/app/src/store/themeSlice.ts+++ b/app/src/store/themeSlice.ts@@ -8,6 +8,7 @@ import {resolveFamilyVariant,THEME_FAMILIES,} from '../lib/theme/presets';+import { DEFAULT_LAYOUT, resolveLayout, type ThemeLayout } from '../lib/theme/layout';import type { FontRole } from '../lib/theme/tokens';import type { Theme, ThemeFamily } from '../lib/theme/types';@@ -94,6 +95,12 @@ interface ThemeState {themeVariant: ThemeVariant;/** User-authored themes (full or partial token overrides). */customThemes: Theme[];+ /**+ * Appearance → Layout: corner rounding, border contrast and which areas draw+ * borders. Theme-independent. Absent in state persisted before it existed;+ * read it through {@link selectThemeLayout}, which fills the defaults.+ */+ layout: ThemeLayout;}const initialState: ThemeState = {@@ -105,6 +112,7 @@ const initialState: ThemeState = {activeThemeId: DEFAULT_FAMILY_ID,themeVariant: 'system',customThemes: [],+ layout: DEFAULT_LAYOUT,};const themeSlice = createSlice({@@ -193,6 +201,23 @@ const themeSlice = createSlice({setCustomFontSizePx(state, action: PayloadAction<number | null>) {state.customFontSizePx = action.payload === null ? null : clampFontSizePx(action.payload);},+ /** Merge a partial layout change (e.g. one border area) into the current one. */+ setThemeLayout(+ state,+ action: PayloadAction<Partial<Omit<ThemeLayout, 'borderAreas'>> & {+ borderAreas?: Partial<ThemeLayout['borderAreas']>;+ }>+ ) {+ const current = resolveLayout(state.layout);+ state.layout = resolveLayout({+ ...current,+ ...action.payload,+ borderAreas: { ...current.borderAreas, ...action.payload.borderAreas },+ });+ },+ resetThemeLayout(state) {+ state.layout = DEFAULT_LAYOUT;+ },setDeveloperMode(state, action: PayloadAction<boolean>) {state.developerMode = action.payload;},@@ -226,6 +251,8 @@ export const {setFontSize,setCustomFontSizePx,setDeveloperMode,+ setThemeLayout,+ resetThemeLayout,setActiveTheme,upsertCustomTheme,deleteCustomTheme,@@ -239,6 +266,10 @@ export default themeSlice.reducer;/** Built-in theme families (static). */export const selectThemeFamilies = (): ThemeFamily[] => THEME_FAMILIES;+/** The layout preference with defaults filled for older persisted state. */+export const selectThemeLayout = (state: { theme?: ThemeState }): ThemeLayout =>+ resolveLayout(state.theme?.layout);+export const selectActiveThemeId = (state: { theme?: ThemeState }): string =>state.theme?.activeThemeId ?? DEFAULT_FAMILY_ID;