use scrap::Capturer; use std::{io::ErrorKind::WouldBlock, time::Duration, thread}; pub struct Screen { capturer: Option, pub width: usize, pub height: usize, } impl Screen { pub fn new(capturer: Capturer, width: usize, height: usize) -> Self { Self { capturer: Some(capturer), width, height, } } pub fn take(&mut self) -> anyhow::Result> { match self.capturer.as_mut() { Some(capturer) => loop { match capturer.frame() { Ok(buffer) => { return anyhow::Ok(buffer.to_vec()); } Err(error) => { if error.kind() == WouldBlock { thread::sleep(Duration::from_millis(16)); continue; } else { anyhow::bail!("failed to frame of display. {}", error); } } } }, None => anyhow::bail!("Do not initialized"), } } } unsafe impl Send for Screen {}