mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-23 10:44:21 +01:00
paste images in wsl using ctrl+v (#4123)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { $ } from "bun"
|
import { $ } from "bun"
|
||||||
import { platform } from "os"
|
import { platform, release } from "os"
|
||||||
import clipboardy from "clipboardy"
|
import clipboardy from "clipboardy"
|
||||||
import { lazy } from "../../../../util/lazy.js"
|
import { lazy } from "../../../../util/lazy.js"
|
||||||
import { tmpdir } from "os"
|
import { tmpdir } from "os"
|
||||||
@@ -29,6 +29,18 @@ export namespace Clipboard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (os === "win32" || release().includes("WSL")) {
|
||||||
|
const script =
|
||||||
|
"Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }"
|
||||||
|
const base64 = await $`powershell.exe -command "${script}"`.nothrow().text()
|
||||||
|
if (base64) {
|
||||||
|
const imageBuffer = Buffer.from(base64.trim(), "base64")
|
||||||
|
if (imageBuffer.length > 0) {
|
||||||
|
return { data: imageBuffer.toString("base64"), mime: "image/png" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (os === "linux") {
|
if (os === "linux") {
|
||||||
const wayland = await $`wl-paste -t image/png`.nothrow().arrayBuffer()
|
const wayland = await $`wl-paste -t image/png`.nothrow().arrayBuffer()
|
||||||
if (wayland && wayland.byteLength > 0) {
|
if (wayland && wayland.byteLength > 0) {
|
||||||
@@ -40,18 +52,6 @@ export namespace Clipboard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os === "win32") {
|
|
||||||
const script =
|
|
||||||
"Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }"
|
|
||||||
const base64 = await $`powershell -command "${script}"`.nothrow().text()
|
|
||||||
if (base64) {
|
|
||||||
const imageBuffer = Buffer.from(base64.trim(), "base64")
|
|
||||||
if (imageBuffer.length > 0) {
|
|
||||||
return { data: imageBuffer.toString("base64"), mime: "image/png" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const text = await clipboardy.read().catch(() => {})
|
const text = await clipboardy.read().catch(() => {})
|
||||||
if (text) {
|
if (text) {
|
||||||
return { data: text, mime: "text/plain" }
|
return { data: text, mime: "text/plain" }
|
||||||
|
|||||||
Reference in New Issue
Block a user