diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 73f8756b8..1e13d03a6 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1750,6 +1750,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573" + [[package]] name = "httparse" version = "1.10.1" @@ -4494,6 +4500,7 @@ dependencies = [ "gtk", "heck 0.5.0", "http", + "http-range", "jni", "libc", "log", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 9ff5aeb3b..58081177e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -19,7 +19,7 @@ crate-type = ["staticlib", "cdylib", "rlib"] tauri-build = { version = "2", features = [] } [dependencies] -tauri = { version = "2", features = ["macos-private-api"] } +tauri = { version = "2", features = ["protocol-asset", "macos-private-api"] } tauri-plugin-opener = "2" tauri-plugin-process = "2" serde = { version = "1", features = ["derive"] } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 6e87bb07d..65c7299ad 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -33,7 +33,11 @@ } ], "security": { - "csp": null + "csp": null, + "assetProtocol": { + "enable": true, + "scope": ["**/*"] + } } }, "bundle": { diff --git a/src/features/composer/components/ComposerAttachments.tsx b/src/features/composer/components/ComposerAttachments.tsx index e9496be4e..a9da9fee6 100644 --- a/src/features/composer/components/ComposerAttachments.tsx +++ b/src/features/composer/components/ComposerAttachments.tsx @@ -1,3 +1,4 @@ +import { convertFileSrc } from "@tauri-apps/api/core"; import { Image, X } from "lucide-react"; type ComposerAttachmentsProps = { @@ -18,6 +19,20 @@ function fileTitle(path: string) { return parts.length ? parts[parts.length - 1] : path; } +function attachmentPreviewSrc(path: string) { + if (path.startsWith("data:")) { + return path; + } + if (path.startsWith("http://") || path.startsWith("https://")) { + return path; + } + try { + return convertFileSrc(path); + } catch { + return ""; + } +} + export function ComposerAttachments({ attachments, disabled, @@ -32,15 +47,27 @@ export function ComposerAttachments({ {attachments.map((path) => { const title = fileTitle(path); const titleAttr = path.startsWith("data:") ? "Pasted image" : path; + const previewSrc = attachmentPreviewSrc(path); return (