use arboard::Clipboard; use std::error::Error; use std::time::SystemTime; use uuid::Uuid; use crate::models::{ClipboardData, ClipboardEntry, Image}; // pub trait ImageDataExt { // fn to_png(&self) -> Result, Box>; // } // // impl ImageDataExt for ImageData<'_> { // fn to_png(&self) -> Result, Box> { // let mut buffer = Vec::new(); // let encoder = PngEncoder::new(&mut buffer); // encoder.write_image( // &self.bytes, // self.width as u32, // self.height as u32, // ExtendedColorType::Rgba8, // )?; // Ok(buffer) // } // } impl ClipboardEntry { pub fn new(clipboard: &mut Clipboard) -> Result> { let clipboard_data_opt: Option = match clipboard.get_text() { Ok(text) => Some(ClipboardData::Text(text)), Err(_) => match clipboard.get_image() { Ok(image) => { let id = Uuid::new_v4(); Some(ClipboardData::Image(Image { raw_pixels: Some(image.bytes.into_owned()), width: image.width as u32, height: image.height as u32, id, })) } Err(_) => None, }, }; let Some(clipboard_data) = clipboard_data_opt else { return Err("Clipboard empty".into()); }; Ok(ClipboardEntry { content: clipboard_data, timestamp: SystemTime::now(), }) } }