mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
None of this is reachable, and none of it is caught by the compiler: tsc's noUnusedLocals only sees a name unused inside its own file, and CSS has no such check at all. - --scroll-height, a token no rule ever read. - DropMenu's danger flag and the .dropmenu-danger rule behind it, which no caller has ever set. - SunMoonIcon and PowerIcon, from a footer that has not looked like that for a while. FlameIcon stays: the Stats costliest-session row draws it. - currentTheme, whose last caller went with the theme cycle, and settingsSnapshot, which never had one. - .segmented, .segment and .segment-active, left behind by the period control that now draws its own tabs. - A SystemTime import in usage_guard that only the tests use, which the ordinary build had been warning about since it landed.
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
/// The few preferences that live in the webview (everything the CLI also needs, like the
|
|
/// currency, lives in ~/.config/codeburn/config.json via the Rust side).
|
|
|
|
const KEYS = {
|
|
theme: 'codeburn.theme',
|
|
insight: 'codeburn.insight',
|
|
starBannerDismissed: 'codeburn.starBannerDismissed',
|
|
trayBadge: 'codeburn.trayBadge',
|
|
accent: 'codeburn.accent',
|
|
} as const
|
|
|
|
type Key = keyof typeof KEYS
|
|
|
|
export function readSetting(key: Key): string | null {
|
|
try {
|
|
return localStorage.getItem(KEYS[key])
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function writeSetting(key: Key, value: string | null): void {
|
|
try {
|
|
if (value === null) localStorage.removeItem(KEYS[key])
|
|
else localStorage.setItem(KEYS[key], value)
|
|
} catch {
|
|
// Storage can be unavailable in a locked-down webview; preferences are best-effort.
|
|
}
|
|
}
|
|
|
|
export type Theme = 'light' | 'dark'
|
|
|
|
export function applyTheme(theme: Theme | null): void {
|
|
if (theme) document.documentElement.setAttribute('data-theme', theme)
|
|
else document.documentElement.removeAttribute('data-theme')
|
|
writeSetting('theme', theme)
|
|
}
|