Files
SubMiner/src/renderer/utils/mpv-command-dispatch.ts
T
sudacode e49b5f6589 fix(overlay): send session help commands before closing the modal
- Closing help first could destroy the dedicated modal window on Linux/Windows, dropping the IPC for the selected command
- dispatchConfiguredMpvCommand now returns a promise so help closes only after subtitle seek + re-pause are sent
- Add test asserting IPC order for a paused subtitle seek
2026-09-29 20:22:01 -07:00

40 lines
1.2 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.
* Resolves once every command has been sent; it never rejects.
*/
export function dispatchConfiguredMpvCommand(
command: MpvCommand,
deps: {
getPlaybackPaused: () => Promise<boolean | null>;
sendMpvCommand: (command: MpvCommand) => void;
},
): Promise<void> {
if (!isSubtitleSeekCommand(command)) {
deps.sendMpvCommand(command);
return Promise.resolve();
}
// The fallback only covers a failed pause lookup, so a failed re-pause never resends the seek.
return 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));
}