Add interval timeout to heartbeat

This commit is contained in:
Jackson Coxson
2025-01-23 09:38:43 -07:00
parent 45811dc977
commit f589ad661b
4 changed files with 12 additions and 4 deletions

2
Cargo.lock generated
View File

@@ -424,7 +424,7 @@ dependencies = [
[[package]]
name = "idevice"
version = "0.1.6"
version = "0.1.7"
dependencies = [
"env_logger",
"log",

View File

@@ -2,7 +2,7 @@
name = "idevice"
description = "A Rust library to interact with services on iOS devices."
authors = ["Jackson Coxson"]
version = "0.1.6"
version = "0.1.7"
edition = "2021"
license = "MIT"
documentation = "https://docs.rs/idevice"

View File

@@ -12,8 +12,14 @@ impl HeartbeatClient {
Self { idevice }
}
pub async fn get_marco(&mut self) -> Result<u64, IdeviceError> {
let rec = self.idevice.read_plist().await?;
pub async fn get_marco(&mut self, interval: u64) -> Result<u64, IdeviceError> {
// Get a plist or wait for the interval
let rec = tokio::select! {
rec = self.idevice.read_plist() => rec?,
_ = tokio::time::sleep(tokio::time::Duration::from_secs(interval)) => {
return Err(IdeviceError::HeartbeatTimeout)
}
};
match rec.get("Interval") {
Some(plist::Value::Integer(interval)) => {
if let Some(interval) = interval.as_unsigned() {

View File

@@ -141,6 +141,8 @@ pub enum IdeviceError {
NoEstablishedConnection,
#[error("device went to sleep")]
HeartbeatSleepyTime,
#[error("heartbeat timeout")]
HeartbeatTimeout,
#[error("not found")]
NotFound,
#[error("unknown error `{0}` returned from device")]