mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-09-30 17:40:53 -07:00
feat(overlay): run session help commands with Enter or double-click (#275)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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));
|
||||
}
|
||||
Reference in New Issue
Block a user