Skip to content

The agent that grows with you

fix(desktop): clear-mode fade tracks the drag again

Brooklyn Nicholson6eb23c79d3af
diff --git a/apps/desktop/src/store/translucency.test.ts b/apps/desktop/src/store/translucency.test.ts
index ea2e4196096..7ac8ecd47b3 100644
--- a/apps/desktop/src/store/translucency.test.ts
+++ b/apps/desktop/src/store/translucency.test.ts
@@ -125,7 +125,11 @@ describe('window translucency lever', () => {
}
})
- it('mirrors the whole state to the desktop bridge, coalesced across a drag', () => {
+ // Flipped from an earlier version that asserted the bridge was debounced:
+ // in clear mode the native window fade IS the effect, and main can only
+ // move it when told — a debounced send froze the fade mid-drag. Main diffs
+ // and debounces its own disk write, so per-tick sends are cheap.
+ it('mirrors every tick to the desktop bridge so the clear-mode fade tracks the drag', () => {
vi.useFakeTimers()
const calls: unknown[] = []
window.hermesDesktop = { setTranslucency: (payload: unknown) => calls.push(payload) } as never
@@ -135,12 +139,7 @@ describe('window translucency lever', () => {
setTranslucency(intensity)
}
- // Each tick would otherwise wake the main process.
- expect(calls).toHaveLength(0)
-
- vi.advanceTimersByTime(200)
-
- expect(calls).toHaveLength(1)
+ expect(calls).toHaveLength(5)
expect(calls.at(-1)).toEqual({
intensity: 40,
mode: 'clear',
diff --git a/apps/desktop/src/store/translucency.ts b/apps/desktop/src/store/translucency.ts
index 0fc4254cb2f..480a7dd6b71 100644
--- a/apps/desktop/src/store/translucency.ts
+++ b/apps/desktop/src/store/translucency.ts
@@ -251,39 +251,36 @@ const applyGlassSurfaces = ({ intensity, mode, scope }: TranslucencyState): void
}
if (typeof window !== 'undefined') {
- // The intensity slider fires ~100 updates per drag, and two of the three
- // things a sync does are expensive per-tick: localStorage.setItem is
- // synchronous, and the IPC send wakes the main process. Only the page paint
- // has to keep up with the hand — nothing reads the persisted value until a
- // cold launch, and main's own work is diffed anyway.
- //
- // So: paint every tick, persist and notify on a trailing edge.
- let flushTimer: null | number = null
-
- const flush = () => {
- flushTimer = null
-
- const state = $translucency.get()
-
- writeJson(KEY, state)
- window.hermesDesktop?.setTranslucency?.(state)
+ // The intensity slider fires ~100 updates per drag. The expensive per-tick
+ // work is the synchronous localStorage.setItem — so THAT is debounced.
+ // Everything the user can see must track the hand: the page paint (glass is
+ // rendered here) AND the IPC send, because in clear mode the effect is the
+ // native window opacity and main can only move it when told. Main diffs the
+ // state and debounces its own disk write, so per-tick sends cost one
+ // setOpacity in clear mode and nothing at all under glass.
+ let storageTimer: null | number = null
+
+ const persist = () => {
+ storageTimer = null
+ writeJson(KEY, $translucency.get())
}
$translucency.subscribe(state => {
applyGlassSurfaces(state)
+ window.hermesDesktop?.setTranslucency?.(state)
- if (flushTimer !== null) {
- window.clearTimeout(flushTimer)
+ if (storageTimer !== null) {
+ window.clearTimeout(storageTimer)
}
- flushTimer = window.setTimeout(flush, 120)
+ storageTimer = window.setTimeout(persist, 120)
})
// A window closing mid-drag must not lose the setting.
window.addEventListener('pagehide', () => {
- if (flushTimer !== null) {
- window.clearTimeout(flushTimer)
- flush()
+ if (storageTimer !== null) {
+ window.clearTimeout(storageTimer)
+ persist()
}
})