mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-07-09 17:28:45 +00:00
Fix native clipboard in bun release (#6418)
* copy native clipboard .node files to the clipboard package
under the bun binary packaging, require("@mariozechner/clipboard-linux-x64-gnu")
doesn't work so instead we rely on require("./clipboard.linux-x64-gnu.node")
for that we need to copy the .node files to the clipboard package dir
* fallback to xclip if native clipboard fails on x11
This commit is contained in:
parent
7198e78f99
commit
62f45badae
3 changed files with 24 additions and 6 deletions
|
|
@ -277,7 +277,7 @@ export async function readClipboardImage(options?: {
|
|||
}
|
||||
|
||||
if (!image && !wayland) {
|
||||
image = await readClipboardImageViaNativeClipboard();
|
||||
image = (await readClipboardImageViaNativeClipboard()) ?? readClipboardImageViaXclip();
|
||||
}
|
||||
} else {
|
||||
image = await readClipboardImageViaNativeClipboard();
|
||||
|
|
|
|||
|
|
@ -147,7 +147,9 @@ describe("readClipboardImage", () => {
|
|||
|
||||
test("Non-Wayland: uses clipboard", async () => {
|
||||
mocks.spawnSync.mockImplementation(() => {
|
||||
throw new Error("spawnSync should not be called for non-Wayland sessions");
|
||||
throw new Error(
|
||||
"spawnSync should not be called for non-Wayland sessions when native clipboard returns an image",
|
||||
);
|
||||
});
|
||||
|
||||
mocks.clipboard.hasImage.mockReturnValue(true);
|
||||
|
|
@ -160,15 +162,23 @@ describe("readClipboardImage", () => {
|
|||
expect(Array.from(result?.bytes ?? [])).toEqual([7]);
|
||||
});
|
||||
|
||||
test("Non-Wayland: returns null when clipboard has no image", async () => {
|
||||
mocks.spawnSync.mockImplementation(() => {
|
||||
throw new Error("spawnSync should not be called for non-Wayland sessions");
|
||||
test("Non-Wayland: falls back to xclip when clipboard has no image", async () => {
|
||||
mocks.spawnSync.mockImplementation((command, args, _options) => {
|
||||
if (command === "xclip" && args.includes("TARGETS")) {
|
||||
return spawnOk(Buffer.from("image/png\n", "utf-8"));
|
||||
}
|
||||
if (command === "xclip" && args.includes("image/png")) {
|
||||
return spawnOk(Buffer.from([8, 9]));
|
||||
}
|
||||
throw new Error(`Unexpected spawnSync call: ${command} ${args.join(" ")}`);
|
||||
});
|
||||
|
||||
mocks.clipboard.hasImage.mockReturnValue(false);
|
||||
|
||||
const { readClipboardImage } = await import("../src/utils/clipboard-image.ts");
|
||||
const result = await readClipboardImage({ platform: "linux", env: {} });
|
||||
expect(result).toBeNull();
|
||||
expect(result).not.toBeNull();
|
||||
expect(result?.mimeType).toBe("image/png");
|
||||
expect(Array.from(result?.bytes ?? [])).toEqual([8, 9]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue