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; const sub = subtitle;
sub.subtitles = subtitle.subtitles.filter((subFile: any) => { sub.subtitles = subtitle.subtitles.filter((subFile: any) => {
const extension = subFile.file_path.substring( const extension = subFile.file_path.substring(
sub.file_path.length - 3 subFile.file_path.length - 3
); );
return [MWCaptionType.SRT, MWCaptionType.VTT].includes(extension); return [MWCaptionType.SRT, MWCaptionType.VTT].includes(extension);
}); });

View File

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

View File

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

View File

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