Files
SubMiner/src/core/utils/shortcut-config.ts
T
sudacode 2772c61aba feat: add mark-watched action, background app reuse, and N+1 compat
- Add `--mark-watched` CLI flag + mpv session binding; marks video watched, shows OSD, advances playlist
- Launcher detects running background app via `--app-ping` and borrows it instead of owning its lifecycle
- Preserve N+1 highlighting for existing configs with `knownWords.highlightEnabled` set
- Fix `resolveConfiguredShortcuts` to respect explicit `null` overrides (disabling defaults)
- Split session-help modal into focused modules (colors, render, sections, tabs)
2026-05-20 01:45:14 -07:00

70 lines
3.3 KiB
TypeScript

import { Config } from '../../types';
export interface ConfiguredShortcuts {
toggleVisibleOverlayGlobal: string | null | undefined;
copySubtitle: string | null | undefined;
copySubtitleMultiple: string | null | undefined;
updateLastCardFromClipboard: string | null | undefined;
triggerFieldGrouping: string | null | undefined;
triggerSubsync: string | null | undefined;
mineSentence: string | null | undefined;
mineSentenceMultiple: string | null | undefined;
multiCopyTimeoutMs: number;
toggleSecondarySub: string | null | undefined;
markAudioCard: string | null | undefined;
openCharacterDictionary: string | null | undefined;
openRuntimeOptions: string | null | undefined;
openJimaku: string | null | undefined;
openSessionHelp: string | null | undefined;
openControllerSelect: string | null | undefined;
openControllerDebug: string | null | undefined;
toggleSubtitleSidebar: string | null | undefined;
}
export function resolveConfiguredShortcuts(
config: Config,
defaultConfig: Config,
): ConfiguredShortcuts {
const isAnkiConnectDisabled = config.ankiConnect?.enabled === false;
type ShortcutKey = keyof Omit<ConfiguredShortcuts, 'multiCopyTimeoutMs'> &
keyof NonNullable<Config['shortcuts']>;
const normalizeShortcut = (value: string | null | undefined): string | null | undefined => {
if (typeof value !== 'string') return value;
return value.replace(/\bKey([A-Z])\b/g, '$1').replace(/\bDigit([0-9])\b/g, '$1');
};
const shortcutValue = (key: ShortcutKey): string | null | undefined =>
Object.prototype.hasOwnProperty.call(config.shortcuts ?? {}, key)
? config.shortcuts?.[key]
: defaultConfig.shortcuts?.[key];
return {
toggleVisibleOverlayGlobal: normalizeShortcut(shortcutValue('toggleVisibleOverlayGlobal')),
copySubtitle: normalizeShortcut(shortcutValue('copySubtitle')),
copySubtitleMultiple: normalizeShortcut(shortcutValue('copySubtitleMultiple')),
updateLastCardFromClipboard: normalizeShortcut(
isAnkiConnectDisabled ? null : shortcutValue('updateLastCardFromClipboard'),
),
triggerFieldGrouping: normalizeShortcut(
isAnkiConnectDisabled ? null : shortcutValue('triggerFieldGrouping'),
),
triggerSubsync: normalizeShortcut(shortcutValue('triggerSubsync')),
mineSentence: normalizeShortcut(isAnkiConnectDisabled ? null : shortcutValue('mineSentence')),
mineSentenceMultiple: normalizeShortcut(
isAnkiConnectDisabled ? null : shortcutValue('mineSentenceMultiple'),
),
multiCopyTimeoutMs:
config.shortcuts?.multiCopyTimeoutMs ?? defaultConfig.shortcuts?.multiCopyTimeoutMs ?? 5000,
toggleSecondarySub: normalizeShortcut(shortcutValue('toggleSecondarySub')),
markAudioCard: normalizeShortcut(isAnkiConnectDisabled ? null : shortcutValue('markAudioCard')),
openCharacterDictionary: normalizeShortcut(shortcutValue('openCharacterDictionary')),
openRuntimeOptions: normalizeShortcut(shortcutValue('openRuntimeOptions')),
openJimaku: normalizeShortcut(shortcutValue('openJimaku')),
openSessionHelp: normalizeShortcut(shortcutValue('openSessionHelp')),
openControllerSelect: normalizeShortcut(shortcutValue('openControllerSelect')),
openControllerDebug: normalizeShortcut(shortcutValue('openControllerDebug')),
toggleSubtitleSidebar: normalizeShortcut(shortcutValue('toggleSubtitleSidebar')),
};
}