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