diff --git a/idevice/src/lib.rs b/idevice/src/lib.rs index 6d37459..185fe8b 100644 --- a/idevice/src/lib.rs +++ b/idevice/src/lib.rs @@ -89,16 +89,18 @@ impl Idevice { /// Sends raw bytes to the socket async fn send_raw(&mut self, message: &[u8]) -> Result<(), IdeviceError> { - self.send_raw_with_progress(message, |_| async {}).await + self.send_raw_with_progress(message, |_| async {}, ()).await } - async fn send_raw_with_progress( + async fn send_raw_with_progress( &mut self, message: &[u8], - callback: impl Fn((usize, usize)) -> Fut, + callback: impl Fn(((usize, usize), S)) -> Fut, + state: S, ) -> Result<(), IdeviceError> where Fut: std::future::Future, + S: Clone, { if let Some(socket) = &mut self.socket { let message_parts = message.chunks(1024 * 64); @@ -107,7 +109,7 @@ impl Idevice { for (i, part) in message_parts.enumerate() { debug!("Writing {i}/{part_len}"); socket.write_all(part).await?; - callback((i, part_len)).await; + callback(((i, part_len), state.clone())).await; } Ok(()) } else { diff --git a/idevice/src/mounter.rs b/idevice/src/mounter.rs index 9b47618..677d52c 100644 --- a/idevice/src/mounter.rs +++ b/idevice/src/mounter.rs @@ -80,19 +80,21 @@ impl ImageMounter { image: &[u8], signature: Vec, ) -> Result<(), IdeviceError> { - self.upload_image_with_progress(image_type, image, signature, |_| async {}) + self.upload_image_with_progress(image_type, image, signature, |_| async {}, ()) .await } - pub async fn upload_image_with_progress( + pub async fn upload_image_with_progress( &mut self, image_type: impl Into, image: &[u8], signature: Vec, - callback: impl Fn((usize, usize)) -> Fut, + callback: impl Fn(((usize, usize), S)) -> Fut, + state: S, ) -> Result<(), IdeviceError> where Fut: std::future::Future, + S: Clone, { let image_type = image_type.into(); let image_size = match u64::try_from(image.len()) { @@ -124,7 +126,9 @@ impl ImageMounter { } debug!("Sending image bytes"); - self.idevice.send_raw_with_progress(image, callback).await?; + self.idevice + .send_raw_with_progress(image, callback, state) + .await?; let res = self.idevice.read_plist().await?; match res.get("Status") { @@ -328,6 +332,7 @@ impl ImageMounter { info_plist, unique_chip_id, |_| async {}, + (), ) .await } @@ -335,7 +340,7 @@ impl ImageMounter { /// Calling this has the potential of closing the socket, /// so a provider is required for this abstraction. #[allow(clippy::too_many_arguments)] // literally nobody asked - pub async fn mount_personalized_with_callback( + pub async fn mount_personalized_with_callback( &mut self, provider: &dyn crate::provider::IdeviceProvider, image: Vec, @@ -343,10 +348,12 @@ impl ImageMounter { build_manifest: &[u8], info_plist: Option, unique_chip_id: u64, - callback: impl Fn((usize, usize)) -> Fut, + callback: impl Fn(((usize, usize), S)) -> Fut, + state: S, ) -> Result<(), IdeviceError> where Fut: std::future::Future, + S: Clone, { // Try to fetch personalization manifest let mut hasher = Sha384::new(); @@ -371,7 +378,7 @@ impl ImageMounter { }; debug!("Uploading imaage"); - self.upload_image_with_progress("Personalized", &image, manifest.clone(), callback) + self.upload_image_with_progress("Personalized", &image, manifest.clone(), callback, state) .await?; debug!("Mounting image");