mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-19 11:27:02 -04:00
rewrite settings api to use SettingsStore class (#2257)
Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com>
This commit is contained in:
parent
7190437e92
commit
9aa205b5ec
16 changed files with 336 additions and 180 deletions
|
@ -16,7 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { addSettingsListener, Settings } from "@api/Settings";
|
||||
import { Settings, SettingsStore } from "@api/Settings";
|
||||
|
||||
|
||||
let style: HTMLStyleElement;
|
||||
|
@ -81,10 +81,10 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
initThemes();
|
||||
|
||||
toggle(Settings.useQuickCss);
|
||||
addSettingsListener("useQuickCss", toggle);
|
||||
SettingsStore.addChangeListener("useQuickCss", toggle);
|
||||
|
||||
addSettingsListener("themeLinks", initThemes);
|
||||
addSettingsListener("enabledThemes", initThemes);
|
||||
SettingsStore.addChangeListener("themeLinks", initThemes);
|
||||
SettingsStore.addChangeListener("enabledThemes", initThemes);
|
||||
|
||||
if (!IS_WEB)
|
||||
VencordNative.quickCss.addThemeChangeListener(initThemes);
|
||||
|
|
|
@ -36,14 +36,14 @@ export async function importSettings(data: string) {
|
|||
|
||||
if ("settings" in parsed && "quickCss" in parsed) {
|
||||
Object.assign(PlainSettings, parsed.settings);
|
||||
await VencordNative.settings.set(JSON.stringify(parsed.settings, null, 4));
|
||||
await VencordNative.settings.set(parsed.settings);
|
||||
await VencordNative.quickCss.set(parsed.quickCss);
|
||||
} else
|
||||
throw new Error("Invalid Settings. Is this even a Vencord Settings file?");
|
||||
}
|
||||
|
||||
export async function exportSettings({ minify }: { minify?: boolean; } = {}) {
|
||||
const settings = JSON.parse(VencordNative.settings.get());
|
||||
const settings = VencordNative.settings.get();
|
||||
const quickCss = await VencordNative.quickCss.get();
|
||||
return JSON.stringify({ settings, quickCss }, null, minify ? undefined : 4);
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ export async function putCloudSettings(manual?: boolean) {
|
|||
|
||||
const { written } = await res.json();
|
||||
PlainSettings.cloud.settingsSyncVersion = written;
|
||||
VencordNative.settings.set(JSON.stringify(PlainSettings, null, 4));
|
||||
VencordNative.settings.set(PlainSettings);
|
||||
|
||||
cloudSettingsLogger.info("Settings uploaded to cloud successfully");
|
||||
|
||||
|
@ -222,7 +222,7 @@ export async function getCloudSettings(shouldNotify = true, force = false) {
|
|||
|
||||
// sync with server timestamp instead of local one
|
||||
PlainSettings.cloud.settingsSyncVersion = written;
|
||||
VencordNative.settings.set(JSON.stringify(PlainSettings, null, 4));
|
||||
VencordNative.settings.set(PlainSettings);
|
||||
|
||||
cloudSettingsLogger.info("Settings loaded from cloud successfully");
|
||||
if (shouldNotify)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue