correction + regexp
This commit is contained in:
@ -6,6 +6,8 @@ use std::time::SystemTime;
|
||||
use uuid::Uuid;
|
||||
use wayland_clipboard_listener::{WlClipboardPasteStream, WlListenType};
|
||||
|
||||
const MAX_IMAGE_PIXELS: usize = 3840 * 2160;
|
||||
|
||||
pub fn start(
|
||||
db: Arc<Mutex<Database>>,
|
||||
_clipboard: arboard::Clipboard,
|
||||
@ -17,7 +19,6 @@ pub fn start(
|
||||
|
||||
for msg in stream.paste_stream().flatten() {
|
||||
let context = &msg.context;
|
||||
|
||||
let data: &[u8] = context.context.as_slice();
|
||||
|
||||
if data.is_empty() {
|
||||
@ -26,11 +27,9 @@ pub fn start(
|
||||
|
||||
let entry = if let Ok(text) = String::from_utf8(data.to_vec()) {
|
||||
let text = text.trim_end_matches('\n').to_string();
|
||||
|
||||
if text.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
ClipboardEntry {
|
||||
content: ClipboardData::Text(text),
|
||||
timestamp: SystemTime::now(),
|
||||
@ -39,8 +38,20 @@ pub fn start(
|
||||
match image::load_from_memory(data) {
|
||||
Ok(img) => {
|
||||
let (width, height) = (img.width(), img.height());
|
||||
let rgba = img.into_rgba8();
|
||||
|
||||
if (width as usize) * (height as usize) > MAX_IMAGE_PIXELS {
|
||||
eprintln!(
|
||||
"Image Wayland ignorée : {}×{} ({} Mpx > limite {}×{})",
|
||||
width,
|
||||
height,
|
||||
(width as usize * height as usize) / 1_000_000,
|
||||
3840,
|
||||
2160
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
let rgba = img.into_rgba8();
|
||||
ClipboardEntry {
|
||||
content: ClipboardData::Image(Image {
|
||||
raw_pixels: Some(rgba.into_raw()),
|
||||
@ -52,7 +63,7 @@ pub fn start(
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Clipboard ignoré : {e}");
|
||||
eprintln!("Clipboard ignoré (format inconnu) : {e}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user