fix(desktop): finer window translucency steps
The Window Translucency slider moved in fixed 5% jumps, so a 0-100 lever had only 21 stops packed into a 160px control -- and arrow-key nudges skipped 5 at a time. The settings that are actually readable live at the low end, so the coarse step made most of them unreachable. Step in single percent, and hoist the bounds into named constants beside the atom that owns them, mirroring PET_SCALE_MIN/PET_SCALE_MAX so the control and the clamp read from one source.
This commit is contained in:
@@ -20,7 +20,13 @@ import { $reactionsEnabled, setReactionsEnabled } from '@/store/reactions-enable
|
||||
import { $reasoningCollapsedByDefault, setReasoningCollapsedByDefault } from '@/store/reasoning-disclosure'
|
||||
import { $sessionListDensity, type SessionListDensity, setSessionListDensity } from '@/store/session-list-density'
|
||||
import { $toolViewMode, setToolViewMode } from '@/store/tool-view'
|
||||
import { $translucency, setTranslucency } from '@/store/translucency'
|
||||
import {
|
||||
$translucency,
|
||||
setTranslucency,
|
||||
TRANSLUCENCY_MAX,
|
||||
TRANSLUCENCY_MIN,
|
||||
TRANSLUCENCY_STEP
|
||||
} from '@/store/translucency'
|
||||
import { $zoomPercent, setZoomPercent } from '@/store/zoom'
|
||||
import { getBaseColors, useTheme } from '@/themes/context'
|
||||
import { installVscodeThemeFromMarketplace } from '@/themes/install'
|
||||
@@ -466,13 +472,13 @@ export function AppearanceSettings() {
|
||||
<input
|
||||
aria-label={a.translucencyTitle}
|
||||
className="h-1 w-40 cursor-pointer appearance-none rounded-full bg-(--ui-stroke-tertiary)"
|
||||
max={100}
|
||||
min={0}
|
||||
max={TRANSLUCENCY_MAX}
|
||||
min={TRANSLUCENCY_MIN}
|
||||
onChange={event => {
|
||||
triggerHaptic('selection')
|
||||
setTranslucency(Number(event.target.value))
|
||||
}}
|
||||
step={5}
|
||||
step={TRANSLUCENCY_STEP}
|
||||
style={{ accentColor: 'var(--dt-primary)' }}
|
||||
type="range"
|
||||
value={translucency}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
|
||||
import { onPersistenceEvent, type PersistenceEvent } from '@/lib/storage'
|
||||
|
||||
import { $translucency, setTranslucency, TRANSLUCENCY_MAX, TRANSLUCENCY_MIN, TRANSLUCENCY_STEP } from './translucency'
|
||||
|
||||
const KEY = 'hermes.desktop.translucency.v1'
|
||||
|
||||
describe('window translucency lever', () => {
|
||||
beforeEach(() => setTranslucency(TRANSLUCENCY_MIN))
|
||||
|
||||
it('steps in single percent so the readable low end is reachable', () => {
|
||||
expect(TRANSLUCENCY_STEP).toBe(1)
|
||||
expect(TRANSLUCENCY_MIN).toBe(0)
|
||||
expect(TRANSLUCENCY_MAX).toBe(100)
|
||||
})
|
||||
|
||||
it('defaults to off', () => {
|
||||
expect($translucency.get()).toBe(TRANSLUCENCY_MIN)
|
||||
})
|
||||
|
||||
it('accepts every step the slider can emit', () => {
|
||||
for (let intensity = TRANSLUCENCY_MIN; intensity <= TRANSLUCENCY_MAX; intensity += TRANSLUCENCY_STEP) {
|
||||
setTranslucency(intensity)
|
||||
expect($translucency.get()).toBe(intensity)
|
||||
}
|
||||
})
|
||||
|
||||
it('clamps out-of-range input to the lever bounds', () => {
|
||||
setTranslucency(-40)
|
||||
expect($translucency.get()).toBe(TRANSLUCENCY_MIN)
|
||||
|
||||
setTranslucency(240)
|
||||
expect($translucency.get()).toBe(TRANSLUCENCY_MAX)
|
||||
})
|
||||
|
||||
it('rounds fractional input to a whole percent', () => {
|
||||
setTranslucency(35.6)
|
||||
expect($translucency.get()).toBe(36)
|
||||
})
|
||||
|
||||
it('persists under a stable key so a saved setting survives upgrades', () => {
|
||||
const writes: PersistenceEvent[] = []
|
||||
|
||||
const stop = onPersistenceEvent(event => {
|
||||
if (event.op === 'write') {
|
||||
writes.push(event)
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
setTranslucency(23)
|
||||
} finally {
|
||||
stop()
|
||||
}
|
||||
|
||||
expect(writes).toContainEqual({ key: KEY, op: 'write', value: '23' })
|
||||
})
|
||||
})
|
||||
@@ -16,7 +16,14 @@ import { persistString, storedString } from '@/lib/storage'
|
||||
|
||||
const KEY = 'hermes.desktop.translucency.v1'
|
||||
|
||||
const clamp = (n: number): number => Math.min(100, Math.max(0, Math.round(n)))
|
||||
// Slider bounds — mirror `electron/window-opacity.ts` (TRANSLUCENCY_MIN / MAX)
|
||||
// so the control and the main-process clamp agree on the same range. The step
|
||||
// is renderer-only: the main process takes any integer in range.
|
||||
export const TRANSLUCENCY_MIN = 0
|
||||
export const TRANSLUCENCY_MAX = 100
|
||||
export const TRANSLUCENCY_STEP = 1
|
||||
|
||||
const clamp = (n: number): number => Math.min(TRANSLUCENCY_MAX, Math.max(TRANSLUCENCY_MIN, Math.round(n)))
|
||||
|
||||
const read = (): number => {
|
||||
const n = Number(storedString(KEY))
|
||||
|
||||
Reference in New Issue
Block a user