diff --git a/frontend/src/ts/controllers/theme-controller.ts b/frontend/src/ts/controllers/theme-controller.ts index 95011cacb..6e12660c4 100644 --- a/frontend/src/ts/controllers/theme-controller.ts +++ b/frontend/src/ts/controllers/theme-controller.ts @@ -231,20 +231,27 @@ function updateFooterIndicator(nameOverride?: string): void { } } +type PreviewState = { + theme: string; + colors?: string[]; +} | null; + +let previewState: PreviewState = null; + export function preview( themeIdentifier: string, customColorsOverride?: string[] ): void { - debouncedPreview(themeIdentifier, customColorsOverride); + previewState = { theme: themeIdentifier, colors: customColorsOverride }; + debouncedPreview(); } -const debouncedPreview = debounce<(t: string, c?: string[]) => void>( - 250, - (themeIdenfitier, customColorsOverride) => { +const debouncedPreview = debounce<() => void>(250, () => { + if (previewState) { isPreviewingTheme = true; - void apply(themeIdenfitier, customColorsOverride, true); + void apply(previewState.theme, previewState.colors, true); } -); +}); async function set( themeIdentifier: string, @@ -264,6 +271,8 @@ async function set( } export async function clearPreview(applyTheme = true): Promise { + previewState = null; + if (isPreviewingTheme) { isPreviewingTheme = false; if (applyTheme) {