Add list_processes

This commit is contained in:
Jackson Coxson
2025-07-19 11:43:57 -06:00
parent 0a3c1b9c03
commit 7fbe1d8a43
2 changed files with 35 additions and 0 deletions

View File

@@ -65,6 +65,14 @@ pub struct ExecutableUrl {
pub relative: String,
}
#[derive(Deserialize, Clone, Debug)]
pub struct ProcessToken {
#[serde(rename = "processIdentifier")]
pub pid: u32,
#[serde(rename = "executableURL")]
pub executable_url: Option<ExecutableUrl>,
}
impl<R: ReadWrite> AppServiceClient<R> {
pub async fn new(stream: R) -> Result<Self, IdeviceError> {
Ok(Self {
@@ -166,4 +174,27 @@ impl<R: ReadWrite> AppServiceClient<R> {
Ok(res)
}
pub async fn list_processes(&mut self) -> Result<Vec<ProcessToken>, IdeviceError> {
let res = self
.inner
.invoke("com.apple.coredevice.feature.listprocesses", None)
.await?;
println!("{}", pretty_print_plist(&res));
let res = match res
.as_dictionary()
.and_then(|x| x.get("processTokens"))
.and_then(|x| plist::from_value(x).unwrap())
{
Some(r) => r,
None => {
warn!("CoreDevice res did not contain parsable processToken");
return Err(IdeviceError::UnexpectedResponse);
}
};
Ok(res)
}
}