web/settings: try to migrate settings if new format is not used yet

This commit is contained in:
dumbmoron 2024-07-13 20:39:40 +00:00
parent 5a630c2320
commit 436b735d2a
No known key found for this signature in database

View file

@ -4,6 +4,7 @@ import { merge } from 'ts-deepmerge';
import type { RecursivePartial } from '../types/generic';
import type { CobaltSettings } from '../types/settings';
import { migrateOldSettings } from '../settings/migrate';
import defaultSettings from '../settings/defaults';
type PartialSettings = RecursivePartial<CobaltSettings>;
@ -43,6 +44,11 @@ const migrate = (settings: PartialSettingsWithSchema) => {
const loadFromStorage = () => {
const settings = localStorage.getItem('settings');
if (!settings) {
const migrated = migrateOldSettings();
if (migrated) {
return writeToStorage(migrated);
}
return {};
}