Initial Settings UI work

This commit is contained in:
Vendicated
2023-04-09 00:49:47 +02:00
parent 8b68eef9a7
commit 7e0532444d
16 changed files with 169 additions and 37 deletions

28
src/renderer/settings.ts Normal file
View File

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