mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-01 19:42:03 +00:00
* fix(cli): use 'where' instead of 'which' on Windows for FFmpeg and browser detection - findFFmpeg() now uses 'where ffmpeg' on Windows, 'which ffmpeg' on Unix - whichBinary() now uses 'where' on Windows, 'which' on Unix Fixes FFmpeg detection failure on Windows where 'which' command doesn't exist. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(cli): handle multi-line output from Windows 'where' command Windows 'where' can return multiple paths (one per line) when there are multiple matches on PATH. Take only the first non-empty line. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(cli): extend Windows 'where' fix to whisper, tts, and clipboard modules - whisper/manager.ts: whichBinary() now uses 'where' on Windows - tts/synthesize.ts: findPython() now uses 'where' on Windows - utils/clipboard.ts: detectProvider() now uses 'where' on Windows All functions handle multi-line output from 'where' command. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
/**
|
|
* Minimal cross-platform clipboard copy. Shells out to the OS tool; gracefully
|
|
* no-ops when no tool is available (CI, headless SSH, etc.) so callers can
|
|
* always invoke it without guarding.
|
|
*
|
|
* Returns true if the copy succeeded, false otherwise.
|
|
*/
|
|
|
|
import { spawnSync } from "node:child_process";
|
|
import { platform } from "node:os";
|
|
|
|
interface ClipboardProvider {
|
|
cmd: string;
|
|
args: string[];
|
|
}
|
|
|
|
function detectProvider(): ClipboardProvider | undefined {
|
|
const os = platform();
|
|
if (os === "darwin") {
|
|
return { cmd: "pbcopy", args: [] };
|
|
}
|
|
if (os === "win32") {
|
|
return { cmd: "clip.exe", args: [] };
|
|
}
|
|
// Linux / BSD — pick the first tool that's on PATH.
|
|
// WSL exposes clip.exe too; prefer it so copies land in the Windows
|
|
// clipboard where the user actually sees them.
|
|
const candidates: ClipboardProvider[] = [
|
|
{ cmd: "clip.exe", args: [] },
|
|
{ cmd: "wl-copy", args: [] },
|
|
{ cmd: "xclip", args: ["-selection", "clipboard"] },
|
|
{ cmd: "xsel", args: ["--clipboard", "--input"] },
|
|
];
|
|
const cmd = process.platform === "win32" ? "where" : "which";
|
|
for (const p of candidates) {
|
|
const result = spawnSync(cmd, [p.cmd], { stdio: "ignore" });
|
|
if (result.status === 0) return p;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
let cachedProvider: ClipboardProvider | undefined | null = null;
|
|
|
|
export function copyToClipboard(text: string): boolean {
|
|
if (cachedProvider === null) cachedProvider = detectProvider();
|
|
const provider = cachedProvider;
|
|
if (!provider) return false;
|
|
try {
|
|
const res = spawnSync(provider.cmd, provider.args, {
|
|
input: text,
|
|
encoding: "utf-8",
|
|
});
|
|
return res.status === 0;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|