fix(overlay): restore mpv focus and pointer state on macOS (#104)

This commit is contained in:
2026-05-31 21:25:04 -07:00
committed by GitHub
parent e1ea464bc9
commit b510c54875
21 changed files with 373 additions and 28 deletions
+35
View File
@@ -0,0 +1,35 @@
import { execFile as nodeExecFile } from 'node:child_process';
const FOCUS_MPV_PROCESS_SCRIPT =
'tell application "System Events" to set frontmost of the first process whose name is "mpv" to true';
type ExecFileForMacOSFocus = (
command: string,
args: string[],
options: { timeout: number },
callback: (error: Error | null) => void,
) => void;
export type MacOSMpvFocusDeps = {
execFile?: ExecFileForMacOSFocus;
};
export async function focusMacOSMpvProcess(deps: MacOSMpvFocusDeps = {}): Promise<void> {
const execFile: ExecFileForMacOSFocus =
deps.execFile ??
((command, args, options, callback) => {
nodeExecFile(command, args, options, (error) => {
callback(error);
});
});
await new Promise<void>((resolve, reject) => {
execFile('/usr/bin/osascript', ['-e', FOCUS_MPV_PROCESS_SCRIPT], { timeout: 2000 }, (error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
}