mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-30 06:12:06 -07:00
Refactor startup, queries, and workflow into focused modules (#36)
* chore(backlog): add mining workflow milestone and tasks
* refactor: split character dictionary runtime modules
* refactor: split shared type entrypoints
* refactor: use bun serve for stats server
* feat: add repo-local subminer workflow plugin
* fix: add stats server node fallback
* refactor: split immersion tracker query modules
* chore: update backlog task records
* refactor: migrate shared type imports
* refactor: compose startup and setup window wiring
* Add backlog tasks and launcher time helper tests
- Track follow-up cleanup work in Backlog.md
- Replace Date.now usage with shared nowMs helper
- Add launcher args/parser and core regression tests
* test: increase launcher test timeout for CI stability
* fix: address CodeRabbit review feedback
* refactor(main): extract remaining inline runtime logic from main
* chore(backlog): update task notes and changelog fragment
* refactor: split main boot phases
* test: stabilize bun coverage reporting
* Switch plausible endpoint and harden coverage lane parsing
- update docs-site tracking to use the Plausible capture endpoint
- tighten coverage lane argument and LCOV parsing checks
- make script entrypoint use CommonJS main guard
* Restrict docs analytics and build coverage input
- limit Plausible init to docs.subminer.moe
- build Yomitan before src coverage lane
* fix(ci): normalize Windows shortcut paths for cross-platform tests
* Fix verification and immersion-tracker grouping
- isolate verifier artifacts and lease handling
- switch weekly/monthly tracker cutoffs to calendar boundaries
- tighten boot lifecycle and zip writer tests
* fix: resolve CI type failures in boot and immersion query tests
* fix: remove strict spread usage in Date mocks
* fix: use explicit super args for MockDate constructors
* Factor out mock date helper in tracker tests
- reuse a shared `withMockDate` helper for date-sensitive query tests
- make monthly rollup assertions key off `videoId` instead of row order
* fix: use variadic array type for MockDate constructor args
TS2367: fixed-length tuple made args.length === 0 unreachable.
* refactor: remove unused createMainBootRuntimes/Handlers aggregate functions
These functions were never called by production code — main.ts imports
the individual composeBoot* re-exports directly.
* refactor: remove boot re-export alias layer
main.ts now imports directly from the runtime/composers and runtime/domains
modules, eliminating the intermediate boot/ indirection.
* refactor: consolidate 3 near-identical setup window factories
Extract shared createSetupWindowHandler with a config parameter.
Public API unchanged.
* refactor: parameterize duplicated getAffected*Ids query helpers
Four structurally identical functions collapsed into two parameterized
helpers while preserving the existing public API.
* refactor: inline identity composers (stats-startup, overlay-window)
composeStatsStartupRuntime was a no-op that returned its input.
composeOverlayWindowHandlers was a 1-line delegation.
Both removed in favor of direct usage.
* chore: remove unused token/queue file path constants from main.ts
* fix: replace any types in boot services with proper signatures
* refactor: deduplicate ensureDir into shared/fs-utils
5 copies of mkdir-p-if-not-exists consolidated into one shared module
with ensureDir (directory path) and ensureDirForFile (file path) variants.
* fix: tighten type safety in boot services
- Add AppLifecycleShape and OverlayModalInputStateShape constraints
so TAppLifecycleApp and TOverlayModalInputState generics are bounded
- Remove unsafe `as { handleModalInputStateChange? }` cast — now
directly callable via the constraint
- Use `satisfies AppLifecycleShape` for structural validation on the
appLifecycleApp object literal
- Document Electron App.on incompatibility with simple signatures
* refactor: inline subtitle-prefetch-runtime-composer
The composer was a pure pass-through that destructured an object and
reassembled it with the same fields. Inlined at the call site.
* chore: consolidate duplicate import paths in main.ts
* test: extract mpv composer test fixture factory to reduce duplication
* test: add behavioral assertions to composer tests
Upgrade 8 composer test files from shape-only typeof checks to behavioral
assertions that invoke returned handlers and verify injected dependencies are
actually called, following the mpv-runtime-composer pattern.
* refactor: normalize import extensions in query modules
* refactor: consolidate toDbMs into query-shared.ts
* refactor: remove Node.js fallback from stats-server, use Bun only
* Fix monthly rollup test expectations
- Preserve multi-arg Date construction in mock helper
- Align rollup assertions with the correct videoId
* fix: address PR 36 CodeRabbit follow-ups
* fix: harden coverage lane cleanup
* fix(stats): fallback to node server when Bun.serve unavailable
* fix(ci): restore coverage lane compatibility
* chore(backlog): close TASK-242
* fix: address latest CodeRabbit review round
* fix: guard disabled immersion retention windows
* fix: migrate discord rpc wrapper
* fix(ci): add changelog fragment for PR 36
* fix: stabilize macOS visible overlay toggle
* fix: pin installed mpv plugin to current binary
* fix: strip inline subtitle markup from sidebar cues
* fix(renderer): restore subtitle sidebar mpv passthrough
* feat(discord): add configurable presence style presets
Replace the hardcoded "Mining and crafting (Anki cards)" meme message
with a preset system. New `discordPresence.presenceStyle` option
supports four presets: "default" (clean bilingual), "meme" (the OG
Minecraft joke), "japanese" (fully JP), and "minimal". The default
preset shows "Sentence Mining" with 日本語学習中 as the small image
tooltip. Existing users can set presenceStyle to "meme" to keep the
old behavior.
* fix: finalize v0.10.0 release prep
* docs: add subtitle sidebar guide and release note
* chore(backlog): mark docs task done
* fix: lazily resolve youtube playback socket path
* chore(release): build v0.10.0 changelog
* Revert "chore(release): build v0.10.0 changelog"
This reverts commit 9741c0f020.
This commit is contained in:
@@ -118,10 +118,14 @@ export function getDefaultControllerBinding(actionId: ControllerBindingActionId)
|
||||
if (!definition) {
|
||||
return { kind: 'none' } as const;
|
||||
}
|
||||
return JSON.parse(JSON.stringify(definition.defaultBinding)) as ResolvedControllerConfig['bindings'][ControllerBindingActionId];
|
||||
return JSON.parse(
|
||||
JSON.stringify(definition.defaultBinding),
|
||||
) as ResolvedControllerConfig['bindings'][ControllerBindingActionId];
|
||||
}
|
||||
|
||||
export function getDefaultDpadFallback(actionId: ControllerBindingActionId): ControllerDpadFallback {
|
||||
export function getDefaultDpadFallback(
|
||||
actionId: ControllerBindingActionId,
|
||||
): ControllerDpadFallback {
|
||||
const definition = getControllerBindingDefinition(actionId);
|
||||
if (!definition || definition.defaultBinding.kind !== 'axis') return 'none';
|
||||
const binding = definition.defaultBinding;
|
||||
@@ -249,7 +253,11 @@ export function createControllerConfigForm(options: {
|
||||
|
||||
if (definition.bindingType === 'axis') {
|
||||
renderAxisStickRow(definition, binding as ResolvedControllerAxisBinding, learningActionId);
|
||||
renderAxisDpadRow(definition, binding as ResolvedControllerAxisBinding, dpadLearningActionId);
|
||||
renderAxisDpadRow(
|
||||
definition,
|
||||
binding as ResolvedControllerAxisBinding,
|
||||
dpadLearningActionId,
|
||||
);
|
||||
} else {
|
||||
renderDiscreteRow(definition, binding, learningActionId);
|
||||
}
|
||||
@@ -265,7 +273,12 @@ export function createControllerConfigForm(options: {
|
||||
const isExpanded = expandedRowKey === rowKey;
|
||||
const isLearning = learningActionId === definition.id;
|
||||
|
||||
const row = createRow(definition.label, formatFriendlyBindingLabel(binding), binding.kind === 'none', isExpanded);
|
||||
const row = createRow(
|
||||
definition.label,
|
||||
formatFriendlyBindingLabel(binding),
|
||||
binding.kind === 'none',
|
||||
isExpanded,
|
||||
);
|
||||
row.addEventListener('click', () => {
|
||||
expandedRowKey = expandedRowKey === rowKey ? null : rowKey;
|
||||
render();
|
||||
@@ -277,9 +290,18 @@ export function createControllerConfigForm(options: {
|
||||
? 'Press a button, trigger, or move a stick\u2026'
|
||||
: `Currently: ${formatControllerBindingSummary(binding)}`;
|
||||
const panel = createEditPanel(hint, isLearning, {
|
||||
onLearn: (e) => { e.stopPropagation(); options.onLearn(definition.id, definition.bindingType); },
|
||||
onClear: (e) => { e.stopPropagation(); options.onClear(definition.id); },
|
||||
onReset: (e) => { e.stopPropagation(); options.onReset(definition.id); },
|
||||
onLearn: (e) => {
|
||||
e.stopPropagation();
|
||||
options.onLearn(definition.id, definition.bindingType);
|
||||
},
|
||||
onClear: (e) => {
|
||||
e.stopPropagation();
|
||||
options.onClear(definition.id);
|
||||
},
|
||||
onReset: (e) => {
|
||||
e.stopPropagation();
|
||||
options.onReset(definition.id);
|
||||
},
|
||||
});
|
||||
options.container.appendChild(panel);
|
||||
}
|
||||
@@ -294,7 +316,12 @@ export function createControllerConfigForm(options: {
|
||||
const isExpanded = expandedRowKey === rowKey;
|
||||
const isLearning = learningActionId === definition.id;
|
||||
|
||||
const row = createRow(`${definition.label} (Stick)`, formatFriendlyStickLabel(binding), binding.kind === 'none', isExpanded);
|
||||
const row = createRow(
|
||||
`${definition.label} (Stick)`,
|
||||
formatFriendlyStickLabel(binding),
|
||||
binding.kind === 'none',
|
||||
isExpanded,
|
||||
);
|
||||
row.addEventListener('click', () => {
|
||||
expandedRowKey = expandedRowKey === rowKey ? null : rowKey;
|
||||
render();
|
||||
@@ -305,9 +332,18 @@ export function createControllerConfigForm(options: {
|
||||
const summary = binding.kind === 'none' ? 'Disabled' : `Axis ${binding.axisIndex}`;
|
||||
const hint = isLearning ? 'Move a stick or trigger\u2026' : `Currently: ${summary}`;
|
||||
const panel = createEditPanel(hint, isLearning, {
|
||||
onLearn: (e) => { e.stopPropagation(); options.onLearn(definition.id, 'axis'); },
|
||||
onClear: (e) => { e.stopPropagation(); options.onClear(definition.id); },
|
||||
onReset: (e) => { e.stopPropagation(); options.onReset(definition.id); },
|
||||
onLearn: (e) => {
|
||||
e.stopPropagation();
|
||||
options.onLearn(definition.id, 'axis');
|
||||
},
|
||||
onClear: (e) => {
|
||||
e.stopPropagation();
|
||||
options.onClear(definition.id);
|
||||
},
|
||||
onReset: (e) => {
|
||||
e.stopPropagation();
|
||||
options.onReset(definition.id);
|
||||
},
|
||||
});
|
||||
options.container.appendChild(panel);
|
||||
}
|
||||
@@ -322,9 +358,15 @@ export function createControllerConfigForm(options: {
|
||||
const isExpanded = expandedRowKey === rowKey;
|
||||
const isLearning = dpadLearningActionId === definition.id;
|
||||
|
||||
const dpadFallback: ControllerDpadFallback = binding.kind === 'none' ? 'none' : binding.dpadFallback;
|
||||
const dpadFallback: ControllerDpadFallback =
|
||||
binding.kind === 'none' ? 'none' : binding.dpadFallback;
|
||||
const badgeText = DPAD_FALLBACK_LABELS[dpadFallback];
|
||||
const row = createRow(`${definition.label} (D-pad)`, badgeText, dpadFallback === 'none', isExpanded);
|
||||
const row = createRow(
|
||||
`${definition.label} (D-pad)`,
|
||||
badgeText,
|
||||
dpadFallback === 'none',
|
||||
isExpanded,
|
||||
);
|
||||
row.addEventListener('click', () => {
|
||||
expandedRowKey = expandedRowKey === rowKey ? null : rowKey;
|
||||
render();
|
||||
@@ -336,15 +378,29 @@ export function createControllerConfigForm(options: {
|
||||
? 'Press a D-pad direction\u2026'
|
||||
: `Currently: ${DPAD_FALLBACK_LABELS[dpadFallback]}`;
|
||||
const panel = createEditPanel(hint, isLearning, {
|
||||
onLearn: (e) => { e.stopPropagation(); options.onDpadLearn(definition.id); },
|
||||
onClear: (e) => { e.stopPropagation(); options.onDpadClear(definition.id); },
|
||||
onReset: (e) => { e.stopPropagation(); options.onDpadReset(definition.id); },
|
||||
onLearn: (e) => {
|
||||
e.stopPropagation();
|
||||
options.onDpadLearn(definition.id);
|
||||
},
|
||||
onClear: (e) => {
|
||||
e.stopPropagation();
|
||||
options.onDpadClear(definition.id);
|
||||
},
|
||||
onReset: (e) => {
|
||||
e.stopPropagation();
|
||||
options.onDpadReset(definition.id);
|
||||
},
|
||||
});
|
||||
options.container.appendChild(panel);
|
||||
}
|
||||
}
|
||||
|
||||
function createRow(labelText: string, badgeText: string, isDisabled: boolean, isExpanded: boolean): HTMLDivElement {
|
||||
function createRow(
|
||||
labelText: string,
|
||||
badgeText: string,
|
||||
isDisabled: boolean,
|
||||
isExpanded: boolean,
|
||||
): HTMLDivElement {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'controller-config-row';
|
||||
if (isExpanded) row.classList.add('expanded');
|
||||
|
||||
@@ -66,7 +66,10 @@ function createFakeElement() {
|
||||
if (!match) return null;
|
||||
const testId = match[1];
|
||||
for (const child of el.children) {
|
||||
if (typeof child.getAttribute === 'function' && child.getAttribute('data-testid') === testId) {
|
||||
if (
|
||||
typeof child.getAttribute === 'function' &&
|
||||
child.getAttribute('data-testid') === testId
|
||||
) {
|
||||
return child;
|
||||
}
|
||||
if (typeof child.querySelector === 'function') {
|
||||
@@ -105,7 +108,10 @@ function installFakeDom() {
|
||||
return {
|
||||
restore: () => {
|
||||
Object.defineProperty(globalThis, 'window', { configurable: true, value: previousWindow });
|
||||
Object.defineProperty(globalThis, 'document', { configurable: true, value: previousDocument });
|
||||
Object.defineProperty(globalThis, 'document', {
|
||||
configurable: true,
|
||||
value: previousDocument,
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,8 +31,9 @@ export function createControllerSelectModal(
|
||||
let lastRenderedActiveGamepadId: string | null = null;
|
||||
let lastRenderedPreferredId = '';
|
||||
type ControllerBindingKey = keyof NonNullable<typeof ctx.state.controllerConfig>['bindings'];
|
||||
type ControllerBindingValue =
|
||||
NonNullable<NonNullable<typeof ctx.state.controllerConfig>['bindings']>[ControllerBindingKey];
|
||||
type ControllerBindingValue = NonNullable<
|
||||
NonNullable<typeof ctx.state.controllerConfig>['bindings']
|
||||
>[ControllerBindingKey];
|
||||
let learningActionId: ControllerBindingKey | null = null;
|
||||
let dpadLearningActionId: ControllerBindingKey | null = null;
|
||||
let bindingCapture: ReturnType<typeof createControllerBindingCapture> | null = null;
|
||||
@@ -198,7 +199,9 @@ export function createControllerSelectModal(
|
||||
lastRenderedPreferredId = preferredId;
|
||||
}
|
||||
|
||||
async function saveControllerConfig(update: Parameters<typeof window.electronAPI.saveControllerConfig>[0]) {
|
||||
async function saveControllerConfig(
|
||||
update: Parameters<typeof window.electronAPI.saveControllerConfig>[0],
|
||||
) {
|
||||
await window.electronAPI.saveControllerConfig(update);
|
||||
if (!ctx.state.controllerConfig) return;
|
||||
if (update.preferredGamepadId !== undefined) {
|
||||
@@ -304,7 +307,10 @@ export function createControllerSelectModal(
|
||||
if (result.bindingType === 'dpad') {
|
||||
void saveDpadFallback(result.actionId as ControllerBindingKey, result.dpadDirection);
|
||||
} else {
|
||||
void saveBinding(result.actionId as ControllerBindingKey, result.binding as ControllerBindingValue);
|
||||
void saveBinding(
|
||||
result.actionId as ControllerBindingKey,
|
||||
result.binding as ControllerBindingValue,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,10 +90,7 @@ test('findActiveSubtitleCueIndex prefers current subtitle timing over near-futur
|
||||
{ startTime: 233.05, endTime: 236, text: 'next' },
|
||||
];
|
||||
|
||||
assert.equal(
|
||||
findActiveSubtitleCueIndex(cues, { text: 'previous', startTime: 231 }, 233, 0),
|
||||
0,
|
||||
);
|
||||
assert.equal(findActiveSubtitleCueIndex(cues, { text: 'previous', startTime: 231 }, 233, 0), 0);
|
||||
});
|
||||
|
||||
test('subtitle sidebar modal opens from snapshot and clicking cue seeks playback', async () => {
|
||||
@@ -1217,10 +1214,22 @@ test('subtitle sidebar polling schedules serialized timeouts instead of interval
|
||||
assert.equal(timeoutCount > 0, true);
|
||||
assert.equal(intervalCount, 0);
|
||||
} finally {
|
||||
Object.defineProperty(globalThis, 'setTimeout', { configurable: true, value: previousSetTimeout });
|
||||
Object.defineProperty(globalThis, 'clearTimeout', { configurable: true, value: previousClearTimeout });
|
||||
Object.defineProperty(globalThis, 'setInterval', { configurable: true, value: previousSetInterval });
|
||||
Object.defineProperty(globalThis, 'clearInterval', { configurable: true, value: previousClearInterval });
|
||||
Object.defineProperty(globalThis, 'setTimeout', {
|
||||
configurable: true,
|
||||
value: previousSetTimeout,
|
||||
});
|
||||
Object.defineProperty(globalThis, 'clearTimeout', {
|
||||
configurable: true,
|
||||
value: previousClearTimeout,
|
||||
});
|
||||
Object.defineProperty(globalThis, 'setInterval', {
|
||||
configurable: true,
|
||||
value: previousSetInterval,
|
||||
});
|
||||
Object.defineProperty(globalThis, 'clearInterval', {
|
||||
configurable: true,
|
||||
value: previousClearInterval,
|
||||
});
|
||||
Object.defineProperty(globalThis, 'window', { configurable: true, value: previousWindow });
|
||||
Object.defineProperty(globalThis, 'document', { configurable: true, value: previousDocument });
|
||||
}
|
||||
@@ -1232,6 +1241,7 @@ test('subtitle sidebar closes and resumes a hover pause', async () => {
|
||||
const previousDocument = globals.document;
|
||||
const mpvCommands: Array<Array<string | number>> = [];
|
||||
const modalListeners = new Map<string, Array<() => void>>();
|
||||
const contentListeners = new Map<string, Array<() => void>>();
|
||||
|
||||
const snapshot: SubtitleSidebarSnapshot = {
|
||||
cues: [{ startTime: 1, endTime: 2, text: 'first' }],
|
||||
@@ -1308,6 +1318,11 @@ test('subtitle sidebar closes and resumes a hover pause', async () => {
|
||||
subtitleSidebarContent: {
|
||||
classList: createClassList(),
|
||||
getBoundingClientRect: () => ({ width: 420 }),
|
||||
addEventListener: (type: string, listener: () => void) => {
|
||||
const bucket = contentListeners.get(type) ?? [];
|
||||
bucket.push(listener);
|
||||
contentListeners.set(type, bucket);
|
||||
},
|
||||
},
|
||||
subtitleSidebarClose: { addEventListener: () => {} },
|
||||
subtitleSidebarStatus: { textContent: '' },
|
||||
@@ -1324,7 +1339,7 @@ test('subtitle sidebar closes and resumes a hover pause', async () => {
|
||||
await modal.openSubtitleSidebarModal();
|
||||
await modal.refreshSubtitleSidebarSnapshot();
|
||||
mpvCommands.length = 0;
|
||||
await modalListeners.get('mouseenter')?.[0]?.();
|
||||
await contentListeners.get('mouseenter')?.[0]?.();
|
||||
|
||||
assert.deepEqual(mpvCommands.at(-1), ['set_property', 'pause', 'yes']);
|
||||
|
||||
@@ -1344,6 +1359,7 @@ test('subtitle sidebar hover pause ignores playback-state IPC failures', async (
|
||||
const previousDocument = globals.document;
|
||||
const mpvCommands: Array<Array<string | number>> = [];
|
||||
const modalListeners = new Map<string, Array<() => Promise<void> | void>>();
|
||||
const contentListeners = new Map<string, Array<() => Promise<void> | void>>();
|
||||
|
||||
const snapshot: SubtitleSidebarSnapshot = {
|
||||
cues: [{ startTime: 1, endTime: 2, text: 'first' }],
|
||||
@@ -1422,6 +1438,11 @@ test('subtitle sidebar hover pause ignores playback-state IPC failures', async (
|
||||
subtitleSidebarContent: {
|
||||
classList: createClassList(),
|
||||
getBoundingClientRect: () => ({ width: 420 }),
|
||||
addEventListener: (type: string, listener: () => Promise<void> | void) => {
|
||||
const bucket = contentListeners.get(type) ?? [];
|
||||
bucket.push(listener);
|
||||
contentListeners.set(type, bucket);
|
||||
},
|
||||
},
|
||||
subtitleSidebarClose: { addEventListener: () => {} },
|
||||
subtitleSidebarStatus: { textContent: '' },
|
||||
@@ -1437,7 +1458,7 @@ test('subtitle sidebar hover pause ignores playback-state IPC failures', async (
|
||||
|
||||
await modal.openSubtitleSidebarModal();
|
||||
await assert.doesNotReject(async () => {
|
||||
await modalListeners.get('mouseenter')?.[0]?.();
|
||||
await contentListeners.get('mouseenter')?.[0]?.();
|
||||
});
|
||||
|
||||
assert.equal(state.subtitleSidebarPausedByHover, false);
|
||||
@@ -1564,17 +1585,13 @@ test('subtitle sidebar embedded layout reserves and releases mpv right margin',
|
||||
assert.ok(
|
||||
mpvCommands.some(
|
||||
(command) =>
|
||||
command[0] === 'set_property' &&
|
||||
command[1] === 'osd-align-x' &&
|
||||
command[2] === 'left',
|
||||
command[0] === 'set_property' && command[1] === 'osd-align-x' && command[2] === 'left',
|
||||
),
|
||||
);
|
||||
assert.ok(
|
||||
mpvCommands.some(
|
||||
(command) =>
|
||||
command[0] === 'set_property' &&
|
||||
command[1] === 'osd-align-y' &&
|
||||
command[2] === 'top',
|
||||
command[0] === 'set_property' && command[1] === 'osd-align-y' && command[2] === 'top',
|
||||
),
|
||||
);
|
||||
assert.ok(
|
||||
@@ -1597,7 +1614,11 @@ test('subtitle sidebar embedded layout reserves and releases mpv right margin',
|
||||
assert.deepEqual(mpvCommands.at(-5), ['set_property', 'video-margin-ratio-right', 0]);
|
||||
assert.deepEqual(mpvCommands.at(-4), ['set_property', 'osd-align-x', 'left']);
|
||||
assert.deepEqual(mpvCommands.at(-3), ['set_property', 'osd-align-y', 'top']);
|
||||
assert.deepEqual(mpvCommands.at(-2), ['set_property', 'user-data/osc/margins', '{"l":0,"r":0,"t":0,"b":0}']);
|
||||
assert.deepEqual(mpvCommands.at(-2), [
|
||||
'set_property',
|
||||
'user-data/osc/margins',
|
||||
'{"l":0,"r":0,"t":0,"b":0}',
|
||||
]);
|
||||
assert.deepEqual(mpvCommands.at(-1), ['set_property', 'video-pan-x', 0]);
|
||||
assert.equal(bodyClassList.contains('subtitle-sidebar-embedded-open'), false);
|
||||
assert.deepEqual(rootStyleCalls.at(-1), ['--subtitle-sidebar-reserved-width', '0px']);
|
||||
@@ -1735,6 +1756,7 @@ test('subtitle sidebar embedded layout restores macOS and Windows passthrough ou
|
||||
const mpvCommands: Array<Array<string | number>> = [];
|
||||
const ignoreMouseCalls: Array<[boolean, { forward?: boolean } | undefined]> = [];
|
||||
const modalListeners = new Map<string, Array<() => void>>();
|
||||
const contentListeners = new Map<string, Array<() => void>>();
|
||||
|
||||
const snapshot: SubtitleSidebarSnapshot = {
|
||||
cues: [{ startTime: 1, endTime: 2, text: 'first' }],
|
||||
@@ -1814,6 +1836,11 @@ test('subtitle sidebar embedded layout restores macOS and Windows passthrough ou
|
||||
subtitleSidebarContent: {
|
||||
classList: createClassList(),
|
||||
getBoundingClientRect: () => ({ width: 360 }),
|
||||
addEventListener: (type: string, listener: () => void) => {
|
||||
const bucket = contentListeners.get(type) ?? [];
|
||||
bucket.push(listener);
|
||||
contentListeners.set(type, bucket);
|
||||
},
|
||||
},
|
||||
subtitleSidebarClose: { addEventListener: () => {} },
|
||||
subtitleSidebarStatus: { textContent: '' },
|
||||
@@ -1833,15 +1860,15 @@ test('subtitle sidebar embedded layout restores macOS and Windows passthrough ou
|
||||
await modal.openSubtitleSidebarModal();
|
||||
assert.deepEqual(ignoreMouseCalls.at(-1), [true, { forward: true }]);
|
||||
|
||||
modalListeners.get('mouseenter')?.[0]?.();
|
||||
contentListeners.get('mouseenter')?.[0]?.();
|
||||
assert.deepEqual(ignoreMouseCalls.at(-1), [false, undefined]);
|
||||
|
||||
modalListeners.get('mouseleave')?.[0]?.();
|
||||
contentListeners.get('mouseleave')?.[0]?.();
|
||||
assert.deepEqual(ignoreMouseCalls.at(-1), [true, { forward: true }]);
|
||||
|
||||
state.isOverSubtitle = true;
|
||||
modalListeners.get('mouseenter')?.[0]?.();
|
||||
modalListeners.get('mouseleave')?.[0]?.();
|
||||
contentListeners.get('mouseenter')?.[0]?.();
|
||||
contentListeners.get('mouseleave')?.[0]?.();
|
||||
assert.deepEqual(ignoreMouseCalls.at(-1), [false, undefined]);
|
||||
|
||||
void mpvCommands;
|
||||
@@ -1851,6 +1878,251 @@ test('subtitle sidebar embedded layout restores macOS and Windows passthrough ou
|
||||
}
|
||||
});
|
||||
|
||||
test('subtitle sidebar overlay layout restores macOS and Windows passthrough outside sidebar hover', async () => {
|
||||
const globals = globalThis as typeof globalThis & { window?: unknown; document?: unknown };
|
||||
const previousWindow = globals.window;
|
||||
const previousDocument = globals.document;
|
||||
const mpvCommands: Array<Array<string | number>> = [];
|
||||
const ignoreMouseCalls: Array<[boolean, { forward?: boolean } | undefined]> = [];
|
||||
const modalListeners = new Map<string, Array<() => void>>();
|
||||
const contentListeners = new Map<string, Array<() => void>>();
|
||||
|
||||
const snapshot: SubtitleSidebarSnapshot = {
|
||||
cues: [{ startTime: 1, endTime: 2, text: 'first' }],
|
||||
currentSubtitle: {
|
||||
text: 'first',
|
||||
startTime: 1,
|
||||
endTime: 2,
|
||||
},
|
||||
currentTimeSec: 1.1,
|
||||
config: {
|
||||
enabled: true,
|
||||
autoOpen: false,
|
||||
layout: 'overlay',
|
||||
toggleKey: 'Backslash',
|
||||
pauseVideoOnHover: false,
|
||||
autoScroll: true,
|
||||
maxWidth: 360,
|
||||
opacity: 0.92,
|
||||
backgroundColor: 'rgba(54, 58, 79, 0.88)',
|
||||
textColor: '#cad3f5',
|
||||
fontFamily: '"Iosevka Aile", sans-serif',
|
||||
fontSize: 17,
|
||||
timestampColor: '#a5adcb',
|
||||
activeLineColor: '#f5bde6',
|
||||
activeLineBackgroundColor: 'rgba(138, 173, 244, 0.22)',
|
||||
hoverLineBackgroundColor: 'rgba(54, 58, 79, 0.84)',
|
||||
},
|
||||
};
|
||||
|
||||
Object.defineProperty(globalThis, 'window', {
|
||||
configurable: true,
|
||||
value: {
|
||||
innerWidth: 1200,
|
||||
electronAPI: {
|
||||
getSubtitleSidebarSnapshot: async () => snapshot,
|
||||
sendMpvCommand: (command: Array<string | number>) => {
|
||||
mpvCommands.push(command);
|
||||
},
|
||||
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => {
|
||||
ignoreMouseCalls.push([ignore, options]);
|
||||
},
|
||||
} as unknown as ElectronAPI,
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
},
|
||||
});
|
||||
Object.defineProperty(globalThis, 'document', {
|
||||
configurable: true,
|
||||
value: {
|
||||
createElement: () => createCueRow(),
|
||||
body: {
|
||||
classList: createClassList(),
|
||||
},
|
||||
documentElement: {
|
||||
style: {
|
||||
setProperty: () => {},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const state = createRendererState();
|
||||
const ctx = {
|
||||
dom: {
|
||||
overlay: { classList: createClassList() },
|
||||
subtitleSidebarModal: {
|
||||
classList: createClassList(['hidden']),
|
||||
setAttribute: () => {},
|
||||
style: { setProperty: () => {} },
|
||||
addEventListener: (type: string, listener: () => void) => {
|
||||
const bucket = modalListeners.get(type) ?? [];
|
||||
bucket.push(listener);
|
||||
modalListeners.set(type, bucket);
|
||||
},
|
||||
},
|
||||
subtitleSidebarContent: {
|
||||
classList: createClassList(),
|
||||
getBoundingClientRect: () => ({ width: 360 }),
|
||||
addEventListener: (type: string, listener: () => void) => {
|
||||
const bucket = contentListeners.get(type) ?? [];
|
||||
bucket.push(listener);
|
||||
contentListeners.set(type, bucket);
|
||||
},
|
||||
},
|
||||
subtitleSidebarClose: { addEventListener: () => {} },
|
||||
subtitleSidebarStatus: { textContent: '' },
|
||||
subtitleSidebarList: createListStub(),
|
||||
},
|
||||
platform: {
|
||||
shouldToggleMouseIgnore: true,
|
||||
},
|
||||
state,
|
||||
};
|
||||
|
||||
const modal = createSubtitleSidebarModal(ctx as never, {
|
||||
modalStateReader: { isAnyModalOpen: () => false },
|
||||
});
|
||||
modal.wireDomEvents();
|
||||
|
||||
assert.equal(modalListeners.get('mouseenter')?.length ?? 0, 0);
|
||||
assert.equal(modalListeners.get('mouseleave')?.length ?? 0, 0);
|
||||
assert.equal(contentListeners.get('mouseenter')?.length ?? 0, 1);
|
||||
assert.equal(contentListeners.get('mouseleave')?.length ?? 0, 1);
|
||||
|
||||
await modal.openSubtitleSidebarModal();
|
||||
assert.deepEqual(ignoreMouseCalls.at(-1), [true, { forward: true }]);
|
||||
|
||||
contentListeners.get('mouseenter')?.[0]?.();
|
||||
assert.deepEqual(ignoreMouseCalls.at(-1), [false, undefined]);
|
||||
|
||||
contentListeners.get('mouseleave')?.[0]?.();
|
||||
assert.deepEqual(ignoreMouseCalls.at(-1), [true, { forward: true }]);
|
||||
|
||||
void mpvCommands;
|
||||
} finally {
|
||||
Object.defineProperty(globalThis, 'window', { configurable: true, value: previousWindow });
|
||||
Object.defineProperty(globalThis, 'document', { configurable: true, value: previousDocument });
|
||||
}
|
||||
});
|
||||
|
||||
test('subtitle sidebar overlay layout only stays interactive while focus remains inside the sidebar panel', async () => {
|
||||
const globals = globalThis as typeof globalThis & { window?: unknown; document?: unknown };
|
||||
const previousWindow = globals.window;
|
||||
const previousDocument = globals.document;
|
||||
const ignoreMouseCalls: Array<[boolean, { forward?: boolean } | undefined]> = [];
|
||||
const contentListeners = new Map<string, Array<(event?: FocusEvent) => void>>();
|
||||
|
||||
const snapshot: SubtitleSidebarSnapshot = {
|
||||
cues: [{ startTime: 1, endTime: 2, text: 'first' }],
|
||||
currentSubtitle: {
|
||||
text: 'first',
|
||||
startTime: 1,
|
||||
endTime: 2,
|
||||
},
|
||||
currentTimeSec: 1.1,
|
||||
config: {
|
||||
enabled: true,
|
||||
autoOpen: false,
|
||||
layout: 'overlay',
|
||||
toggleKey: 'Backslash',
|
||||
pauseVideoOnHover: false,
|
||||
autoScroll: true,
|
||||
maxWidth: 360,
|
||||
opacity: 0.92,
|
||||
backgroundColor: 'rgba(54, 58, 79, 0.88)',
|
||||
textColor: '#cad3f5',
|
||||
fontFamily: '"Iosevka Aile", sans-serif',
|
||||
fontSize: 17,
|
||||
timestampColor: '#a5adcb',
|
||||
activeLineColor: '#f5bde6',
|
||||
activeLineBackgroundColor: 'rgba(138, 173, 244, 0.22)',
|
||||
hoverLineBackgroundColor: 'rgba(54, 58, 79, 0.84)',
|
||||
},
|
||||
};
|
||||
|
||||
Object.defineProperty(globalThis, 'window', {
|
||||
configurable: true,
|
||||
value: {
|
||||
innerWidth: 1200,
|
||||
electronAPI: {
|
||||
getSubtitleSidebarSnapshot: async () => snapshot,
|
||||
sendMpvCommand: () => {},
|
||||
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => {
|
||||
ignoreMouseCalls.push([ignore, options]);
|
||||
},
|
||||
} as unknown as ElectronAPI,
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
},
|
||||
});
|
||||
Object.defineProperty(globalThis, 'document', {
|
||||
configurable: true,
|
||||
value: {
|
||||
createElement: () => createCueRow(),
|
||||
body: {
|
||||
classList: createClassList(),
|
||||
},
|
||||
documentElement: {
|
||||
style: {
|
||||
setProperty: () => {},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const state = createRendererState();
|
||||
const sidebarContent = {
|
||||
classList: createClassList(),
|
||||
getBoundingClientRect: () => ({ width: 360 }),
|
||||
addEventListener: (type: string, listener: (event?: FocusEvent) => void) => {
|
||||
const bucket = contentListeners.get(type) ?? [];
|
||||
bucket.push(listener);
|
||||
contentListeners.set(type, bucket);
|
||||
},
|
||||
contains: () => false,
|
||||
};
|
||||
const ctx = {
|
||||
dom: {
|
||||
overlay: { classList: createClassList() },
|
||||
subtitleSidebarModal: {
|
||||
classList: createClassList(['hidden']),
|
||||
setAttribute: () => {},
|
||||
style: { setProperty: () => {} },
|
||||
addEventListener: () => {},
|
||||
},
|
||||
subtitleSidebarContent: sidebarContent,
|
||||
subtitleSidebarClose: { addEventListener: () => {} },
|
||||
subtitleSidebarStatus: { textContent: '' },
|
||||
subtitleSidebarList: createListStub(),
|
||||
},
|
||||
platform: {
|
||||
shouldToggleMouseIgnore: true,
|
||||
},
|
||||
state,
|
||||
};
|
||||
|
||||
const modal = createSubtitleSidebarModal(ctx as never, {
|
||||
modalStateReader: { isAnyModalOpen: () => false },
|
||||
});
|
||||
modal.wireDomEvents();
|
||||
|
||||
await modal.openSubtitleSidebarModal();
|
||||
assert.deepEqual(ignoreMouseCalls.at(-1), [true, { forward: true }]);
|
||||
|
||||
contentListeners.get('focusin')?.[0]?.();
|
||||
assert.deepEqual(ignoreMouseCalls.at(-1), [false, undefined]);
|
||||
|
||||
contentListeners.get('focusout')?.[0]?.({ relatedTarget: null } as FocusEvent);
|
||||
assert.deepEqual(ignoreMouseCalls.at(-1), [true, { forward: true }]);
|
||||
} finally {
|
||||
Object.defineProperty(globalThis, 'window', { configurable: true, value: previousWindow });
|
||||
Object.defineProperty(globalThis, 'document', { configurable: true, value: previousDocument });
|
||||
}
|
||||
});
|
||||
|
||||
test('closing embedded subtitle sidebar recomputes passthrough from remaining subtitle hover state', async () => {
|
||||
const globals = globalThis as typeof globalThis & { window?: unknown; document?: unknown };
|
||||
const previousWindow = globals.window;
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import type {
|
||||
SubtitleCue,
|
||||
SubtitleData,
|
||||
SubtitleSidebarSnapshot,
|
||||
} from '../../types';
|
||||
import type { SubtitleCue, SubtitleData, SubtitleSidebarSnapshot } from '../../types';
|
||||
import type { ModalStateReader, RendererContext } from '../context';
|
||||
import { syncOverlayMouseIgnoreState } from '../overlay-mouse-ignore.js';
|
||||
|
||||
@@ -76,8 +72,7 @@ export function findActiveSubtitleCueIndex(
|
||||
if (typeof currentTimeSec === 'number' && Number.isFinite(currentTimeSec)) {
|
||||
const activeOrUpcomingCue = cues.findIndex(
|
||||
(cue) =>
|
||||
cue.endTime > currentTimeSec &&
|
||||
cue.startTime <= currentTimeSec + ACTIVE_CUE_LOOKAHEAD_SEC,
|
||||
cue.endTime > currentTimeSec && cue.startTime <= currentTimeSec + ACTIVE_CUE_LOOKAHEAD_SEC,
|
||||
);
|
||||
if (activeOrUpcomingCue >= 0) {
|
||||
return activeOrUpcomingCue;
|
||||
@@ -109,8 +104,7 @@ export function findActiveSubtitleCueIndex(
|
||||
return -1;
|
||||
}
|
||||
|
||||
const hasTiming =
|
||||
typeof current.startTime === 'number' && Number.isFinite(current.startTime);
|
||||
const hasTiming = typeof current.startTime === 'number' && Number.isFinite(current.startTime);
|
||||
|
||||
if (preferredCueIndex >= 0) {
|
||||
if (!hasTiming && currentTimeSec === null) {
|
||||
@@ -149,11 +143,23 @@ export function createSubtitleSidebarModal(
|
||||
let lastAppliedVideoMarginRatio: number | null = null;
|
||||
let subtitleSidebarHoverRequestId = 0;
|
||||
let disposeDomEvents: (() => void) | null = null;
|
||||
let subtitleSidebarHovered = false;
|
||||
let subtitleSidebarFocusedWithin = false;
|
||||
|
||||
function restoreEmbeddedSidebarPassthrough(): void {
|
||||
syncOverlayMouseIgnoreState(ctx);
|
||||
}
|
||||
|
||||
function syncSidebarInteractionState(): void {
|
||||
ctx.state.isOverSubtitleSidebar = subtitleSidebarHovered || subtitleSidebarFocusedWithin;
|
||||
}
|
||||
|
||||
function clearSidebarInteractionState(): void {
|
||||
subtitleSidebarHovered = false;
|
||||
subtitleSidebarFocusedWithin = false;
|
||||
syncSidebarInteractionState();
|
||||
}
|
||||
|
||||
function setStatus(message: string): void {
|
||||
ctx.dom.subtitleSidebarStatus.textContent = message;
|
||||
}
|
||||
@@ -213,16 +219,8 @@ export function createSubtitleSidebarModal(
|
||||
'video-margin-ratio-right',
|
||||
Number(ratio.toFixed(4)),
|
||||
]);
|
||||
window.electronAPI.sendMpvCommand([
|
||||
'set_property',
|
||||
'osd-align-x',
|
||||
'left',
|
||||
]);
|
||||
window.electronAPI.sendMpvCommand([
|
||||
'set_property',
|
||||
'osd-align-y',
|
||||
'top',
|
||||
]);
|
||||
window.electronAPI.sendMpvCommand(['set_property', 'osd-align-x', 'left']);
|
||||
window.electronAPI.sendMpvCommand(['set_property', 'osd-align-y', 'top']);
|
||||
window.electronAPI.sendMpvCommand([
|
||||
'set_property',
|
||||
'user-data/osc/margins',
|
||||
@@ -302,13 +300,14 @@ export function createSubtitleSidebarModal(
|
||||
}
|
||||
|
||||
const list = ctx.dom.subtitleSidebarList;
|
||||
const active = list.children[ctx.state.subtitleSidebarActiveCueIndex] as HTMLElement | undefined;
|
||||
const active = list.children[ctx.state.subtitleSidebarActiveCueIndex] as
|
||||
| HTMLElement
|
||||
| undefined;
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetScrollTop =
|
||||
active.offsetTop - (list.clientHeight - active.clientHeight) / 2;
|
||||
const targetScrollTop = active.offsetTop - (list.clientHeight - active.clientHeight) / 2;
|
||||
const nextScrollTop = Math.max(0, targetScrollTop);
|
||||
if (previousActiveCueIndex < 0) {
|
||||
list.scrollTop = nextScrollTop;
|
||||
@@ -363,9 +362,9 @@ export function createSubtitleSidebarModal(
|
||||
}
|
||||
|
||||
if (ctx.state.subtitleSidebarActiveCueIndex >= 0) {
|
||||
const current = ctx.dom.subtitleSidebarList.children[ctx.state.subtitleSidebarActiveCueIndex] as
|
||||
| HTMLElement
|
||||
| undefined;
|
||||
const current = ctx.dom.subtitleSidebarList.children[
|
||||
ctx.state.subtitleSidebarActiveCueIndex
|
||||
] as HTMLElement | undefined;
|
||||
current?.classList.add('active');
|
||||
}
|
||||
}
|
||||
@@ -392,6 +391,7 @@ export function createSubtitleSidebarModal(
|
||||
applyConfig(snapshot);
|
||||
if (!snapshot.config.enabled) {
|
||||
resumeSubtitleSidebarHoverPause();
|
||||
clearSidebarInteractionState();
|
||||
ctx.state.subtitleSidebarCues = [];
|
||||
ctx.state.subtitleSidebarModalOpen = false;
|
||||
ctx.dom.subtitleSidebarModal.classList.add('hidden');
|
||||
@@ -463,7 +463,7 @@ export function createSubtitleSidebarModal(
|
||||
}
|
||||
|
||||
ctx.state.subtitleSidebarModalOpen = true;
|
||||
ctx.state.isOverSubtitleSidebar = false;
|
||||
clearSidebarInteractionState();
|
||||
ctx.dom.subtitleSidebarModal.classList.remove('hidden');
|
||||
ctx.dom.subtitleSidebarModal.setAttribute('aria-hidden', 'false');
|
||||
renderCueList();
|
||||
@@ -476,7 +476,11 @@ export function createSubtitleSidebarModal(
|
||||
|
||||
async function autoOpenSubtitleSidebarOnStartup(): Promise<void> {
|
||||
const snapshot = await refreshSnapshot();
|
||||
if (!snapshot.config.enabled || !snapshot.config.autoOpen || ctx.state.subtitleSidebarModalOpen) {
|
||||
if (
|
||||
!snapshot.config.enabled ||
|
||||
!snapshot.config.autoOpen ||
|
||||
ctx.state.subtitleSidebarModalOpen
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await openSubtitleSidebarModal();
|
||||
@@ -487,7 +491,7 @@ export function createSubtitleSidebarModal(
|
||||
return;
|
||||
}
|
||||
resumeSubtitleSidebarHoverPause();
|
||||
ctx.state.isOverSubtitleSidebar = false;
|
||||
clearSidebarInteractionState();
|
||||
ctx.state.subtitleSidebarModalOpen = false;
|
||||
ctx.dom.subtitleSidebarModal.classList.add('hidden');
|
||||
ctx.dom.subtitleSidebarModal.setAttribute('aria-hidden', 'true');
|
||||
@@ -512,10 +516,7 @@ export function createSubtitleSidebarModal(
|
||||
return;
|
||||
}
|
||||
|
||||
updateActiveCue(
|
||||
{ text: data.text, startTime: data.startTime },
|
||||
data.startTime ?? null,
|
||||
);
|
||||
updateActiveCue({ text: data.text, startTime: data.startTime }, data.startTime ?? null);
|
||||
}
|
||||
|
||||
function wireDomEvents(): void {
|
||||
@@ -548,8 +549,9 @@ export function createSubtitleSidebarModal(
|
||||
ctx.dom.subtitleSidebarList.addEventListener('wheel', () => {
|
||||
ctx.state.subtitleSidebarManualScrollUntilMs = Date.now() + MANUAL_SCROLL_HOLD_MS;
|
||||
});
|
||||
ctx.dom.subtitleSidebarModal.addEventListener('mouseenter', async () => {
|
||||
ctx.state.isOverSubtitleSidebar = true;
|
||||
ctx.dom.subtitleSidebarContent.addEventListener('mouseenter', async () => {
|
||||
subtitleSidebarHovered = true;
|
||||
syncSidebarInteractionState();
|
||||
restoreEmbeddedSidebarPassthrough();
|
||||
if (!ctx.state.subtitleSidebarPauseVideoOnHover || ctx.state.subtitleSidebarPausedByHover) {
|
||||
return;
|
||||
@@ -569,8 +571,36 @@ export function createSubtitleSidebarModal(
|
||||
ctx.state.subtitleSidebarPausedByHover = true;
|
||||
}
|
||||
});
|
||||
ctx.dom.subtitleSidebarModal.addEventListener('mouseleave', () => {
|
||||
ctx.state.isOverSubtitleSidebar = false;
|
||||
ctx.dom.subtitleSidebarContent.addEventListener('mouseleave', () => {
|
||||
subtitleSidebarHovered = false;
|
||||
syncSidebarInteractionState();
|
||||
if (ctx.state.isOverSubtitleSidebar) {
|
||||
restoreEmbeddedSidebarPassthrough();
|
||||
return;
|
||||
}
|
||||
resumeSubtitleSidebarHoverPause();
|
||||
});
|
||||
ctx.dom.subtitleSidebarContent.addEventListener('focusin', () => {
|
||||
subtitleSidebarFocusedWithin = true;
|
||||
syncSidebarInteractionState();
|
||||
restoreEmbeddedSidebarPassthrough();
|
||||
});
|
||||
ctx.dom.subtitleSidebarContent.addEventListener('focusout', (event: FocusEvent) => {
|
||||
const relatedTarget = event.relatedTarget;
|
||||
if (
|
||||
typeof Node !== 'undefined' &&
|
||||
relatedTarget instanceof Node &&
|
||||
ctx.dom.subtitleSidebarContent.contains(relatedTarget)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
subtitleSidebarFocusedWithin = false;
|
||||
syncSidebarInteractionState();
|
||||
if (ctx.state.isOverSubtitleSidebar) {
|
||||
restoreEmbeddedSidebarPassthrough();
|
||||
return;
|
||||
}
|
||||
resumeSubtitleSidebarHoverPause();
|
||||
});
|
||||
const resizeHandler = () => {
|
||||
|
||||
@@ -28,13 +28,13 @@ export function createYoutubeTrackPickerModal(
|
||||
function setStatus(message: string, isError = false): void {
|
||||
ctx.state.youtubePickerStatus = message;
|
||||
ctx.dom.youtubePickerStatus.textContent = message;
|
||||
ctx.dom.youtubePickerStatus.style.color = isError
|
||||
? '#ed8796'
|
||||
: '#a5adcb';
|
||||
ctx.dom.youtubePickerStatus.style.color = isError ? '#ed8796' : '#a5adcb';
|
||||
}
|
||||
|
||||
function getTrackLabel(trackId: string): string {
|
||||
return ctx.state.youtubePickerPayload?.tracks.find((track) => track.id === trackId)?.label ?? '';
|
||||
return (
|
||||
ctx.state.youtubePickerPayload?.tracks.find((track) => track.id === trackId)?.label ?? ''
|
||||
);
|
||||
}
|
||||
|
||||
function renderTrackList(): void {
|
||||
@@ -82,10 +82,7 @@ export function createYoutubeTrackPickerModal(
|
||||
if (track.id === primaryTrackId) continue;
|
||||
ctx.dom.youtubePickerSecondarySelect.appendChild(createOption(track.id, track.label));
|
||||
}
|
||||
if (
|
||||
primaryTrackId &&
|
||||
ctx.dom.youtubePickerSecondarySelect.value === primaryTrackId
|
||||
) {
|
||||
if (primaryTrackId && ctx.dom.youtubePickerSecondarySelect.value === primaryTrackId) {
|
||||
ctx.dom.youtubePickerSecondarySelect.value = '';
|
||||
}
|
||||
}
|
||||
@@ -126,7 +123,9 @@ export function createYoutubeTrackPickerModal(
|
||||
setStatus('Select the subtitle tracks to download.');
|
||||
}
|
||||
|
||||
async function resolveSelection(action: 'use-selected' | 'continue-without-subtitles'): Promise<void> {
|
||||
async function resolveSelection(
|
||||
action: 'use-selected' | 'continue-without-subtitles',
|
||||
): Promise<void> {
|
||||
if (resolveSelectionInFlight) {
|
||||
return;
|
||||
}
|
||||
@@ -238,7 +237,9 @@ export function createYoutubeTrackPickerModal(
|
||||
return true;
|
||||
}
|
||||
void resolveSelection(
|
||||
payloadHasTracks(ctx.state.youtubePickerPayload) ? 'use-selected' : 'continue-without-subtitles',
|
||||
payloadHasTracks(ctx.state.youtubePickerPayload)
|
||||
? 'use-selected'
|
||||
: 'continue-without-subtitles',
|
||||
);
|
||||
return true;
|
||||
}
|
||||
@@ -269,7 +270,9 @@ export function createYoutubeTrackPickerModal(
|
||||
|
||||
ctx.dom.youtubePickerContinueButton.addEventListener('click', () => {
|
||||
void resolveSelection(
|
||||
payloadHasTracks(ctx.state.youtubePickerPayload) ? 'use-selected' : 'continue-without-subtitles',
|
||||
payloadHasTracks(ctx.state.youtubePickerPayload)
|
||||
? 'use-selected'
|
||||
: 'continue-without-subtitles',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user