From ec10019bfaae72ee27c3a8a2be7d9ac3895089cf Mon Sep 17 00:00:00 2001 From: jj Date: Wed, 30 Oct 2024 12:11:21 +0000 Subject: [PATCH] web/settings: fix types, migrate old settings from v2 --- web/src/lib/state/settings.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/web/src/lib/state/settings.ts b/web/src/lib/state/settings.ts index c7f64e5d..0b69b86e 100644 --- a/web/src/lib/state/settings.ts +++ b/web/src/lib/state/settings.ts @@ -1,11 +1,10 @@ import { derived, readable, type Updater } from 'svelte/store'; import { browser } from '$app/environment'; import { merge } from 'ts-deepmerge'; - import type { - CobaltSettings, PartialSettings, - AllPartialSettingsWithSchema + AllPartialSettingsWithSchema, + CobaltSettings } from '../types/settings'; import { migrateOldSettings } from '../settings/migrate'; @@ -39,7 +38,7 @@ const migrate = (settings: AllPartialSettingsWithSchema): PartialSettings => { .filter(version => version > settings.schemaVersion) .reduce((settings, migrationVersion) => { return migrations[migrationVersion](settings); - }, settings as AllPartialSettingsWithSchema); + }, settings as AllPartialSettingsWithSchema) as PartialSettings; } @@ -51,7 +50,7 @@ const loadFromStorage = () => { if (!settings) { const migrated = migrateOldSettings(); if (migrated) { - return writeToStorage(migrated); + return writeToStorage(migrate(migrated)); } return {}; @@ -60,7 +59,7 @@ const loadFromStorage = () => { return loadFromString(settings); } -export const loadFromString = (settings: string) => { +export const loadFromString = (settings: string): PartialSettings => { const parsed = JSON.parse(settings) as AllPartialSettingsWithSchema; if (parsed.schemaVersion < defaultSettings.schemaVersion) { return migrate(parsed);