From 8570b262e42e9688db66f2874559faf34628e0de Mon Sep 17 00:00:00 2001 From: sudacode Date: Thu, 5 Mar 2026 22:47:38 -0800 Subject: [PATCH] fix: preserve pause state on next subtitle jump --- src/core/services/mpv.test.ts | 43 +++++++++++++++++++++++++++++++++++ src/core/services/mpv.ts | 9 ++++++++ 2 files changed, 52 insertions(+) diff --git a/src/core/services/mpv.test.ts b/src/core/services/mpv.test.ts index 7f18d5e..f4a388e 100644 --- a/src/core/services/mpv.test.ts +++ b/src/core/services/mpv.test.ts @@ -453,3 +453,46 @@ test('MpvIpcClient updates current audio stream index from track list', async () assert.equal(client.currentAudioStreamIndex, 11); }); + +test('MpvIpcClient playNextSubtitle preserves a manual paused state', async () => { + const commands: unknown[] = []; + const client = new MpvIpcClient('/tmp/mpv.sock', makeDeps()); + (client as any).send = (payload: unknown) => { + commands.push(payload); + return true; + }; + (client as any).pendingPauseAtSubEnd = true; + (client as any).pauseAtTime = 42; + + await invokeHandleMessage(client, { + event: 'property-change', + name: 'pause', + data: true, + }); + + client.playNextSubtitle(); + + assert.equal((client as any).pendingPauseAtSubEnd, false); + assert.equal((client as any).pauseAtTime, null); + assert.deepEqual(commands, [{ command: ['sub-seek', 1] }]); +}); + +test('MpvIpcClient playNextSubtitle still auto-pauses at end while already playing', async () => { + const commands: unknown[] = []; + const client = new MpvIpcClient('/tmp/mpv.sock', makeDeps()); + (client as any).send = (payload: unknown) => { + commands.push(payload); + return true; + }; + + await invokeHandleMessage(client, { + event: 'property-change', + name: 'pause', + data: false, + }); + + client.playNextSubtitle(); + + assert.equal((client as any).pendingPauseAtSubEnd, true); + assert.deepEqual(commands, [{ command: ['sub-seek', 1] }]); +}); diff --git a/src/core/services/mpv.ts b/src/core/services/mpv.ts index 50c0e74..a555161 100644 --- a/src/core/services/mpv.ts +++ b/src/core/services/mpv.ts @@ -161,6 +161,7 @@ export class MpvIpcClient implements MpvClient { osdDimensions: null, }; private previousSecondarySubVisibility: boolean | null = null; + private playbackPaused: boolean | null = null; private pauseAtTime: number | null = null; private pendingPauseAtSubEnd = false; private nextDynamicRequestId = 1000; @@ -207,6 +208,7 @@ export class MpvIpcClient implements MpvClient { this.connected = false; this.connecting = false; this.socket = null; + this.playbackPaused = null; this.emit('connection-change', { connected: false }); this.failPendingRequests(); this.scheduleReconnect(); @@ -310,6 +312,7 @@ export class MpvIpcClient implements MpvClient { this.emit('time-pos-change', payload); }, emitPauseChange: (payload) => { + this.playbackPaused = payload.paused; this.emit('pause-change', payload); }, emitSecondarySubtitleChange: (payload) => { @@ -492,6 +495,12 @@ export class MpvIpcClient implements MpvClient { } playNextSubtitle(): void { + if (this.playbackPaused === true) { + this.pendingPauseAtSubEnd = false; + this.pauseAtTime = null; + this.send({ command: ['sub-seek', 1] }); + return; + } this.pendingPauseAtSubEnd = true; this.send({ command: ['sub-seek', 1] }); }