fix migration

This commit is contained in:
frost768 2023-04-06 04:34:59 +03:00
parent 2178057633
commit 5d8f03b859
4 changed files with 13 additions and 1 deletions

View File

@ -230,7 +230,7 @@ registerProvider({
const sub = subtitle;
sub.subtitles = subtitle.subtitles.filter((subFile: any) => {
const extension = subFile.file_path.substring(
sub.file_path.length - 3
subFile.file_path.length - 3
);
return [MWCaptionType.SRT, MWCaptionType.VTT].includes(extension);
});

View File

@ -5,6 +5,7 @@ import { SettingsStore } from "./store";
import { MWSettingsData } from "./types";
interface MWSettingsDataSetters {
setLanguage(language: LangCode): void;
setCaptionLanguage(language: LangCode): void;
setCaptionDelay(delay: number): void;
setCaptionColor(color: string): void;
@ -21,6 +22,14 @@ export function SettingsProvider(props: { children: ReactNode }) {
const context: MWSettingsDataWrapper = useMemo(() => {
const settingsContext: MWSettingsDataWrapper = {
...settings,
setLanguage(language) {
setSettings((oldSettings) => {
return {
...oldSettings,
language,
};
});
},
setCaptionLanguage(language) {
setSettings((oldSettings) => {
const captionSettings = oldSettings.captionSettings;

View File

@ -20,6 +20,7 @@ export const SettingsStore = createVersionedStore<MWSettingsData>()
},
migrate(data: MWSettingsDataV1): MWSettingsData {
return {
language: data.language,
captionSettings: {
language: "none",
...data.captionSettings,
@ -31,6 +32,7 @@ export const SettingsStore = createVersionedStore<MWSettingsData>()
version: 1,
create(): MWSettingsData {
return {
language: "en",
captionSettings: {
delay: 0,
language: "none",

View File

@ -31,5 +31,6 @@ export interface MWSettingsDataV1 {
}
export interface MWSettingsData {
language: LangCode;
captionSettings: CaptionSettings;
}