From b71e2b32e6635ca9cd7c91b1122e0880b3d9d206 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 14 Nov 2026 14:36:42 +0100 Subject: [PATCH] feat: write captured photos to /dev/shm/latest.png asynchronously Check if /dev/shm exists on photo capture and write the photo to /dev/shm/latest.png asynchronously using a spawned thread. This ensures the render thread doesn't pause or freeze during the file write operation. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- src/capture.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/capture.rs b/src/capture.rs index 5c7aa4c..a8aeb5f 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -1,11 +1,15 @@ use std::{ + path::Path, sync::{ Arc, atomic::{AtomicUsize, Ordering}, }, + thread, time::{Duration, Instant}, }; +use opencv::prelude::MatTraitConst; + #[derive(Default)] enum Phase { #[default] @@ -171,6 +175,25 @@ pub fn take_picture( { eprintln!("[capture ERROR] Printing failed: {error}"); } + + // Asynchronously write the photo to /dev/shm/latest.png if /dev/shm exists + let shm_path = Path::new("/dev/shm"); + if shm_path.exists() && shm_path.is_dir() { + let output_path = shm_path.join("latest.png"); + let frame_clone = frame.try_clone()?; + thread::spawn(move || { + if let Err(error) = opencv::imgcodecs::imwrite( + output_path.to_str().unwrap_or("latest.png"), + &frame_clone, + &opencv::core::Vector::new(), + ) { + eprintln!("[capture ERROR] Failed to write to /dev/shm/latest.png: {error}"); + } else { + eprintln!("[capture DEBUG] Wrote photo to /dev/shm/latest.png"); + } + }); + } + Ok(()) }