From d5036cf01f673a2d0069e0daf811f396a9eeb582 Mon Sep 17 00:00:00 2001 From: Abdul Rahman ArM <39548998+invarrow@users.noreply.github.com> Date: Sun, 8 Feb 2026 16:54:09 +0530 Subject: fix(desktop): add native clipboard image paste and fix text paste (#12682) --- packages/desktop/src/index.tsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'packages/desktop/src') 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): 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((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) -- cgit v1.2.3