diff options
author | Lewis Crichton <lewi@lewisakura.moe> | 2023-04-07 01:27:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-07 02:27:18 +0200 |
commit | 97f8d4d5154d566568fc475d6aaba5db07399b2b (patch) | |
tree | feafd22c26bdfc37a2d787e60f52bec94e777636 /src/api | |
parent | 2672dea8e361e8216b9459ac5dac97d36a47e412 (diff) | |
download | Vencord-97f8d4d5154d566568fc475d6aaba5db07399b2b.tar.gz Vencord-97f8d4d5154d566568fc475d6aaba5db07399b2b.tar.bz2 Vencord-97f8d4d5154d566568fc475d6aaba5db07399b2b.zip |
feat: Cloud settings sync (#505)
Co-authored-by: Ven <vendicated@riseup.net>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/settings.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/api/settings.ts b/src/api/settings.ts index 321a4c4..8a7d9ff 100644 --- a/src/api/settings.ts +++ b/src/api/settings.ts @@ -16,9 +16,12 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { debounce } from "@utils/debounce"; import IpcEvents from "@utils/IpcEvents"; +import { localStorage } from "@utils/localStorage"; import Logger from "@utils/Logger"; import { mergeDefaults } from "@utils/misc"; +import { putCloudSettings } from "@utils/settingsSync"; import { DefinedSettings, OptionType, SettingsChecks, SettingsDefinition } from "@utils/types"; import { React } from "@webpack/common"; @@ -49,6 +52,13 @@ export interface Settings { useNative: "always" | "never" | "not-focused"; logLimit: number; }; + + cloud: { + authenticated: boolean; + url: string; + settingsSync: boolean; + settingsSyncVersion: number; + }; } const DefaultSettings: Settings = { @@ -69,6 +79,13 @@ const DefaultSettings: Settings = { position: "bottom-right", useNative: "not-focused", logLimit: 50 + }, + + cloud: { + authenticated: false, + url: "https://api.vencord.dev/", + settingsSync: false, + settingsSyncVersion: 0 } }; @@ -80,6 +97,13 @@ try { logger.error("An error occurred while loading the settings. Corrupt settings file?\n", err); } +const saveSettingsOnFrequentAction = debounce(async () => { + if (Settings.cloud.settingsSync && Settings.cloud.authenticated) { + await putCloudSettings(); + delete localStorage.Vencord_settingsDirty; + } +}, 60_000); + type SubscriptionCallback = ((newValue: any, path: string) => void) & { _path?: string; }; const subscriptions = new Set<SubscriptionCallback>(); @@ -142,6 +166,9 @@ function makeProxy(settings: any, root = settings, path = ""): Settings { } } // And don't forget to persist the settings! + PlainSettings.cloud.settingsSyncVersion = Date.now(); + localStorage.Vencord_settingsDirty = true; + saveSettingsOnFrequentAction(); VencordNative.ipc.invoke(IpcEvents.SET_SETTINGS, JSON.stringify(root, null, 4)); return true; } |