project-client/src/renderer/settings.ts

31 lines
927 B
TypeScript
Raw Normal View History

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