use plist::Value;
use crate::{
IdeviceError, ReadWrite,
dvt::remote_server::{Channel, RemoteServerClient},
obf,
};
#[derive(Debug)]
pub struct ScreenshotClient<'a, R: ReadWrite> {
channel: Channel<'a, R>,
}
impl<'a, R: ReadWrite> ScreenshotClient<'a, R> {
pub async fn new(client: &'a mut RemoteServerClient<R>) -> Result<Self, IdeviceError> {
let channel = client
.make_channel(obf!("com.apple.instruments.server.services.screenshot"))
.await?;
Ok(Self { channel })
}
pub async fn take_screenshot(&mut self) -> Result<Vec<u8>, IdeviceError> {
let method = Value::String("takeScreenshot".into());
self.channel.call_method(Some(method), None, true).await?;
let msg = self.channel.read_message().await?;
match msg.data {
Some(Value::Data(data)) => Ok(data),
_ => Err(IdeviceError::UnexpectedResponse(
"missing screenshot data in DVT response".into(),
)),
}
}
}