The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): share the theme shape check between registries
Brooklyn Nicholson9403ad265638
diff --git a/apps/desktop/src/themes/types.ts b/apps/desktop/src/themes/types.tsindex 3aefda3eaa3..a8e16d71375 100644--- a/apps/desktop/src/themes/types.ts+++ b/apps/desktop/src/themes/types.ts@@ -99,3 +99,25 @@ export interface DesktopTheme {/** Dark-variant terminal ANSI palette. Falls back to `terminal`. */darkTerminal?: DesktopTerminalPalette}++// The minimal set of color keys a stored theme must carry to be usable. We keep+// this loose — `applyTheme` tolerates missing optionals via fallbacks — but a+// theme with no background/foreground/primary is junk and gets dropped.+const REQUIRED_COLOR_KEYS: ReadonlyArray<keyof DesktopThemeColors> = ['background', 'foreground', 'primary']++/** Shape check for a theme read back from storage or a contribution. */+export function isValidTheme(value: unknown): value is DesktopTheme {+ if (!value || typeof value !== 'object') {+ return false+ }++ const theme = value as Partial<DesktopTheme>++ if (typeof theme.name !== 'string' || typeof theme.label !== 'string' || !theme.colors) {+ return false+ }++ const colors = theme.colors as unknown as Record<string, unknown>++ return REQUIRED_COLOR_KEYS.every(key => typeof colors[key] === 'string')+}diff --git a/apps/desktop/src/themes/user-themes.ts b/apps/desktop/src/themes/user-themes.tsindex 3dfba148d4b..d3c0f167663 100644--- a/apps/desktop/src/themes/user-themes.ts+++ b/apps/desktop/src/themes/user-themes.ts@@ -16,7 +16,7 @@ import { registry } from '@/contrib/registry'import { $backendThemes } from './backend-sync'import { BUILTIN_THEMES } from './presets'-import type { DesktopTheme, DesktopThemeColors } from './types'+import { type DesktopTheme, isValidTheme } from './types'const USER_THEMES_KEY = 'hermes-desktop-user-themes-v1'@@ -25,27 +25,6 @@ const USER_THEMES_KEY = 'hermes-desktop-user-themes-v1'// back out, so every install surface can tell what's already installed.const MARKETPLACE_DESC_PREFIX = 'VS Code · '-// The minimal set of color keys a stored theme must carry to be usable. We keep-// this loose — `applyTheme` tolerates missing optionals via fallbacks — but a-// theme with no background/foreground/primary is junk and gets dropped.-const REQUIRED_COLOR_KEYS: ReadonlyArray<keyof DesktopThemeColors> = ['background', 'foreground', 'primary']--function isValidTheme(value: unknown): value is DesktopTheme {- if (!value || typeof value !== 'object') {- return false- }-- const theme = value as Partial<DesktopTheme>-- if (typeof theme.name !== 'string' || typeof theme.label !== 'string' || !theme.colors) {- return false- }-- const colors = theme.colors as unknown as Record<string, unknown>-- return REQUIRED_COLOR_KEYS.every(key => typeof colors[key] === 'string')-}-function readStored(): Record<string, DesktopTheme> {try {const raw = window.localStorage.getItem(USER_THEMES_KEY)