mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
web/settings: fix types, migrate old settings from v2
This commit is contained in:
parent
bad59750bf
commit
ec10019bfa
1 changed files with 5 additions and 6 deletions
|
@ -1,11 +1,10 @@
|
||||||
import { derived, readable, type Updater } from 'svelte/store';
|
import { derived, readable, type Updater } from 'svelte/store';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { merge } from 'ts-deepmerge';
|
import { merge } from 'ts-deepmerge';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
CobaltSettings,
|
|
||||||
PartialSettings,
|
PartialSettings,
|
||||||
AllPartialSettingsWithSchema
|
AllPartialSettingsWithSchema,
|
||||||
|
CobaltSettings
|
||||||
} from '../types/settings';
|
} from '../types/settings';
|
||||||
|
|
||||||
import { migrateOldSettings } from '../settings/migrate';
|
import { migrateOldSettings } from '../settings/migrate';
|
||||||
|
@ -39,7 +38,7 @@ const migrate = (settings: AllPartialSettingsWithSchema): PartialSettings => {
|
||||||
.filter(version => version > settings.schemaVersion)
|
.filter(version => version > settings.schemaVersion)
|
||||||
.reduce((settings, migrationVersion) => {
|
.reduce((settings, migrationVersion) => {
|
||||||
return migrations[migrationVersion](settings);
|
return migrations[migrationVersion](settings);
|
||||||
}, settings as AllPartialSettingsWithSchema);
|
}, settings as AllPartialSettingsWithSchema) as PartialSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,7 +50,7 @@ const loadFromStorage = () => {
|
||||||
if (!settings) {
|
if (!settings) {
|
||||||
const migrated = migrateOldSettings();
|
const migrated = migrateOldSettings();
|
||||||
if (migrated) {
|
if (migrated) {
|
||||||
return writeToStorage(migrated);
|
return writeToStorage(migrate(migrated));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
@ -60,7 +59,7 @@ const loadFromStorage = () => {
|
||||||
return loadFromString(settings);
|
return loadFromString(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadFromString = (settings: string) => {
|
export const loadFromString = (settings: string): PartialSettings => {
|
||||||
const parsed = JSON.parse(settings) as AllPartialSettingsWithSchema;
|
const parsed = JSON.parse(settings) as AllPartialSettingsWithSchema;
|
||||||
if (parsed.schemaVersion < defaultSettings.schemaVersion) {
|
if (parsed.schemaVersion < defaultSettings.schemaVersion) {
|
||||||
return migrate(parsed);
|
return migrate(parsed);
|
||||||
|
|
Loading…
Reference in a new issue