From d6c43986fd665b60a8a83d41ef907dab22e990e7 Mon Sep 17 00:00:00 2001 From: megumin Date: Fri, 4 Aug 2023 18:52:20 +0100 Subject: Add proper user-friendly theme manager (#635) Co-authored-by: Justice Almanzar Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Co-authored-by: V --- src/api/Settings.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/api') diff --git a/src/api/Settings.ts b/src/api/Settings.ts index 709050f..c380f63 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -34,6 +34,7 @@ export interface Settings { useQuickCss: boolean; enableReactDevtools: boolean; themeLinks: string[]; + enabledThemes: string[]; frameless: boolean; transparent: boolean; winCtrlQ: boolean; @@ -68,6 +69,7 @@ const DefaultSettings: Settings = { autoUpdateNotification: true, useQuickCss: true, themeLinks: [], + enabledThemes: [], enableReactDevtools: false, frameless: false, transparent: false, @@ -107,7 +109,7 @@ const saveSettingsOnFrequentAction = debounce(async () => { } }, 60_000); -type SubscriptionCallback = ((newValue: any, path: string) => void) & { _path?: string; }; +type SubscriptionCallback = ((newValue: any, path: string) => void) & { _paths?: Array; }; const subscriptions = new Set(); const proxyCache = {} as Record; @@ -164,7 +166,7 @@ function makeProxy(settings: any, root = settings, path = ""): Settings { const setPath = `${path}${path && "."}${p}`; delete proxyCache[setPath]; for (const subscription of subscriptions) { - if (!subscription._path || subscription._path === setPath) { + if (!subscription._paths || subscription._paths.includes(setPath)) { subscription(v, setPath); } } @@ -235,7 +237,7 @@ type ResolvePropDeep = P extends "" ? T : export function addSettingsListener(path: Path, onUpdate: (newValue: Settings[Path], path: Path) => void): void; export function addSettingsListener(path: Path, onUpdate: (newValue: Path extends "" ? any : ResolvePropDeep, path: Path extends "" ? string : Path) => void): void; export function addSettingsListener(path: string, onUpdate: (newValue: any, path: string) => void) { - (onUpdate as SubscriptionCallback)._path = path; + ((onUpdate as SubscriptionCallback)._paths ??= []).push(path); subscriptions.add(onUpdate); } -- cgit