diff --git a/src/scripts/settings.ts b/src/scripts/settings.ts index 6ff90873..439b9b35 100644 --- a/src/scripts/settings.ts +++ b/src/scripts/settings.ts @@ -1079,8 +1079,8 @@ function resetSettings(action: 'yes' | 'no' | 'first') { storage.sync.clear() storage.local.clear() - setTimeout(() => { - storage.sync.set({ ...getSyncDefaults() }) + setTimeout(async () => { + storage.sync.set({ ...(await getSyncDefaults()) }) storage.local.set({ ...LOCAL_DEFAULT }) fadeOut() }, 50) @@ -1098,7 +1098,7 @@ export function updateSettingsJSON(data?: Sync.Storage) { function updateTextArea(data: Sync.Storage) { const pre = document.getElementById('settings-data') - if (pre) { + if (pre && data.about) { data.about.browser = PLATFORM pre.textContent = orderedStringify(data) } diff --git a/src/scripts/storage.ts b/src/scripts/storage.ts index 4cbbb4b9..a6a8ee01 100644 --- a/src/scripts/storage.ts +++ b/src/scripts/storage.ts @@ -55,10 +55,11 @@ function verifyDataAsLocal(data: Keyval) { export async function getSyncDefaults(): Promise { try { - const json = await (await fetch('defaults.json')).json() + const json = await (await fetch('config.json')).json() return verifyDataAsSync(json) } catch (error) { - console.log('No defaults.json settings found') + //@ts-expect-error + console.log(error.stack) } return SYNC_DEFAULT @@ -137,10 +138,15 @@ function online(): Storage { } const init = async () => { + const config = await getSyncDefaults() const about = parse(localStorage.bonjourr)?.about + if (!localStorage.bonjourr) { + online().sync.set(config) + } + if (!about) { - online().sync.set({ about: SYNC_DEFAULT.about }) + online().sync.set({ about: config.about }) } return { @@ -212,6 +218,10 @@ function webext(): Storage { }) } + if (Object.keys(store.sync)?.length === 0) { + store.sync = await getSyncDefaults() + } + const sync = verifyDataAsSync(store.sync) const local = verifyDataAsLocal(store.local)