The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): cache backend skins so the boot paint can resolve the saved one
Brooklyn Nicholson413d5ab86322
diff --git a/apps/desktop/src/themes/backend-sync.test.ts b/apps/desktop/src/themes/backend-sync.test.tsindex 373333123a0..24716f1d982 100644--- a/apps/desktop/src/themes/backend-sync.test.ts+++ b/apps/desktop/src/themes/backend-sync.test.ts@@ -1,4 +1,4 @@-import { beforeEach, describe, expect, it } from 'vitest'+import { beforeEach, describe, expect, it, vi } from 'vitest'import { $backendThemes, $pendingSkinApply, __resetBackendSkinSync, ingestBackendSkin } from './backend-sync'@@ -8,7 +8,10 @@ const skin = (name: string) => ({})describe('ingestBackendSkin', () => {- beforeEach(() => __resetBackendSkinSync())+ beforeEach(() => {+ window.localStorage.clear()+ __resetBackendSkinSync()+ })it('registers a converted skin without applying when apply=false', () => {ingestBackendSkin(skin('neon'), { apply: false })@@ -106,4 +109,25 @@ describe('ingestBackendSkin', () => {expect($pendingSkinApply.get()).toBeNull()})++ it('hydrates the registry from storage on load, so a persisted pick resolves before the gateway connects', async () => {+ ingestBackendSkin(skin('neon'), { apply: false })+ expect(JSON.parse(window.localStorage.getItem('hermes-desktop-backend-themes-v1') ?? '{}').neon?.name).toBe('neon')++ // Relaunch: a fresh module instance with the same storage.+ vi.resetModules()+ const fresh = await import('./backend-sync')++ expect(fresh.$backendThemes.get().neon?.name).toBe('neon')+ })++ it('drops junk and built-in names from the cached registry', async () => {+ const mono = { name: 'mono', label: 'x', colors: { background: '#000', foreground: '#fff', primary: '#f0f' } }+ window.localStorage.setItem('hermes-desktop-backend-themes-v1', JSON.stringify({ mono, bad: { name: 'bad' } }))++ vi.resetModules()+ const fresh = await import('./backend-sync')++ expect(fresh.$backendThemes.get()).toEqual({})+ })})diff --git a/apps/desktop/src/themes/backend-sync.ts b/apps/desktop/src/themes/backend-sync.tsindex 9a988730f10..e12b2bcb7fd 100644--- a/apps/desktop/src/themes/backend-sync.ts+++ b/apps/desktop/src/themes/backend-sync.ts@@ -19,12 +19,29 @@import type { HermesSkin } from '@hermes/shared/skin'import { atom } from 'nanostores'+import { readJson, writeJson } from '@/lib/storage'+import { BUILTIN_THEMES } from './presets'import { skinToDesktopTheme } from './skin'-import type { DesktopTheme } from './types'+import { type DesktopTheme, isValidTheme } from './types'++// Cached so the boot-time paint (which runs before the gateway connects) can+// resolve a persisted skin pick synchronously, like a built-in or a user+// install. Without it the stored name failed `resolveTheme` on every launch+// and the app silently painted the default until the next `skin.changed`.+const BACKEND_THEMES_KEY = 'hermes-desktop-backend-themes-v1'++const readCached = (): Record<string, DesktopTheme> =>+ Object.fromEntries(+ Object.entries(readJson<Record<string, unknown>>(BACKEND_THEMES_KEY) ?? {}).filter(+ (entry): entry is [string, DesktopTheme] => !BUILTIN_THEMES[entry[0]] && isValidTheme(entry[1])+ )+ )/** Skins pushed by the backend, keyed by name. Merged by `listAllThemes`. */-export const $backendThemes = atom<Record<string, DesktopTheme>>({})+export const $backendThemes = atom<Record<string, DesktopTheme>>(typeof window === 'undefined' ? {} : readCached())++$backendThemes.listen(themes => writeJson(BACKEND_THEMES_KEY, themes))/** One-shot skin name the ThemeProvider should switch to (it clears this). */export const $pendingSkinApply = atom<string | null>(null)