feat(browser): copy extension path to clipboard
This commit is contained in:
23
src/infra/clipboard.ts
Normal file
23
src/infra/clipboard.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { runCommandWithTimeout } from "../process/exec.js";
|
||||
|
||||
export async function copyToClipboard(value: string): Promise<boolean> {
|
||||
const attempts: Array<{ argv: string[] }> = [
|
||||
{ argv: ["pbcopy"] },
|
||||
{ argv: ["xclip", "-selection", "clipboard"] },
|
||||
{ argv: ["wl-copy"] },
|
||||
{ argv: ["clip.exe"] }, // WSL / Windows
|
||||
{ argv: ["powershell", "-NoProfile", "-Command", "Set-Clipboard"] },
|
||||
];
|
||||
for (const attempt of attempts) {
|
||||
try {
|
||||
const result = await runCommandWithTimeout(attempt.argv, {
|
||||
timeoutMs: 3_000,
|
||||
input: value,
|
||||
});
|
||||
if (result.code === 0 && !result.killed) return true;
|
||||
} catch {
|
||||
// keep trying the next fallback
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user