mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-06-13 15:13:32 -07:00
fix(overlay): restore mpv focus and pointer state on macOS (#104)
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user