Vesktop/src/renderer/settings.ts

32 lines
941 B
TypeScript
Raw Normal View History

2023-04-09 22:49:50 +02:00
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
2023-04-10 01:16:44 +02:00
import { SettingsStore } from "shared/utils/SettingsStore";
2023-04-09 22:49:50 +02:00
2023-04-09 00:49:47 +02:00
import { Common } from "./vencord";
2023-04-10 03:26:55 +02:00
export const Settings = new SettingsStore(VencordDesktopNative.settings.get());
Settings.addGlobalChangeListener((o, p) => VencordDesktopNative.settings.set(o, p));
2023-04-09 00:49:47 +02:00
export function useSettings() {
const [, update] = Common.React.useReducer(x => x + 1, 0);
2023-04-10 01:04:41 +02:00
2023-04-09 00:49:47 +02:00
Common.React.useEffect(() => {
2023-04-10 01:04:41 +02:00
Settings.addGlobalChangeListener(update);
return () => Settings.removeGlobalChangeListener(update);
2023-04-09 00:49:47 +02:00
}, []);
2023-04-10 01:04:41 +02:00
return Settings.store;
2023-04-09 00:49:47 +02:00
}
2023-04-10 03:26:55 +02:00
export function getValueAndOnChange(key: keyof typeof Settings.store) {
2023-04-09 00:49:47 +02:00
return {
2023-04-10 03:26:55 +02:00
value: Settings.store[key] as any,
onChange: (value: any) => (Settings.store[key] = value)
2023-04-09 00:49:47 +02:00
};
}