mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-26 00:26:05 -07:00
fix: address latest coderabbit review
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
commandNeedsOverlayStartupPrereqs,
|
||||
commandNeedsOverlayRuntime,
|
||||
hasExplicitCommand,
|
||||
isHeadlessInitialCommand,
|
||||
@@ -75,6 +76,7 @@ test('youtube playback does not use generic overlay-runtime bootstrap classifica
|
||||
const args = parseArgs(['--youtube-play', 'https://youtube.com/watch?v=abc']);
|
||||
|
||||
assert.equal(commandNeedsOverlayRuntime(args), false);
|
||||
assert.equal(commandNeedsOverlayStartupPrereqs(args), true);
|
||||
});
|
||||
|
||||
test('parseArgs handles jellyfin item listing controls', () => {
|
||||
@@ -148,6 +150,9 @@ test('hasExplicitCommand and shouldStartApp preserve command intent', () => {
|
||||
assert.equal(shouldStartApp(help), false);
|
||||
assert.equal(shouldRunSettingsOnlyStartup(help), false);
|
||||
|
||||
const youtubePlay = parseArgs(['--youtube-play', 'https://youtube.com/watch?v=abc']);
|
||||
assert.equal(commandNeedsOverlayStartupPrereqs(youtubePlay), true);
|
||||
|
||||
const anilistStatus = parseArgs(['--anilist-status']);
|
||||
assert.equal(anilistStatus.anilistStatus, true);
|
||||
assert.equal(hasExplicitCommand(anilistStatus), true);
|
||||
|
||||
15
src/main.ts
15
src/main.ts
@@ -503,6 +503,7 @@ let anilistCachedAccessToken: string | null = null;
|
||||
let jellyfinPlayQuitOnDisconnectArmed = false;
|
||||
let youtubePlayQuitOnDisconnectArmed = false;
|
||||
let youtubePlayQuitOnDisconnectArmTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
let youtubePlaybackFlowGeneration = 0;
|
||||
const JELLYFIN_LANG_PREF = 'ja,jp,jpn,japanese,en,eng,english,enUS,en-US';
|
||||
const JELLYFIN_TICKS_PER_SECOND = 10_000_000;
|
||||
const JELLYFIN_REMOTE_PROGRESS_INTERVAL_MS = 3000;
|
||||
@@ -986,6 +987,7 @@ async function runYoutubePlaybackFlowMain(request: {
|
||||
mode: NonNullable<CliArgs['youtubeMode']>;
|
||||
source: CliCommandSource;
|
||||
}): Promise<void> {
|
||||
const flowGeneration = ++youtubePlaybackFlowGeneration;
|
||||
youtubePrimarySubtitleNotificationRuntime.setAppOwnedFlowInFlight(true);
|
||||
let flowCompleted = false;
|
||||
try {
|
||||
@@ -1047,6 +1049,9 @@ async function runYoutubePlaybackFlowMain(request: {
|
||||
}
|
||||
if (request.source === 'initial') {
|
||||
youtubePlayQuitOnDisconnectArmTimer = setTimeout(() => {
|
||||
if (youtubePlaybackFlowGeneration !== flowGeneration) {
|
||||
return;
|
||||
}
|
||||
youtubePlayQuitOnDisconnectArmed = true;
|
||||
youtubePlayQuitOnDisconnectArmTimer = null;
|
||||
}, 3000);
|
||||
@@ -1062,11 +1067,13 @@ async function runYoutubePlaybackFlowMain(request: {
|
||||
flowCompleted = true;
|
||||
logger.info(`YouTube playback flow completed from ${request.source}.`);
|
||||
} finally {
|
||||
if (!flowCompleted) {
|
||||
clearYoutubePlayQuitOnDisconnectArmTimer();
|
||||
youtubePlayQuitOnDisconnectArmed = false;
|
||||
if (youtubePlaybackFlowGeneration === flowGeneration) {
|
||||
if (!flowCompleted) {
|
||||
clearYoutubePlayQuitOnDisconnectArmTimer();
|
||||
youtubePlayQuitOnDisconnectArmed = false;
|
||||
}
|
||||
youtubePrimarySubtitleNotificationRuntime.setAppOwnedFlowInFlight(false);
|
||||
}
|
||||
youtubePrimarySubtitleNotificationRuntime.setAppOwnedFlowInFlight(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ test('texthooker precheck no-ops for texthooker command', () => {
|
||||
test('texthooker precheck transitions for youtube playback startup prereqs', () => {
|
||||
let mode = true;
|
||||
let prereqs = 0;
|
||||
let warmups = 0;
|
||||
let logs = 0;
|
||||
const handlePrecheck = createHandleTexthookerOnlyModeTransitionHandler({
|
||||
isTexthookerOnlyMode: () => mode,
|
||||
setTexthookerOnlyMode: (enabled) => {
|
||||
@@ -77,12 +79,18 @@ test('texthooker precheck transitions for youtube playback startup prereqs', ()
|
||||
ensureOverlayStartupPrereqs: () => {
|
||||
prereqs += 1;
|
||||
},
|
||||
startBackgroundWarmups: () => {},
|
||||
logInfo: () => {},
|
||||
startBackgroundWarmups: () => {
|
||||
warmups += 1;
|
||||
},
|
||||
logInfo: () => {
|
||||
logs += 1;
|
||||
},
|
||||
});
|
||||
|
||||
handlePrecheck({ youtubePlay: 'https://youtube.com/watch?v=abc', texthooker: false } as never);
|
||||
|
||||
assert.equal(mode, false);
|
||||
assert.equal(prereqs, 1);
|
||||
assert.equal(warmups, 1);
|
||||
assert.equal(logs, 1);
|
||||
});
|
||||
|
||||
@@ -144,13 +144,13 @@ export function createPrepareYoutubePlaybackInMpvHandler(deps: YoutubePlaybackLa
|
||||
// Continue polling until media tracks are actually available.
|
||||
}
|
||||
}
|
||||
const pathChanged = currentPath !== previousPath;
|
||||
const pathDiffersFromInitial = currentPath !== previousPath;
|
||||
const matchesChangedTarget =
|
||||
currentPath === targetUrl ||
|
||||
(isYoutubeMediaPath(currentPath) &&
|
||||
isYoutubeMediaPath(targetUrl) &&
|
||||
pathMatchesYoutubeTarget(currentPath, targetUrl));
|
||||
if (pathChanged && matchesChangedTarget) {
|
||||
if (pathDiffersFromInitial && matchesChangedTarget) {
|
||||
if (deps.requestProperty) {
|
||||
try {
|
||||
const trackList = await deps.requestProperty('track-list');
|
||||
|
||||
Reference in New Issue
Block a user