summaryrefslogtreecommitdiffhomepage
path: root/packages/desktop/src
diff options
context:
space:
mode:
authorAbdul Rahman ArM <[email protected]>2026-02-08 16:54:09 +0530
committerGitHub <[email protected]>2026-02-08 11:24:09 +0000
commitd5036cf01f673a2d0069e0daf811f396a9eeb582 (patch)
tree22d932530276c7094d73aaa561890eb5945b78d2 /packages/desktop/src
parentd1ebe0767c264d395c8bc504c0957ccc3af90103 (diff)
downloadopencode-d5036cf01f673a2d0069e0daf811f396a9eeb582.tar.gz
opencode-d5036cf01f673a2d0069e0daf811f396a9eeb582.zip
fix(desktop): add native clipboard image paste and fix text paste (#12682)
Diffstat (limited to 'packages/desktop/src')
-rw-r--r--packages/desktop/src/index.tsx24
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsx
index d3377e95a..dd78224e3 100644
--- a/packages/desktop/src/index.tsx
+++ b/packages/desktop/src/index.tsx
@@ -16,6 +16,7 @@ import { fetch as tauriFetch } from "@tauri-apps/plugin-http"
import { Store } from "@tauri-apps/plugin-store"
import { Splash } from "@opencode-ai/ui/logo"
import { createSignal, Show, Accessor, JSX, createResource, onMount, onCleanup } from "solid-js"
+import { readImage } from "@tauri-apps/plugin-clipboard-manager"
import { UPDATER_ENABLED } from "./updater"
import { initI18n, t } from "./i18n"
@@ -344,6 +345,29 @@ const createPlatform = (password: Accessor<string | null>): Platform => ({
checkAppExists: async (appName: string) => {
return commands.checkAppExists(appName)
},
+
+ async readClipboardImage() {
+ const image = await readImage().catch(() => null)
+ if (!image) return null
+ const bytes = await image.rgba().catch(() => null)
+ if (!bytes || bytes.length === 0) return null
+ const size = await image.size().catch(() => null)
+ if (!size) return null
+ const canvas = document.createElement("canvas")
+ canvas.width = size.width
+ canvas.height = size.height
+ const ctx = canvas.getContext("2d")
+ if (!ctx) return null
+ const imageData = ctx.createImageData(size.width, size.height)
+ imageData.data.set(bytes)
+ ctx.putImageData(imageData, 0, 0)
+ return new Promise<File | null>((resolve) => {
+ canvas.toBlob((blob) => {
+ if (!blob) return resolve(null)
+ resolve(new File([blob], `pasted-image-${Date.now()}.png`, { type: "image/png" }))
+ }, "image/png")
+ })
+ },
})
let menuTrigger = null as null | ((id: string) => void)