fix: reset WS subtitle state and parsed cues on media path change

- Clear activeParsedSubtitleCues, activeParsedSubtitleSource, lastObservedTimePos
- Broadcast reset payload to subtitleWsService and annotationSubtitleWsService
- Extend wiring test to cover new reset fields and WS broadcasts
This commit is contained in:
2026-05-20 11:40:21 -07:00
parent 1145e131da
commit e18b6eda77
2 changed files with 18 additions and 1 deletions
+13 -1
View File
@@ -4247,11 +4247,23 @@ const {
const normalizedPath = path.trim(); const normalizedPath = path.trim();
const previousPath = appState.currentMediaPath?.trim() || null; const previousPath = appState.currentMediaPath?.trim() || null;
if ((normalizedPath || null) !== previousPath) { if ((normalizedPath || null) !== previousPath) {
const resetSubtitlePayload = { text: '', tokens: null };
const frequencyDictionary = getResolvedConfig().subtitleStyle.frequencyDictionary;
const frequencyOptions = {
enabled: frequencyDictionary.enabled,
topX: frequencyDictionary.topX,
mode: frequencyDictionary.mode,
};
autoplaySubtitlePrimedMediaPath = null; autoplaySubtitlePrimedMediaPath = null;
lastObservedTimePos = 0;
appState.currentSubText = ''; appState.currentSubText = '';
appState.currentSubAssText = ''; appState.currentSubAssText = '';
appState.currentSubtitleData = null; appState.currentSubtitleData = null;
broadcastToOverlayWindows('subtitle:set', { text: '', tokens: null }); appState.activeParsedSubtitleCues = [];
appState.activeParsedSubtitleSource = null;
broadcastToOverlayWindows('subtitle:set', resetSubtitlePayload);
subtitleWsService.broadcast(resetSubtitlePayload, frequencyOptions);
annotationSubtitleWsService.broadcast(resetSubtitlePayload, frequencyOptions);
} }
autoplayReadyGate.invalidatePendingAutoplayReadyFallbacks(); autoplayReadyGate.invalidatePendingAutoplayReadyFallbacks();
currentMediaTokenizationGate.updateCurrentMediaPath(path); currentMediaTokenizationGate.updateCurrentMediaPath(path);
+5
View File
@@ -31,7 +31,12 @@ test('media path changes clear rendered subtitle state', () => {
assert.match(actionBlock, /appState\.currentSubText = '';/); assert.match(actionBlock, /appState\.currentSubText = '';/);
assert.match(actionBlock, /appState\.currentSubAssText = '';/); assert.match(actionBlock, /appState\.currentSubAssText = '';/);
assert.match(actionBlock, /appState\.currentSubtitleData = null;/); assert.match(actionBlock, /appState\.currentSubtitleData = null;/);
assert.match(actionBlock, /appState\.activeParsedSubtitleCues = \[\];/);
assert.match(actionBlock, /appState\.activeParsedSubtitleSource = null;/);
assert.match(actionBlock, /lastObservedTimePos = 0;/);
assert.match(actionBlock, /broadcastToOverlayWindows\('subtitle:set',/); assert.match(actionBlock, /broadcastToOverlayWindows\('subtitle:set',/);
assert.match(actionBlock, /subtitleWsService\.broadcast\(/);
assert.match(actionBlock, /annotationSubtitleWsService\.broadcast\(/);
assert.ok( assert.ok(
actionBlock.indexOf('appState.currentSubtitleData = null;') < actionBlock.indexOf('appState.currentSubtitleData = null;') <
actionBlock.indexOf("broadcastToOverlayWindows('subtitle:set'"), actionBlock.indexOf("broadcastToOverlayWindows('subtitle:set'"),