Skip to content

Commit

Permalink
Explain to user why the subtitle track selector auto-opens sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
killergerbah committed Sep 24, 2024
1 parent 94af60e commit 0dad032
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 14 deletions.
1 change: 1 addition & 0 deletions common/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"videoDataSync": {
"emptySubtitleTrack": "Empty",
"loadSubtitlesFirst": "Untertitel müssen ausgewählt werden",
"failedToAutoLoad": "Could not auto-load subtitles in your preferred language.",
"rememberTrackPreference": "Remember these track choices for this site",
"selectSubtitles": "Untertitel auswählen",
"subtitleTrack": "Untertitelspur",
Expand Down
1 change: 1 addition & 0 deletions common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"videoDataSync": {
"emptySubtitleTrack": "Empty",
"loadSubtitlesFirst": "Subtitles must be loaded before you can start mining.",
"failedToAutoLoad": "Could not auto-load subtitles in your preferred language.",
"rememberTrackPreference": "Remember these track choices for this site",
"selectSubtitles": "Select Subtitles",
"subtitleTrack": "Subtitle Track",
Expand Down
1 change: 1 addition & 0 deletions common/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"videoDataSync": {
"emptySubtitleTrack": "En Blanco",
"loadSubtitlesFirst": "Deben cargarse los subtítulos antes de comenzar a minar",
"failedToAutoLoad": "Could not auto-load subtitles in your preferred language.",
"rememberTrackPreference": "Recordar estas opciones de pista para este sitio",
"selectSubtitles": "Seleccionar Subtítulos",
"subtitleTrack": "Pista de Subtítulos",
Expand Down
1 change: 1 addition & 0 deletions common/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"videoDataSync": {
"emptySubtitleTrack": "",
"loadSubtitlesFirst": "マイニングを開始する前に字幕をロードしてください。",
"failedToAutoLoad": "Could not auto-load subtitles in your preferred language.",
"rememberTrackPreference": "字幕トラックの選択を記憶する",
"selectSubtitles": "字幕を選択",
"subtitleTrack": "字幕トラック",
Expand Down
1 change: 1 addition & 0 deletions common/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"videoDataSync": {
"emptySubtitleTrack": "Pusta",
"loadSubtitlesFirst": "Napisy muszą być załadowane zanim zaczniesz kopać.",
"failedToAutoLoad": "Could not auto-load subtitles in your preferred language.",
"rememberTrackPreference": "Zapamiętaj ustawienia ścieżek dla tej strony",
"selectSubtitles": "Wybierz napisy",
"subtitleTrack": "Ścieżka napisów",
Expand Down
1 change: 1 addition & 0 deletions common/locales/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"videoDataSync": {
"emptySubtitleTrack": "Vazio",
"loadSubtitlesFirst": "Legendas devem ser carregadas antes que você possa começar a minerar.",
"failedToAutoLoad": "Could not auto-load subtitles in your preferred language.",
"rememberTrackPreference": "Lembrar dessas escolhas de faixa para este site",
"selectSubtitles": "Selecionar legenda",
"subtitleTrack": "Selecionar faixa",
Expand Down
1 change: 1 addition & 0 deletions common/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"videoDataSync": {
"emptySubtitleTrack": "Пусто",
"loadSubtitlesFirst": "Прежде чем начать майнинг, надо загрузить субтитры",
"failedToAutoLoad": "Could not auto-load subtitles in your preferred language.",
"rememberTrackPreference": "Запомнить мой выбор дорожек для этого сайта",
"selectSubtitles": "Выбрать субтитры",
"subtitleTrack": "Выбрать дорожку субтитров",
Expand Down
1 change: 1 addition & 0 deletions common/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"videoDataSync": {
"emptySubtitleTrack": "空的",
"loadSubtitlesFirst": "必须先加载字幕,然后才能开始挖掘。",
"failedToAutoLoad": "Could not auto-load subtitles in your preferred language.",
"rememberTrackPreference": "Remember these track choices for this site",
"selectSubtitles": "选择字幕",
"subtitleTrack": "字幕轨道",
Expand Down
8 changes: 7 additions & 1 deletion common/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ export interface VideoData {
subtitles?: VideoDataSubtitleTrack[];
}

export enum VideoDataUiOpenReason {
miningCommand = 1,
failedToAutoLoadPreferredTrack = 2,
userRequested = 3,
}

export interface VideoDataUiModel {
open?: boolean;
isLoading?: boolean;
Expand All @@ -164,7 +170,7 @@ export interface VideoDataUiModel {
themeType?: string;
selectedSubtitle?: string[];
showSubSelect?: boolean;
openedFromMiningCommand?: boolean;
openReason?: VideoDataUiOpenReason;
defaultCheckboxState?: boolean;
}

Expand Down
12 changes: 8 additions & 4 deletions extension/src/controllers/video-data-sync-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
VideoDataUiBridgeConfirmMessage,
VideoDataUiBridgeOpenFileMessage,
VideoDataUiModel,
VideoDataUiOpenReason,
VideoToExtensionCommand,
} from '@project/common';
import { AsbplayerSettings, SettingsProvider, SubtitleListPreference } from '@project/common/settings';
Expand Down Expand Up @@ -38,7 +39,7 @@ async function html(lang: string) {
}

interface ShowOptions {
openedFromMiningCommand: boolean;
reason: VideoDataUiOpenReason;
}

const fetchDataForLanguageOnDemand = (language: string): Promise<VideoData> => {
Expand Down Expand Up @@ -126,9 +127,12 @@ export default class VideoDataSyncController {
document.dispatchEvent(new CustomEvent('asbplayer-get-synced-data'));
}

async show({ openedFromMiningCommand }: ShowOptions) {
async show({ reason }: ShowOptions) {
const client = await this._client();
const model = await this._buildModel({ open: true, openedFromMiningCommand });
const model = await this._buildModel({
open: true,
openReason: reason,
});
this._prepareShow();
client.updateState(model);
}
Expand Down Expand Up @@ -227,7 +231,7 @@ export default class VideoDataSyncController {
this._hideAndResume();
}
} else {
await this.show({ openedFromMiningCommand: false });
await this.show({ reason: VideoDataUiOpenReason.failedToAutoLoadPreferredTrack });
}
}
} else if (this._frame.clientIfLoaded !== undefined) {
Expand Down
5 changes: 4 additions & 1 deletion extension/src/services/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
SubtitleModel,
SubtitlesToVideoMessage,
TakeScreenshotFromExtensionMessage,
VideoDataUiOpenReason,
VideoDisappearedMessage,
VideoHeartbeatMessage,
VideoToExtensionCommand,
Expand Down Expand Up @@ -1250,7 +1251,9 @@ export default class Binding {
}

showVideoDataDialog(openedFromMiningCommand: boolean) {
this.videoDataSyncController.show({ openedFromMiningCommand });
this.videoDataSyncController.show({
reason: openedFromMiningCommand ? VideoDataUiOpenReason.miningCommand : VideoDataUiOpenReason.userRequested,
});
}

async cropAndResize(tabImageDataUrl: string): Promise<string> {
Expand Down
11 changes: 7 additions & 4 deletions extension/src/ui/components/VideoDataSyncDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Typography from '@material-ui/core/Typography';
import makeStyles from '@material-ui/styles/makeStyles';
import Switch from '@material-ui/core/Switch';
import LabelWithHoverEffect from '@project/common/components/LabelWithHoverEffect';
import { ConfirmedVideoDataSubtitleTrack, VideoDataSubtitleTrack } from '@project/common';
import { ConfirmedVideoDataSubtitleTrack, VideoDataSubtitleTrack, VideoDataUiOpenReason } from '@project/common';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';

Expand Down Expand Up @@ -55,7 +55,7 @@ interface Props {
selectedSubtitleTrackIds: string[];
defaultCheckboxState: boolean;
error: string;
openedFromMiningCommand: boolean;
openReason: VideoDataUiOpenReason;
onCancel: () => void;
onOpenFile: () => void;
onConfirm: (track: ConfirmedVideoDataSubtitleTrack[], shouldRememberTrackChoices: boolean) => void;
Expand All @@ -71,7 +71,7 @@ export default function VideoDataSyncDialog({
selectedSubtitleTrackIds,
defaultCheckboxState,
error,
openedFromMiningCommand,
openReason,
onCancel,
onOpenFile,
onConfirm,
Expand Down Expand Up @@ -219,9 +219,12 @@ export default function VideoDataSyncDialog({
)}
</Toolbar>
<DialogContent>
{openedFromMiningCommand && (
{openReason === VideoDataUiOpenReason.miningCommand && (
<DialogContentText>{t('extension.videoDataSync.loadSubtitlesFirst')}</DialogContentText>
)}
{openReason === VideoDataUiOpenReason.failedToAutoLoadPreferredTrack && (
<DialogContentText>{t('extension.videoDataSync.failedToAutoLoad')}</DialogContentText>
)}
<form>
<Grid container direction="column" spacing={2}>
<Grid item>
Expand Down
9 changes: 5 additions & 4 deletions extension/src/ui/components/VideoDataSyncUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
VideoDataUiBridgeConfirmMessage,
VideoDataUiBridgeOpenFileMessage,
VideoDataUiModel,
VideoDataUiOpenReason,
} from '@project/common';
import { createTheme } from '@project/common/theme';
import { PaletteType } from '@material-ui/core';
Expand All @@ -37,7 +38,7 @@ export default function VideoDataSyncUi({ bridge }: Props) {
]);
const [selectedSubtitleTrackIds, setSelectedSubtitleTrackIds] = useState<string[]>(initialTrackIds);
const [defaultCheckboxState, setDefaultCheckboxState] = useState<boolean>(false);
const [openedFromMiningCommand, setOpenedFromMiningCommand] = useState<boolean>(false);
const [openReason, setOpenReason] = useState<VideoDataUiOpenReason>(VideoDataUiOpenReason.userRequested);
const [error, setError] = useState<string>('');
const [themeType, setThemeType] = useState<string>();

Expand Down Expand Up @@ -110,8 +111,8 @@ export default function VideoDataSyncUi({ bridge }: Props) {
setThemeType(model.themeType);
}

if (model.openedFromMiningCommand !== undefined) {
setOpenedFromMiningCommand(model.openedFromMiningCommand);
if (model.openReason !== undefined) {
setOpenReason(model.openReason);
}
});
}, [bridge, t]);
Expand Down Expand Up @@ -159,7 +160,7 @@ export default function VideoDataSyncUi({ bridge }: Props) {
subtitleTracks={subtitles}
selectedSubtitleTrackIds={selectedSubtitleTrackIds}
defaultCheckboxState={defaultCheckboxState}
openedFromMiningCommand={openedFromMiningCommand}
openReason={openReason}
error={error}
onCancel={handleCancel}
onOpenFile={handleOpenFile}
Expand Down

0 comments on commit 0dad032

Please sign in to comment.