Skip to content

Commit

Permalink
fix(clipboard-manager): read_image wrongly set the image rgba data …
Browse files Browse the repository at this point in the history
…with binary PNG data. (#1986)

* fix(clipboard-manager): `read_image` wrongly set the image rgba data with binary PNG data.

* remove depencency of `image` crate; add patch file
  • Loading branch information
RikaKagurasaka authored Oct 30, 2024
1 parent 1f649c7 commit d57df4d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-1985.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"clipboard-manager": patch
---

Fix that `read_image` wrongly set the image rgba data with binary PNG data.
1 change: 0 additions & 1 deletion plugins/clipboard-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ tauri = { workspace = true, features = ["wry"] }

[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
arboard = "3"
image = "0.25"
12 changes: 3 additions & 9 deletions plugins/clipboard-manager/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: MIT

use arboard::ImageData;
use image::ImageEncoder;
use serde::de::DeserializeOwned;
use tauri::{image::Image, plugin::PluginApi, AppHandle, Runtime};

Expand Down Expand Up @@ -85,16 +84,11 @@ impl<R: Runtime> Clipboard<R> {
match &self.clipboard {
Ok(clipboard) => {
let image = clipboard.lock().unwrap().get_image()?;

let mut buffer: Vec<u8> = Vec::new();
image::codecs::png::PngEncoder::new(&mut buffer).write_image(
&image.bytes,
let image = Image::new_owned(
image.bytes.to_vec(),
image.width as u32,
image.height as u32,
image::ExtendedColorType::Rgba8,
)?;

let image = Image::new_owned(buffer, image.width as u32, image.height as u32);
);
Ok(image)
}
Err(e) => Err(crate::Error::Clipboard(e.to_string())),
Expand Down
3 changes: 0 additions & 3 deletions plugins/clipboard-manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ pub enum Error {
Clipboard(String),
#[error(transparent)]
Tauri(#[from] tauri::Error),
#[cfg(desktop)]
#[error("invalid image: {0}")]
Image(#[from] image::ImageError),
}

impl Serialize for Error {
Expand Down

0 comments on commit d57df4d

Please sign in to comment.