refactor: migrate clipboard.ts from Bun.file() to Filesystem module (#14148)
This commit is contained in:
@@ -4,6 +4,7 @@ import clipboardy from "clipboardy"
|
|||||||
import { lazy } from "../../../../util/lazy.js"
|
import { lazy } from "../../../../util/lazy.js"
|
||||||
import { tmpdir } from "os"
|
import { tmpdir } from "os"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
import { Filesystem } from "../../../../util/filesystem"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes text to clipboard via OSC 52 escape sequence.
|
* Writes text to clipboard via OSC 52 escape sequence.
|
||||||
@@ -34,9 +35,8 @@ export namespace Clipboard {
|
|||||||
await $`osascript -e 'set imageData to the clipboard as "PNGf"' -e 'set fileRef to open for access POSIX file "${tmpfile}" with write permission' -e 'set eof fileRef to 0' -e 'write imageData to fileRef' -e 'close access fileRef'`
|
await $`osascript -e 'set imageData to the clipboard as "PNGf"' -e 'set fileRef to open for access POSIX file "${tmpfile}" with write permission' -e 'set eof fileRef to 0' -e 'write imageData to fileRef' -e 'close access fileRef'`
|
||||||
.nothrow()
|
.nothrow()
|
||||||
.quiet()
|
.quiet()
|
||||||
const file = Bun.file(tmpfile)
|
const buffer = await Filesystem.readBytes(tmpfile)
|
||||||
const buffer = await file.arrayBuffer()
|
return { data: buffer.toString("base64"), mime: "image/png" }
|
||||||
return { data: Buffer.from(buffer).toString("base64"), mime: "image/png" }
|
|
||||||
} catch {
|
} catch {
|
||||||
} finally {
|
} finally {
|
||||||
await $`rm -f "${tmpfile}"`.nothrow().quiet()
|
await $`rm -f "${tmpfile}"`.nothrow().quiet()
|
||||||
|
|||||||
Reference in New Issue
Block a user