feat: 改进配置方式,重写逻辑。
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
|
||||
use scrap::Capturer;
|
||||
use std::{io::ErrorKind::WouldBlock, time::Duration, thread};
|
||||
|
||||
pub struct Screen {
|
||||
capturer: Option<Capturer>,
|
||||
@ -29,15 +29,24 @@ impl Screen {
|
||||
|
||||
pub fn take(&mut self) -> anyhow::Result<Vec<u8>> {
|
||||
match self.capturer.as_mut() {
|
||||
Some(capturer) => {
|
||||
let buffer = capturer
|
||||
.frame()
|
||||
.map_err(|error| anyhow::anyhow!("failed to frame of display. {}", error))?;
|
||||
anyhow::Ok(buffer.to_vec())
|
||||
}
|
||||
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 {}
|
||||
unsafe impl Send for Screen {}
|
||||
|
Reference in New Issue
Block a user