Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostMinePlayback preference #415

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/app/services/video-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ export default class VideoChannel {
maxImageHeight,
surroundingSubtitlesCountRadius,
surroundingSubtitlesTimeRadius,
clickToMineDefaultPlayback,
} = settings;
const message: AnkiSettingsToVideoMessage = {
command: 'ankiSettings',
Expand All @@ -509,6 +510,7 @@ export default class VideoChannel {
maxImageHeight,
surroundingSubtitlesCountRadius,
surroundingSubtitlesTimeRadius,
clickToMineDefaultPlayback,
},
};
this.protocol.postMessage(message);
Expand Down
47 changes: 46 additions & 1 deletion common/components/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import RefreshIcon from '@material-ui/icons/Refresh';
import Select from '@material-ui/core/Select';
import TextField from '@material-ui/core/TextField';
import { Theme } from '@material-ui/core/styles';
import { AutoPausePreference, PostMineAction } from '@project/common';
import { AutoPausePreference, PostMineAction, PostMinePlayback } from '@project/common';
import { AsbplayerSettings, KeyBindName, SubtitleListPreference } from '@project/common/settings';
import { computeStyles, download, isNumeric } from '@project/common/util';
import { CustomStyle, validateSettings } from '@project/common/settings';
Expand Down Expand Up @@ -687,6 +687,7 @@ export default function SettingsForm({
fastForwardModePlaybackRate,
keyBindSet,
clickToMineDefaultAction,
clickToMineDefaultPlayback,
preferMp3,
miningHistoryStorageLimit,
preCacheSubtitleDom,
Expand Down Expand Up @@ -1163,6 +1164,50 @@ export default function SettingsForm({
label={t('postMineAction.none')}
/>
</RadioGroup>
<FormLabel className={classes.top} component="legend">
{t('settings.postMinePlayback')}
</FormLabel>
<RadioGroup row={false}>
<LabelWithHoverEffect
control={
<Radio
checked={clickToMineDefaultPlayback === PostMinePlayback.remember}
value={PostMinePlayback.remember}
onChange={(event) =>
event.target.checked &&
handleSettingChanged('clickToMineDefaultPlayback', PostMinePlayback.remember)
}
/>
}
label={t('postMinePlayback.remember')}
/>
<LabelWithHoverEffect
control={
<Radio
checked={clickToMineDefaultPlayback === PostMinePlayback.play}
value={PostMinePlayback.play}
onChange={(event) =>
event.target.checked &&
handleSettingChanged('clickToMineDefaultPlayback', PostMinePlayback.play)
}
/>
}
label={t('postMinePlayback.play')}
/>
<LabelWithHoverEffect
control={
<Radio
checked={clickToMineDefaultPlayback === PostMinePlayback.pause}
value={PostMinePlayback.pause}
onChange={(event) =>
event.target.checked &&
handleSettingChanged('clickToMineDefaultPlayback', PostMinePlayback.pause)
}
/>
}
label={t('postMinePlayback.pause')}
/>
</RadioGroup>
<FormGroup className={classes.formGroup}>
<LabelWithHoverEffect
control={
Expand Down
6 changes: 6 additions & 0 deletions common/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"updateLastCard": "Update last card",
"exportCard": "Export card"
},
"postMinePlayback": {
"remember": "Keep previous state (as before mining)",
"play": "Always play",
"paused": "Always pause"
},
"ankiDialog": {
"applySelection": "Auswahl anwenden",
"audio": "Audio",
Expand Down Expand Up @@ -269,6 +274,7 @@
"mining": "Extraktion",
"miningHistoryStorageLimit": "Extraktions-Historie Speicherlimit",
"clickToMineDefaultAction": "Mining button default action",
"clickToMineDefaultPlayback": "Play mode to use after subtitle has been mined",
"misc": "Sonstige",
"mp3Preference": "Audio in MP3 neu encoden (langsamer)",
"noteType": "Notiztyp",
Expand Down
6 changes: 6 additions & 0 deletions common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"updateLastCard": "Update last card",
"exportCard": "Export card"
},
"postMinePlayback": {
"remember": "Keep previous state (as before mining)",
"play": "Always play",
"paused": "Always pause"
},
"ankiDialog": {
"applySelection": "Apply Selection",
"audio": "Audio",
Expand Down Expand Up @@ -269,6 +274,7 @@
"mining": "Mining",
"miningHistoryStorageLimit": "Mining history storage limit",
"clickToMineDefaultAction": "Mining button default action",
"clickToMineDefaultPlayback": "Play mode to use after subtitle has been mined",
"misc": "Misc",
"mp3Preference": "Re-encode audio as mp3 (slower)",
"noteType": "Note Type",
Expand Down
6 changes: 6 additions & 0 deletions common/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"updateLastCard": "Actualizar última tarjeta",
"exportCard": "Export card"
},
"postMinePlayback": {
"remember": "Keep previous state (as before mining)",
"play": "Always play",
"paused": "Always pause"
},
"ankiDialog": {
"applySelection": "Aplicar Selección",
"audio": "Audio",
Expand Down Expand Up @@ -269,6 +274,7 @@
"mining": "Minado",
"miningHistoryStorageLimit": "Límite de almacenamiento del historial de minado",
"clickToMineDefaultAction": "Acción por defecto del botón de minado",
"clickToMineDefaultPlayback": "Play mode to use after subtitle has been mined",
"misc": "Otros",
"mp3Preference": "Recodificar audio como MP3 (más lento)",
"noteType": "Tipo de Nota",
Expand Down
6 changes: 6 additions & 0 deletions common/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"updateLastCard": "最後のカードを更新する",
"exportCard": "カードをエクスポート"
},
"postMinePlayback": {
"remember": "Keep previous state (as before mining)",
"play": "Always play",
"paused": "Always pause"
},
"ankiDialog": {
"applySelection": "選択範囲を適用する",
"audio": "音声",
Expand Down Expand Up @@ -269,6 +274,7 @@
"mining": "マイニング",
"miningHistoryStorageLimit": "マイニング履歴の保存数上限",
"clickToMineDefaultAction": "ボタンでマイニングした際のデフォルト動作",
"clickToMineDefaultPlayback": "Play mode to use after subtitle has been mined",
"misc": "その他",
"mp3Preference": "音声を mp3 形式で再録音(低速)",
"noteType": "メモタイプ",
Expand Down
6 changes: 6 additions & 0 deletions common/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"updateLastCard": "Update last card",
"exportCard": "Export card"
},
"postMinePlayback": {
"remember": "Keep previous state (as before mining)",
"play": "Always play",
"paused": "Always pause"
},
"ankiDialog": {
"applySelection": "Zastosuj wybór",
"audio": "Audio",
Expand Down Expand Up @@ -269,6 +274,7 @@
"mining": "Kopanie",
"miningHistoryStorageLimit": "Limit przechowywania historii kopania",
"clickToMineDefaultAction": "Mining button default action",
"clickToMineDefaultPlayback": "Play mode to use after subtitle has been mined",
"misc": "Różne",
"mp3Preference": "Ponowne kodowanie dźwięku do formatu mp3 (wolniejsze)",
"noteType": "Typ notatek",
Expand Down
6 changes: 6 additions & 0 deletions common/locales/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"updateLastCard": "Atualizar último card",
"exportCard": "Export card"
},
"postMinePlayback": {
"remember": "Manter o estado anterior (como antes da mineração)",
"play": "Sempre reproduzir",
"paused": "Sempre pausado"
},
"ankiDialog": {
"applySelection": "Aplicar seleção",
"audio": "Áudio",
Expand Down Expand Up @@ -269,6 +274,7 @@
"mining": "Mineração",
"miningHistoryStorageLimit": "Limite de armazenamento do histórico de mineração",
"clickToMineDefaultAction": "Ação padrão do botão de mineração",
"clickToMineDefaultPlayback": "Modo de reprodução a ser usado depois de mineração",
"misc": "Diversos",
"mp3Preference": "Recodificar áudio como MP3 (mais lento)",
"noteType": "Tipo de nota",
Expand Down
6 changes: 6 additions & 0 deletions common/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"updateLastCard": "Обновить последнюю карточку",
"exportCard": "Export card"
},
"postMinePlayback": {
"remember": "Keep previous state (as before mining)",
"play": "Always play",
"paused": "Always pause"
},
"ankiDialog": {
"applySelection": "Применить выбор",
"audio": "Аудио",
Expand Down Expand Up @@ -269,6 +274,7 @@
"mining": "Майнинг",
"miningHistoryStorageLimit": "Лимит хранения истории майнинга",
"clickToMineDefaultAction": "Стандартное действие кнопки майнинга",
"clickToMineDefaultPlayback": "Play mode to use after subtitle has been mined",
"misc": "Разное",
"mp3Preference": "Перекодировать аудио в MP3 (медленнее)",
"noteType": "Тип анки-заметки",
Expand Down
6 changes: 6 additions & 0 deletions common/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"updateLastCard": "Update last card",
"exportCard": "Export card"
},
"postMinePlayback": {
"remember": "Keep previous state (as before mining)",
"play": "Always play",
"paused": "Always pause"
},
"ankiDialog": {
"applySelection": "应用选中时间范围",
"audio": "音频",
Expand Down Expand Up @@ -269,6 +274,7 @@
"mining": "挖掘",
"miningHistoryStorageLimit": "挖掘历史存储限制",
"clickToMineDefaultAction": "Mining button default action",
"clickToMineDefaultPlayback": "Play mode to use after subtitle has been mined",
"misc": "杂项",
"mp3Preference": "将音频重新编码为mp3(较慢)",
"noteType": "Anki卡牌类型",
Expand Down
1 change: 1 addition & 0 deletions common/settings/settings-import-export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ it('validates exported settings', () => {
miningHistoryStorageLimit: 25,
preCacheSubtitleDom: true,
clickToMineDefaultAction: 1,
clickToMineDefaultPlayback: 0,
themeType: 'dark',
copyToClipboardOnMine: false,
rememberSubtitleOffset: true,
Expand Down
3 changes: 3 additions & 0 deletions common/settings/settings-import-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ const settingsSchema = {
clickToMineDefaultAction: {
type: 'number',
},
clickToMineDefaultPlayback: {
type: 'number',
},
themeType: {
type: 'string',
},
Expand Down
3 changes: 2 additions & 1 deletion common/settings/settings-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AsbplayerSettings, KeyBindName, SubtitleListPreference } from '.';
import { AutoPausePreference, PostMineAction } from '..';
import { AutoPausePreference, PostMineAction, PostMinePlayback } from '..';

// @ts-ignore
const isMacOs = (navigator.userAgentData?.platform ?? navigator.platform)?.toUpperCase()?.indexOf('MAC') > -1;
Expand Down Expand Up @@ -72,6 +72,7 @@ export const defaultSettings: AsbplayerSettings = {
miningHistoryStorageLimit: 25,
preCacheSubtitleDom: true,
clickToMineDefaultAction: PostMineAction.showAnkiDialog,
clickToMineDefaultPlayback: PostMinePlayback.remember,
themeType: 'dark',
copyToClipboardOnMine: false,
rememberSubtitleOffset: true,
Expand Down
4 changes: 3 additions & 1 deletion common/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AutoPausePreference, PostMineAction } from '../src/model';
import { AutoPausePreference, PostMineAction, PostMinePlayback } from '../src/model';

export interface MiscSettings {
readonly themeType: 'dark' | 'light';
Expand Down Expand Up @@ -39,6 +39,7 @@ export interface AnkiSettings {
readonly maxImageHeight: number;
readonly surroundingSubtitlesCountRadius: number;
readonly surroundingSubtitlesTimeRadius: number;
readonly clickToMineDefaultPlayback: PostMinePlayback;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now the settings categorization does seem somewhat arbitrary but I think I would still prefer for this setting to be under MiscSettings.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name this setting something else since it applies even when not clicking to mine.


const ankiSettingsKeysObject: { [key in keyof AnkiSettings]: boolean } = {
Expand All @@ -61,6 +62,7 @@ const ankiSettingsKeysObject: { [key in keyof AnkiSettings]: boolean } = {
maxImageHeight: true,
surroundingSubtitlesCountRadius: true,
surroundingSubtitlesTimeRadius: true,
clickToMineDefaultPlayback: true,
};

export const ankiSettingsKeys: (keyof AnkiSettings)[] = Object.keys(ankiSettingsKeysObject) as (keyof AnkiSettings)[];
Expand Down
6 changes: 6 additions & 0 deletions common/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ export enum PostMineAction {
exportCard = 3,
}

export enum PostMinePlayback {
remember = 0,
play = 1,
pause = 2,
}

export enum AutoPausePreference {
atStart = 1,
atEnd = 2,
Expand Down
27 changes: 19 additions & 8 deletions extension/src/controllers/anki-ui-controller.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import {
AnkiUiBridgeRerecordMessage,
AnkiUiInitialState,
AnkiUiSavedState,
AnkiUiResumeState,
AnkiUiBridgeResumeMessage,
AnkiUiBridgeRewindMessage,
OpenAsbplayerSettingsMessage,
VideoToExtensionCommand,
AnkiUiInitialState,
AnkiUiResumeState,
AnkiUiSavedState,
CopyToClipboardMessage,
OpenAsbplayerSettingsMessage,
PostMinePlayback,
ShowAnkiUiMessage,
VideoToExtensionCommand,
} from '@project/common';
import { AnkiSettings } from '@project/common/settings';
import { sourceString } from '@project/common/util';
import Binding from '../services/binding';
import UiFrame from '../services/ui-frame';
import { fetchLocalization } from '../services/localization-fetcher';
import UiFrame from '../services/ui-frame';

// We need to write the HTML into the iframe manually so that the iframe keeps it's about:blank URL.
// Otherwise, Chrome won't insert content scripts into the iframe (e.g. Yomichan won't work).
Expand Down Expand Up @@ -248,8 +249,18 @@ export default class AnkiUiController {
}
}

if (context.wasPlayingBeforeRecordingMedia) {
context.play();
switch (this._ankiSettings?.clickToMineDefaultPlayback) {
case PostMinePlayback.remember:
if (context.wasPlayingBeforeRecordingMedia) {
context.play();
}
break;
case PostMinePlayback.play:
context.play();
break;
case PostMinePlayback.pause:
// already paused, don't need to do anything
break;
}
break;
case 'rewind':
Expand Down
Loading
Loading