ensure wl-copy is available

This commit is contained in:
Dax Raad
2025-11-01 11:10:39 -04:00
parent 55787f2caa
commit 1bc3c98ae7

View File

@@ -61,7 +61,7 @@ export namespace Clipboard {
const getCopyMethod = lazy(() => {
const os = platform()
if (os === "darwin") {
if (os === "darwin" && Bun.which("oascript")) {
console.log("clipboard: using osascript")
return async (text: string) => {
const escaped = text.replace(/\\/g, "\\\\").replace(/"/g, '\\"')
@@ -70,13 +70,13 @@ export namespace Clipboard {
}
if (os === "linux") {
if (process.env["WAYLAND_DISPLAY"]) {
if (process.env["WAYLAND_DISPLAY"] && Bun.which("wl-copy")) {
console.log("clipboard: using wl-copy")
return async (text: string) => {
const proc = Bun.spawn(["wl-copy"], { stdin: "pipe", stdout: "ignore", stderr: "ignore" })
proc.stdin.write(text)
proc.stdin.end()
await proc.exited
await proc.exited.catch(() => {})
}
}
if (Bun.which("xclip")) {
@@ -117,7 +117,7 @@ export namespace Clipboard {
console.log("clipboard: no native support")
return async (text: string) => {
await clipboardy.write(text)
await clipboardy.write(text).catch(() => {})
}
})