Rewrite settings proxy to proper store

This commit is contained in:
Vendicated
2023-04-10 01:04:41 +02:00
parent ddebb6563a
commit c2eaa9d35a
8 changed files with 90 additions and 58 deletions

View File

@@ -5,26 +5,23 @@
*/
import type { Settings as TSettings } from "shared/settings";
import { makeChangeListenerProxy } from "shared/utils/makeChangeListenerProxy";
import { SettingsStore } from "shared/utils/makeChangeListenerProxy";
import { Common } from "./vencord";
const signals = new Set<() => void>();
export const PlainSettings = VencordDesktopNative.settings.get() as TSettings;
export const Settings = makeChangeListenerProxy(PlainSettings, s => {
VencordDesktopNative.settings.set(s);
signals.forEach(fn => fn());
});
export const Settings = new SettingsStore(PlainSettings);
export function useSettings() {
const [, update] = Common.React.useReducer(x => x + 1, 0);
Common.React.useEffect(() => {
signals.add(update);
return () => signals.delete(update);
Settings.addGlobalChangeListener(update);
return () => Settings.removeGlobalChangeListener(update);
}, []);
return Settings;
return Settings.store;
}
export function getValueAndOnChange(key: keyof TSettings) {