mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-02 18:22:42 -08:00
fix: address latest claude review findings
This commit is contained in:
@@ -13,6 +13,17 @@ function shouldAutoConnectJellyfinRemote(config: {
|
||||
return config.enabled && config.remoteControlEnabled && config.remoteControlAutoConnect;
|
||||
}
|
||||
|
||||
function createDeferred(): {
|
||||
promise: Promise<void>;
|
||||
resolve: () => void;
|
||||
} {
|
||||
let resolve!: () => void;
|
||||
const promise = new Promise<void>((nextResolve) => {
|
||||
resolve = nextResolve;
|
||||
});
|
||||
return { promise, resolve };
|
||||
}
|
||||
|
||||
test('launchBackgroundWarmupTask logs completion timing', async () => {
|
||||
const debugLogs: string[] = [];
|
||||
const launchTask = createLaunchBackgroundWarmupTaskHandler({
|
||||
@@ -194,3 +205,60 @@ test('startBackgroundWarmups logs per-stage progress for enabled tokenization wa
|
||||
assert.ok(debugLogs.includes('[startup-warmup] stage start: jellyfin-remote-session'));
|
||||
assert.ok(debugLogs.includes('[startup-warmup] stage ready: jellyfin-remote-session'));
|
||||
});
|
||||
|
||||
test('startBackgroundWarmups starts mecab and dictionary warmups without waiting for yomitan warmup', async () => {
|
||||
const startedStages: string[] = [];
|
||||
let started = false;
|
||||
let subtitleTokenizationTask: Promise<void> | null = null;
|
||||
const yomitanDeferred = createDeferred();
|
||||
const mecabDeferred = createDeferred();
|
||||
const subtitleDictionariesDeferred = createDeferred();
|
||||
|
||||
const startWarmups = createStartBackgroundWarmupsHandler({
|
||||
getStarted: () => started,
|
||||
setStarted: (value) => {
|
||||
started = value;
|
||||
},
|
||||
isTexthookerOnlyMode: () => false,
|
||||
launchTask: (label, task) => {
|
||||
if (label === 'subtitle-tokenization') {
|
||||
subtitleTokenizationTask = task();
|
||||
}
|
||||
},
|
||||
createMecabTokenizerAndCheck: async () => {
|
||||
startedStages.push('mecab');
|
||||
await mecabDeferred.promise;
|
||||
},
|
||||
ensureYomitanExtensionLoaded: async () => {
|
||||
startedStages.push('yomitan-extension');
|
||||
await yomitanDeferred.promise;
|
||||
},
|
||||
prewarmSubtitleDictionaries: async () => {
|
||||
startedStages.push('subtitle-dictionaries');
|
||||
await subtitleDictionariesDeferred.promise;
|
||||
},
|
||||
shouldWarmupMecab: () => true,
|
||||
shouldWarmupYomitanExtension: () => true,
|
||||
shouldWarmupSubtitleDictionaries: () => true,
|
||||
shouldWarmupJellyfinRemoteSession: () => false,
|
||||
shouldAutoConnectJellyfinRemote: () => false,
|
||||
startJellyfinRemoteSession: async () => {},
|
||||
});
|
||||
|
||||
startWarmups();
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
|
||||
assert.ok(subtitleTokenizationTask);
|
||||
assert.equal(startedStages.includes('yomitan-extension'), true);
|
||||
assert.equal(startedStages.includes('mecab'), true);
|
||||
assert.equal(startedStages.includes('subtitle-dictionaries'), true);
|
||||
|
||||
yomitanDeferred.resolve();
|
||||
mecabDeferred.resolve();
|
||||
subtitleDictionariesDeferred.resolve();
|
||||
if (!subtitleTokenizationTask) {
|
||||
throw new Error('Expected subtitle tokenization warmup task');
|
||||
}
|
||||
await subtitleTokenizationTask;
|
||||
});
|
||||
|
||||
@@ -47,15 +47,16 @@ export function createStartBackgroundWarmupsHandler(deps: {
|
||||
warmupMecab || warmupYomitanExtension || warmupSubtitleDictionaries;
|
||||
if (shouldWarmupTokenization) {
|
||||
deps.launchTask('subtitle-tokenization', async () => {
|
||||
if (warmupYomitanExtension) {
|
||||
deps.logDebug?.('[startup-warmup] stage start: yomitan-extension');
|
||||
await deps.ensureYomitanExtensionLoaded();
|
||||
deps.logDebug?.('[startup-warmup] stage ready: yomitan-extension');
|
||||
} else {
|
||||
deps.logDebug?.('[startup-warmup] stage skipped: yomitan-extension');
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
warmupYomitanExtension
|
||||
? (async () => {
|
||||
deps.logDebug?.('[startup-warmup] stage start: yomitan-extension');
|
||||
await deps.ensureYomitanExtensionLoaded();
|
||||
deps.logDebug?.('[startup-warmup] stage ready: yomitan-extension');
|
||||
})()
|
||||
: Promise.resolve().then(() => {
|
||||
deps.logDebug?.('[startup-warmup] stage skipped: yomitan-extension');
|
||||
}),
|
||||
warmupMecab
|
||||
? (async () => {
|
||||
deps.logDebug?.('[startup-warmup] stage start: mecab');
|
||||
|
||||
@@ -180,3 +180,29 @@ test('dictionary prewarm does not show OSD when notifications are disabled', asy
|
||||
|
||||
assert.deepEqual(osdMessages, []);
|
||||
});
|
||||
|
||||
test('dictionary prewarm clears loading OSD timer even if notifications are disabled before completion', async () => {
|
||||
const clearedTimers: unknown[] = [];
|
||||
const jlptDeferred = createDeferred();
|
||||
const freqDeferred = createDeferred();
|
||||
let shouldShowNotification = true;
|
||||
|
||||
const prewarm = createPrewarmSubtitleDictionariesMainHandler({
|
||||
ensureJlptDictionaryLookup: async () => jlptDeferred.promise,
|
||||
ensureFrequencyDictionaryLookup: async () => freqDeferred.promise,
|
||||
shouldShowOsdNotification: () => shouldShowNotification,
|
||||
showMpvOsd: () => undefined,
|
||||
setInterval: () => 'loading-timer',
|
||||
clearInterval: (timer) => {
|
||||
clearedTimers.push(timer);
|
||||
},
|
||||
});
|
||||
|
||||
const prewarmPromise = prewarm({ showLoadingOsd: true });
|
||||
shouldShowNotification = false;
|
||||
jlptDeferred.resolve();
|
||||
freqDeferred.resolve();
|
||||
await prewarmPromise;
|
||||
|
||||
assert.deepEqual(clearedTimers, ['loading-timer']);
|
||||
});
|
||||
|
||||
@@ -113,7 +113,7 @@ export function createPrewarmSubtitleDictionariesMainHandler(deps: {
|
||||
};
|
||||
|
||||
const endLoadingOsd = (): void => {
|
||||
if (!showMpvOsd || !shouldShowOsdNotification()) {
|
||||
if (!showMpvOsd) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user