From e18b6eda77d1416899de450495f5c1b99023e675 Mon Sep 17 00:00:00 2001 From: sudacode Date: Wed, 20 May 2026 11:40:21 -0700 Subject: [PATCH] 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 --- src/main.ts | 14 +++++++++++++- src/main/main-wiring.test.ts | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 3978fa2f..97db301f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4247,11 +4247,23 @@ const { const normalizedPath = path.trim(); const previousPath = appState.currentMediaPath?.trim() || null; 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; + lastObservedTimePos = 0; appState.currentSubText = ''; appState.currentSubAssText = ''; 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(); currentMediaTokenizationGate.updateCurrentMediaPath(path); diff --git a/src/main/main-wiring.test.ts b/src/main/main-wiring.test.ts index 50812fbd..2a7bc4b1 100644 --- a/src/main/main-wiring.test.ts +++ b/src/main/main-wiring.test.ts @@ -31,7 +31,12 @@ test('media path changes clear rendered subtitle state', () => { assert.match(actionBlock, /appState\.currentSubText = '';/); assert.match(actionBlock, /appState\.currentSubAssText = '';/); 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, /subtitleWsService\.broadcast\(/); + assert.match(actionBlock, /annotationSubtitleWsService\.broadcast\(/); assert.ok( actionBlock.indexOf('appState.currentSubtitleData = null;') < actionBlock.indexOf("broadcastToOverlayWindows('subtitle:set'"),