mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Add interval timeout to heartbeat
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -424,7 +424,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "idevice"
|
name = "idevice"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
name = "idevice"
|
name = "idevice"
|
||||||
description = "A Rust library to interact with services on iOS devices."
|
description = "A Rust library to interact with services on iOS devices."
|
||||||
authors = ["Jackson Coxson"]
|
authors = ["Jackson Coxson"]
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
documentation = "https://docs.rs/idevice"
|
documentation = "https://docs.rs/idevice"
|
||||||
|
|||||||
@@ -12,8 +12,14 @@ impl HeartbeatClient {
|
|||||||
Self { idevice }
|
Self { idevice }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_marco(&mut self) -> Result<u64, IdeviceError> {
|
pub async fn get_marco(&mut self, interval: u64) -> Result<u64, IdeviceError> {
|
||||||
let rec = self.idevice.read_plist().await?;
|
// 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") {
|
match rec.get("Interval") {
|
||||||
Some(plist::Value::Integer(interval)) => {
|
Some(plist::Value::Integer(interval)) => {
|
||||||
if let Some(interval) = interval.as_unsigned() {
|
if let Some(interval) = interval.as_unsigned() {
|
||||||
|
|||||||
@@ -141,6 +141,8 @@ pub enum IdeviceError {
|
|||||||
NoEstablishedConnection,
|
NoEstablishedConnection,
|
||||||
#[error("device went to sleep")]
|
#[error("device went to sleep")]
|
||||||
HeartbeatSleepyTime,
|
HeartbeatSleepyTime,
|
||||||
|
#[error("heartbeat timeout")]
|
||||||
|
HeartbeatTimeout,
|
||||||
#[error("not found")]
|
#[error("not found")]
|
||||||
NotFound,
|
NotFound,
|
||||||
#[error("unknown error `{0}` returned from device")]
|
#[error("unknown error `{0}` returned from device")]
|
||||||
|
|||||||
Reference in New Issue
Block a user