2023-04-09 00:49:47 +02:00
|
|
|
import type { Settings as TSettings } from "shared/settings";
|
|
|
|
import { makeChangeListenerProxy } from "shared/utils/makeChangeListenerProxy";
|
|
|
|
import { Common } from "./vencord";
|
|
|
|
|
|
|
|
const signals = new Set<() => void>();
|
|
|
|
|
2023-04-09 01:20:00 +02:00
|
|
|
export const PlainSettings = VencordDesktopNative.settings.get() as TSettings;
|
2023-04-09 00:49:47 +02:00
|
|
|
export const Settings = makeChangeListenerProxy(PlainSettings, s => {
|
2023-04-09 01:20:00 +02:00
|
|
|
VencordDesktopNative.settings.set(s);
|
2023-04-09 00:49:47 +02:00
|
|
|
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
|
|
|
|
};
|
|
|
|
}
|