Skip to content

Commit 4957d16

Browse files
committed
Tighten live-apply path: name timing constants, hoist ToastAction type, drop unused exports
1 parent c0bc65d commit 4957d16

5 files changed

Lines changed: 14 additions & 15 deletions

File tree

frontend/src/App.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@
9393
// Live-preview apply. Tracks the snapshot signature so we don't fire
9494
// on object-identity churn. `null` baseline doubles as the
9595
// not-yet-armed flag — first read just records the signature.
96+
// Long enough to coalesce slider drags but short enough to feel "live".
97+
const LIVE_APPLY_DEBOUNCE_MS = 1500;
9698
let lastLiveSignature: string | null = null;
9799
const debouncedLiveApply = debounce(() => {
98100
applyThemeLive();
99-
}, 1500);
101+
}, LIVE_APPLY_DEBOUNCE_MS);
100102
$effect(() => {
101103
const enabled = getLiveApply();
102104
// Once armed, skip the JSON.stringify when the toggle is off.

frontend/src/lib/actions/themeActions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export async function applyTheme(): Promise<void> {
6464
}
6565
}
6666

67+
// Quieter undo-offering toast for live preview; long enough to react,
68+
// short enough not to pile up during rapid edits.
69+
const LIVE_APPLY_TOAST_MS = 2200;
70+
6771
// Same backend call as applyTheme(), but with a quieter toast that offers
6872
// Undo. Used by the live-preview effect when the user flips on Live Apply.
6973
export async function applyThemeLive(): Promise<void> {
@@ -73,7 +77,7 @@ export async function applyThemeLive(): Promise<void> {
7377
const result = await runApply();
7478
if (result.success) {
7579
showToast('Live preview applied', {
76-
duration: 2200,
80+
duration: LIVE_APPLY_TOAST_MS,
7781
action: {label: 'Undo', run: undoAction},
7882
});
7983
}

frontend/src/lib/constants/apps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const ALWAYS_INCLUDED_APPS = new Set(['colors']);
2929

3030
// Pretty labels for known templates. Anything not listed falls back to a
3131
// title-cased version of the key.
32-
export const APP_LABELS: Record<string, string> = {
32+
const APP_LABELS: Record<string, string> = {
3333
gtk: 'GTK',
3434
zed: 'Zed',
3535
vscode: 'VS Code',

frontend/src/lib/stores/theme.svelte.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ export function getThemeSignature(): string {
171171
}
172172

173173
let lastAppliedSignature = $state<string>('');
174-
export function getLastAppliedSignature(): string {
175-
return lastAppliedSignature;
176-
}
177174
export function markApplied(): void {
178175
lastAppliedSignature = getThemeSignature();
179176
}
@@ -259,10 +256,6 @@ export function setPaletteFromExtraction(path: string, colors: string[]): void {
259256
setPalette(colors);
260257
}
261258

262-
export function getLastExtractedPath(): string {
263-
return lastExtractedPath;
264-
}
265-
266259
export function setLastExtractedPath(path: string): void {
267260
lastExtractedPath = path;
268261
}

frontend/src/lib/stores/ui.svelte.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ export type Tab =
99
export const COLOR_MODELS = ['rgb', 'hsl', 'oklch'] as const;
1010
export type ColorModel = (typeof COLOR_MODELS)[number];
1111

12+
export type ToastAction = {label: string; run: () => void};
13+
1214
// --- Reactive state ---
1315
let activeTab = $state<Tab>('editor');
1416
let sidebarVisible = $state<boolean>(true);
1517
let toastMessage = $state<string>('');
1618
let toastVisible = $state<boolean>(false);
17-
let toastAction = $state<{label: string; run: () => void} | null>(null);
19+
let toastAction = $state<ToastAction | null>(null);
1820
let liveApply = $state<boolean>(readBoolPref('aether-live-apply', false));
1921
let targetsVisible = $state<boolean>(
2022
readBoolPref('aether-targets-visible', true)
@@ -96,9 +98,7 @@ export function toggleSidebar(): void {
9698

9799
export function showToast(
98100
msg: string,
99-
durationOrOpts:
100-
| number
101-
| {duration?: number; action?: {label: string; run: () => void}} = 3000
101+
durationOrOpts: number | {duration?: number; action?: ToastAction} = 3000
102102
): void {
103103
const opts =
104104
typeof durationOrOpts === 'number'
@@ -114,7 +114,7 @@ export function showToast(
114114
}, duration);
115115
}
116116

117-
export function getToastAction(): {label: string; run: () => void} | null {
117+
export function getToastAction(): ToastAction | null {
118118
return toastAction;
119119
}
120120

0 commit comments

Comments
 (0)