mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-09-30 17:40:53 -07:00
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
type MpvCommand = (string | number)[];
|
|
|
|
function isSubtitleSeekCommand(command: MpvCommand): command is [string, number] {
|
|
return command[0] === 'sub-seek' && typeof command[1] === 'number';
|
|
}
|
|
|
|
/**
|
|
* Sends a configured mpv command. Subtitle seeks re-pause afterwards unless playback
|
|
* is known to be running, so stepping lines from a paused video stays paused.
|
|
*/
|
|
export function dispatchConfiguredMpvCommand(
|
|
command: MpvCommand,
|
|
deps: {
|
|
getPlaybackPaused: () => Promise<boolean | null>;
|
|
sendMpvCommand: (command: MpvCommand) => void;
|
|
},
|
|
): void {
|
|
if (!isSubtitleSeekCommand(command)) {
|
|
deps.sendMpvCommand(command);
|
|
return;
|
|
}
|
|
|
|
// The fallback only covers a failed pause lookup, so a failed re-pause never resends the seek.
|
|
void deps
|
|
.getPlaybackPaused()
|
|
.then(
|
|
(paused) => {
|
|
deps.sendMpvCommand(command);
|
|
if (paused !== false) {
|
|
deps.sendMpvCommand(['set_property', 'pause', 'yes']);
|
|
}
|
|
},
|
|
() => {
|
|
deps.sendMpvCommand(command);
|
|
},
|
|
)
|
|
.catch((error: unknown) => console.error('Could not send mpv command', error));
|
|
}
|