mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
web/settings: add version 3 of setting schema
This commit is contained in:
parent
ec10019bfa
commit
cafe05d5fb
4 changed files with 33 additions and 7 deletions
|
@ -2,7 +2,7 @@ import { defaultLocale } from "$lib/i18n/translations";
|
|||
import type { CobaltSettings } from "$lib/types/settings";
|
||||
|
||||
const defaultSettings: CobaltSettings = {
|
||||
schemaVersion: 2,
|
||||
schemaVersion: 3,
|
||||
advanced: {
|
||||
debug: false,
|
||||
},
|
||||
|
|
|
@ -4,11 +4,13 @@ import { merge } from 'ts-deepmerge';
|
|||
import type {
|
||||
PartialSettings,
|
||||
AllPartialSettingsWithSchema,
|
||||
CobaltSettings
|
||||
CobaltSettings,
|
||||
CobaltSettingsV3
|
||||
} from '../types/settings';
|
||||
|
||||
import { getBrowserLanguage } from '$lib/settings/youtube-lang';
|
||||
import { migrateOldSettings } from '../settings/migrate';
|
||||
import defaultSettings from '../settings/defaults';
|
||||
import type { RecursivePartial } from '$lib/types/generic';
|
||||
|
||||
const updatePlausiblePreference = (settings: PartialSettings) => {
|
||||
if (settings.privacy?.disableAnalytics) {
|
||||
|
@ -29,7 +31,20 @@ const writeToStorage = (settings: PartialSettings) => {
|
|||
|
||||
type Migrator = (s: AllPartialSettingsWithSchema) => AllPartialSettingsWithSchema;
|
||||
const migrations: Record<number, Migrator> = {
|
||||
[3]: (settings: AllPartialSettingsWithSchema) => {
|
||||
const out = settings as RecursivePartial<CobaltSettingsV3>;
|
||||
out.schemaVersion = 3;
|
||||
|
||||
if (settings?.save && 'youtubeDubBrowserLang' in settings.save) {
|
||||
if (settings.save.youtubeDubBrowserLang) {
|
||||
out.save!.youtubeDubLang = getBrowserLanguage();
|
||||
}
|
||||
|
||||
delete settings.save.youtubeDubBrowserLang;
|
||||
}
|
||||
|
||||
return out as AllPartialSettingsWithSchema;
|
||||
}
|
||||
}
|
||||
|
||||
const migrate = (settings: AllPartialSettingsWithSchema): PartialSettings => {
|
||||
|
@ -65,7 +80,7 @@ export const loadFromString = (settings: string): PartialSettings => {
|
|||
return migrate(parsed);
|
||||
}
|
||||
|
||||
return parsed;
|
||||
return parsed as PartialSettings;
|
||||
}
|
||||
|
||||
let update: (_: Updater<PartialSettings>) => void;
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import type { RecursivePartial } from "$lib/types/generic";
|
||||
import type { CobaltSettingsV2 } from "./settings/v2";
|
||||
import type { CobaltSettingsV3 } from "./settings/v3";
|
||||
|
||||
export * from "./settings/v2";
|
||||
export * from "./settings/v3";
|
||||
|
||||
export type CobaltSettings = CobaltSettingsV2;
|
||||
export type CobaltSettings = CobaltSettingsV3;
|
||||
|
||||
export type AnyCobaltSettings = CobaltSettings;
|
||||
export type AnyCobaltSettings = CobaltSettingsV2 | CobaltSettings;
|
||||
|
||||
export type PartialSettings = RecursivePartial<CobaltSettings>;
|
||||
|
||||
|
|
9
web/src/lib/types/settings/v3.ts
Normal file
9
web/src/lib/types/settings/v3.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import type { YoutubeLang } from "$lib/settings/youtube-lang";
|
||||
import { type CobaltSettingsV2 } from "./v2";
|
||||
|
||||
export type CobaltSettingsV3 = Omit<CobaltSettingsV2, 'schemaVersion' | 'save'> & {
|
||||
schemaVersion: 3,
|
||||
save: Omit<CobaltSettingsV2['save'], 'youtubeDubBrowserLang'> & {
|
||||
youtubeDubLang: YoutubeLang;
|
||||
};
|
||||
};
|
Loading…
Reference in a new issue