mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-07 03:22:17 -08:00
fix: preserve pause state on next subtitle jump
This commit is contained in:
@@ -453,3 +453,46 @@ test('MpvIpcClient updates current audio stream index from track list', async ()
|
|||||||
|
|
||||||
assert.equal(client.currentAudioStreamIndex, 11);
|
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] }]);
|
||||||
|
});
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ export class MpvIpcClient implements MpvClient {
|
|||||||
osdDimensions: null,
|
osdDimensions: null,
|
||||||
};
|
};
|
||||||
private previousSecondarySubVisibility: boolean | null = null;
|
private previousSecondarySubVisibility: boolean | null = null;
|
||||||
|
private playbackPaused: boolean | null = null;
|
||||||
private pauseAtTime: number | null = null;
|
private pauseAtTime: number | null = null;
|
||||||
private pendingPauseAtSubEnd = false;
|
private pendingPauseAtSubEnd = false;
|
||||||
private nextDynamicRequestId = 1000;
|
private nextDynamicRequestId = 1000;
|
||||||
@@ -207,6 +208,7 @@ export class MpvIpcClient implements MpvClient {
|
|||||||
this.connected = false;
|
this.connected = false;
|
||||||
this.connecting = false;
|
this.connecting = false;
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
|
this.playbackPaused = null;
|
||||||
this.emit('connection-change', { connected: false });
|
this.emit('connection-change', { connected: false });
|
||||||
this.failPendingRequests();
|
this.failPendingRequests();
|
||||||
this.scheduleReconnect();
|
this.scheduleReconnect();
|
||||||
@@ -310,6 +312,7 @@ export class MpvIpcClient implements MpvClient {
|
|||||||
this.emit('time-pos-change', payload);
|
this.emit('time-pos-change', payload);
|
||||||
},
|
},
|
||||||
emitPauseChange: (payload) => {
|
emitPauseChange: (payload) => {
|
||||||
|
this.playbackPaused = payload.paused;
|
||||||
this.emit('pause-change', payload);
|
this.emit('pause-change', payload);
|
||||||
},
|
},
|
||||||
emitSecondarySubtitleChange: (payload) => {
|
emitSecondarySubtitleChange: (payload) => {
|
||||||
@@ -492,6 +495,12 @@ export class MpvIpcClient implements MpvClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
playNextSubtitle(): void {
|
playNextSubtitle(): void {
|
||||||
|
if (this.playbackPaused === true) {
|
||||||
|
this.pendingPauseAtSubEnd = false;
|
||||||
|
this.pauseAtTime = null;
|
||||||
|
this.send({ command: ['sub-seek', 1] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.pendingPauseAtSubEnd = true;
|
this.pendingPauseAtSubEnd = true;
|
||||||
this.send({ command: ['sub-seek', 1] });
|
this.send({ command: ['sub-seek', 1] });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user