diff --git a/Cargo.lock b/Cargo.lock index 55dd1e6..1294ec6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -424,7 +424,7 @@ dependencies = [ [[package]] name = "idevice" -version = "0.1.6" +version = "0.1.7" dependencies = [ "env_logger", "log", diff --git a/Cargo.toml b/Cargo.toml index 176c124..67b7568 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/heartbeat.rs b/src/heartbeat.rs index efc8016..a2cd33c 100644 --- a/src/heartbeat.rs +++ b/src/heartbeat.rs @@ -12,8 +12,14 @@ impl HeartbeatClient { Self { idevice } } - pub async fn get_marco(&mut self) -> Result { - let rec = self.idevice.read_plist().await?; + pub async fn get_marco(&mut self, interval: u64) -> Result { + // 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() { diff --git a/src/lib.rs b/src/lib.rs index a6a3954..a335cc1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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")]