From 0fbeaaf6237b62d5220da0418d05cae4487f29bf Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 12 Feb 2024 08:55:11 -0800 Subject: feat(settings): settings sync --- src/stores/settings.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/stores/settings.ts') diff --git a/src/stores/settings.ts b/src/stores/settings.ts index 5c27c516..e92d4150 100644 --- a/src/stores/settings.ts +++ b/src/stores/settings.ts @@ -1,5 +1,7 @@ import { browser } from '$app/environment'; -import { writable } from 'svelte/store'; +import root from '$lib/Utility/root'; +import { get, writable } from 'svelte/store'; +import settingsSyncPulled from './settingsSyncPulled'; export interface Settings { cacheMangaMinutes: number; @@ -48,6 +50,7 @@ export interface Settings { displayScheduleListMode: boolean; displayLanguage: 'en' | 'ja'; displayDisableLastActivityWarning: boolean; + settingsSync: boolean; } const defaultSettings: Settings = { @@ -91,7 +94,10 @@ const defaultSettings: Settings = { // Cache cacheMangaMinutes: 120, - cacheMinutes: 30 + cacheMinutes: 30, + + // Sync + settingsSync: false }; const createStore = () => { @@ -134,6 +140,14 @@ const settings = createStore(); settings.subscribe((value) => { if (browser) localStorage.setItem('settings', JSON.stringify(value)); + + if (value.settingsSync && get(settingsSyncPulled) == true) + fetch(root(`/api/configuration`), { + method: 'PUT', + body: JSON.stringify(value) + }).then((response) => { + if (response.ok) console.log('Pushed local configuration'); + }); }); export default settings; -- cgit v1.2.3