The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): close the glass state and perf leaks
Brooklyn Nicholsona1fca9b625c1
diff --git a/apps/desktop/src/app/settings/appearance-settings.tsx b/apps/desktop/src/app/settings/appearance-settings.tsxindex cbc452c838d..84951d8bbdc 100644--- a/apps/desktop/src/app/settings/appearance-settings.tsx+++ b/apps/desktop/src/app/settings/appearance-settings.tsx@@ -28,6 +28,7 @@ import {GLASS_SCOPES,GLASS_SUPPORTED,pulseTranslucencyPeek,+ resetTranslucencyPeek,setTranslucency,setTranslucencyMaterial,setTranslucencyMode,@@ -293,6 +294,12 @@ export function AppearanceSettings() {const activeProfileKey = normalizeProfileKey(useStore($activeGatewayProfile))const a = t.settings.appearance+ // A pointer held on the intensity slider when this overlay closes (Escape+ // mid-drag) never delivers its pointerup here, which would strand the peek+ // counter above zero and ghost the NEXT settings overlay. Unmount drops+ // every outstanding hold.+ useEffect(() => resetTranslucencyPeek, [])+const [query, setQuery] = useState('')// One box does double duty: filter installed themes live (below), and run adiff --git a/apps/desktop/src/store/translucency.test.ts b/apps/desktop/src/store/translucency.test.tsindex 7ac8ecd47b3..d09744a7a22 100644--- a/apps/desktop/src/store/translucency.test.ts+++ b/apps/desktop/src/store/translucency.test.ts@@ -21,6 +21,7 @@ import {endTranslucencyPeek,GLASS_SUPPORTED,isChatWindow,+ resetTranslucencyPeek,setTranslucency,setTranslucencyMaterial,setTranslucencyMode,@@ -311,6 +312,57 @@ describe('translucency peek', () => {})})+describe('peek reset', () => {+ // Escape mid-drag unmounts the slider before its pointerup ever fires; the+ // settings surface calls reset on unmount so the counter can't stay wedged+ // and ghost the next overlay at 8% opacity.+ it('drops every outstanding hold at once', () => {+ beginTranslucencyPeek()+ beginTranslucencyPeek()+ beginTranslucencyPeek()+ expect(document.documentElement.hasAttribute('data-hermes-translucency-peek')).toBe(true)++ resetTranslucencyPeek()+ expect($translucencyPeek.get()).toBe(0)+ expect(document.documentElement.hasAttribute('data-hermes-translucency-peek')).toBe(false)++ // A pulse timer expiring after the reset must not push the counter negative+ // or resurrect the attribute.+ endTranslucencyPeek()+ expect($translucencyPeek.get()).toBe(0)+ expect(document.documentElement.hasAttribute('data-hermes-translucency-peek')).toBe(false)+ })+})++describe('cross-window sync', () => {+ afterEach(() => {+ setTranslucencyMode('clear')+ setTranslucency(TRANSLUCENCY_MIN)+ })++ // Under glass main touches nothing native on an intensity change, so a+ // sibling window's storage event is the ONLY way this window hears about it.+ it("adopts a sibling window's persisted state", () => {+ window.localStorage.setItem(+ KEY,+ JSON.stringify({ intensity: 77, mode: 'clear', material: DEFAULT_GLASS_MATERIAL, scope: DEFAULT_GLASS_SCOPE })+ )++ window.dispatchEvent(new StorageEvent('storage', { key: KEY, newValue: 'x' }))++ expect($translucency.get().intensity).toBe(77)+ })++ it('ignores storage events for other keys', () => {+ setTranslucency(12)+ window.localStorage.setItem(KEY, JSON.stringify({ intensity: 99, mode: 'clear' }))++ window.dispatchEvent(new StorageEvent('storage', { key: 'hermes.desktop.zoom.v1', newValue: 'x' }))++ expect($translucency.get().intensity).toBe(12)+ })+})+// The store must actually CONSULT isChatWindow, not merely export it: glass// rewrites page-level surfaces, and the HUD / pet overlay / quick entry own// their own backgrounds. Driving window.location.search proves the wiring.diff --git a/apps/desktop/src/store/translucency.ts b/apps/desktop/src/store/translucency.tsindex 480a7dd6b71..2b2960c257b 100644--- a/apps/desktop/src/store/translucency.ts+++ b/apps/desktop/src/store/translucency.ts@@ -152,7 +152,18 @@ const measureRailEdge = (): void => {const startRailTracking = (): void => {if (railTrackingOn) {- measureRailEdge()+ // Already tracking: the ResizeObserver on the rail and the window resize+ // listener own every geometry change from here. Re-measuring per store+ // sync would force a layout read (getBoundingClientRect) right after the+ // tint's style write, once per slider tick — write/read thrash on the+ // drag's hot path for a seam that isn't moving. Two exceptions re-acquire:+ // a rail we haven't FOUND yet (scope enabled before the sidebar mounted),+ // and a rail that REMOUNTED (layout reset swaps the element) — the+ // observer sits on the detached node and never fires again. isConnected+ // is a flag read, so the settled hot path stays a single boolean check.+ if (!railTarget || !railTarget.isConnected) {+ measureRailEdge()+ }return}@@ -202,6 +213,19 @@ export function endTranslucencyPeek(): void {$translucencyPeek.set(Math.max(0, $translucencyPeek.get() - 1))}+/**+ * Drop every outstanding hold at once. The settings surface calls this on+ * unmount: a pointer held on the slider when the overlay closes (Escape+ * mid-drag) never delivers its pointerup to the unmounted element, and a+ * counter stuck above zero would leave the peek attribute on <html> —+ * rendering the NEXT settings overlay ghosted at 8% opacity. Outstanding+ * pulse timers still fire endTranslucencyPeek later; the zero floor makes+ * them no-ops.+ */+export function resetTranslucencyPeek(): void {+ $translucencyPeek.set(0)+}+/*** Timed peek for one-shot changes (frost / area / mode clicks, keyboard* slider steps): long enough to read the effect, short enough to hand the@@ -284,6 +308,29 @@ if (typeof window !== 'undefined') {}})+ // Cross-window sync (same pattern as themes/context and store/session):+ // under glass an intensity change is painted entirely by each renderer —+ // main deliberately touches nothing native — so a second chat window only+ // learns about it through the storage event its sibling's debounced write+ // fires. Without this, window B's tint freezes until reload.+ window.addEventListener('storage', event => {+ if (event.key !== KEY) {+ return+ }++ const next = read()+ const current = $translucency.get()++ if (+ next.intensity !== current.intensity ||+ next.mode !== current.mode ||+ next.material !== current.material ||+ next.scope !== current.scope+ ) {+ $translucency.set(next)+ }+ })+$translucencyPeek.subscribe(count => {if (typeof document === 'undefined') {return