Rewrite settings proxy to proper store
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user