opti
This commit is contained in:
Binary file not shown.
@ -80,26 +80,30 @@ impl Database {
|
||||
ClipboardData::Image(img) => {
|
||||
match &img.raw_pixels {
|
||||
Some(px) => {
|
||||
if px.len() > self.max_entry_size_bytes * 4 {
|
||||
eprintln!(
|
||||
"Image rejetée dans DB : {} Mo > limite {} Mo",
|
||||
px.len() / 1_048_576,
|
||||
(self.max_entry_size_bytes * 4) / 1_048_576
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
let path = img.file_path(&self.dir_path);
|
||||
let file = fs::File::create(&path)?;
|
||||
let rgb: Vec<u8> = px
|
||||
.chunks_exact(4)
|
||||
.flat_map(|rgba| [rgba[0], rgba[1], rgba[2]])
|
||||
.collect();
|
||||
JpegEncoder::new_with_quality(file, 70).write_image(
|
||||
|
||||
let mut jpeg_buf = Vec::new();
|
||||
JpegEncoder::new_with_quality(&mut jpeg_buf, 70).write_image(
|
||||
&rgb,
|
||||
img.width,
|
||||
img.height,
|
||||
ExtendedColorType::Rgb8,
|
||||
)?;
|
||||
|
||||
if jpeg_buf.len() > self.max_entry_size_bytes {
|
||||
eprintln!(
|
||||
"Image rejetée dans DB : JPEG {} Ko > limite {} Ko",
|
||||
jpeg_buf.len() / 1024,
|
||||
self.max_entry_size_bytes / 1024
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let path = img.file_path(&self.dir_path);
|
||||
fs::write(&path, &jpeg_buf)?;
|
||||
}
|
||||
None => return Ok(()),
|
||||
}
|
||||
|
||||
@ -9,7 +9,13 @@ pub fn start(db: Arc<Mutex<Database>>, clipboard: Clipboard) -> Result<(), Box<d
|
||||
|
||||
std::thread::spawn(move || {
|
||||
for entry in rx {
|
||||
let lock = db.lock().unwrap();
|
||||
let lock = match db.lock() {
|
||||
Ok(l) => l,
|
||||
Err(poisoned) => {
|
||||
eprintln!("Mutex DB empoisonné, récupération forcée");
|
||||
poisoned.into_inner()
|
||||
}
|
||||
};
|
||||
if let Err(e) = lock.append(entry) {
|
||||
eprintln!("SQLite write error: {e}");
|
||||
} else {
|
||||
|
||||
@ -114,7 +114,8 @@ fn handle_clipboard_event(
|
||||
img_data.height,
|
||||
pixel_count / 1_000_000
|
||||
);
|
||||
*last_image_hash = Some(pixel_count as u64);
|
||||
let sentinel_hash = hash_bytes(&img_data.bytes[..img_data.bytes.len().min(256)]);
|
||||
*last_image_hash = Some(sentinel_hash);
|
||||
*last_text = None;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user