mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Add progress callback for upload image
This commit is contained in:
@@ -44,7 +44,7 @@ usbmuxd = []
|
|||||||
tcp = ["tokio/net"]
|
tcp = ["tokio/net"]
|
||||||
tss = ["dep:uuid", "dep:reqwest"]
|
tss = ["dep:uuid", "dep:reqwest"]
|
||||||
xpc = [
|
xpc = [
|
||||||
"tokio/full",
|
"tokio/sync",
|
||||||
"dep:indexmap",
|
"dep:indexmap",
|
||||||
"dep:uuid",
|
"dep:uuid",
|
||||||
"dep:async-recursion",
|
"dep:async-recursion",
|
||||||
|
|||||||
@@ -89,20 +89,25 @@ impl Idevice {
|
|||||||
|
|
||||||
/// Sends raw bytes to the socket
|
/// Sends raw bytes to the socket
|
||||||
async fn send_raw(&mut self, message: &[u8]) -> Result<(), IdeviceError> {
|
async fn send_raw(&mut self, message: &[u8]) -> Result<(), IdeviceError> {
|
||||||
|
self.send_raw_with_progress(message, |_| async {}).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn send_raw_with_progress<Fut>(
|
||||||
|
&mut self,
|
||||||
|
message: &[u8],
|
||||||
|
callback: impl Fn((usize, usize)) -> Fut,
|
||||||
|
) -> Result<(), IdeviceError>
|
||||||
|
where
|
||||||
|
Fut: std::future::Future<Output = ()>,
|
||||||
|
{
|
||||||
if let Some(socket) = &mut self.socket {
|
if let Some(socket) = &mut self.socket {
|
||||||
let message_parts = message.chunks(1024 * 64);
|
let message_parts = message.chunks(1024 * 64);
|
||||||
let part_len = message_parts.len();
|
let part_len = message_parts.len();
|
||||||
|
|
||||||
let mut err = 5;
|
|
||||||
for (i, part) in message_parts.enumerate() {
|
for (i, part) in message_parts.enumerate() {
|
||||||
debug!("Writing {i}/{part_len}");
|
debug!("Writing {i}/{part_len}");
|
||||||
while let Err(e) = socket.write_all(part).await {
|
socket.write_all(part).await?;
|
||||||
err -= 1;
|
callback((i, part_len)).await;
|
||||||
if err == 0 {
|
|
||||||
return Err(e.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = 5;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -80,6 +80,20 @@ impl ImageMounter {
|
|||||||
image: &[u8],
|
image: &[u8],
|
||||||
signature: Vec<u8>,
|
signature: Vec<u8>,
|
||||||
) -> Result<(), IdeviceError> {
|
) -> Result<(), IdeviceError> {
|
||||||
|
self.upload_image_with_progress(image_type, image, signature, |_| async {})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn upload_image_with_progress<Fut>(
|
||||||
|
&mut self,
|
||||||
|
image_type: impl Into<String>,
|
||||||
|
image: &[u8],
|
||||||
|
signature: Vec<u8>,
|
||||||
|
callback: impl Fn((usize, usize)) -> Fut,
|
||||||
|
) -> Result<(), IdeviceError>
|
||||||
|
where
|
||||||
|
Fut: std::future::Future<Output = ()>,
|
||||||
|
{
|
||||||
let image_type = image_type.into();
|
let image_type = image_type.into();
|
||||||
let image_size = match u64::try_from(image.len()) {
|
let image_size = match u64::try_from(image.len()) {
|
||||||
Ok(i) => i,
|
Ok(i) => i,
|
||||||
@@ -110,8 +124,7 @@ impl ImageMounter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug!("Sending image bytes");
|
debug!("Sending image bytes");
|
||||||
self.idevice.send_raw(image).await?;
|
self.idevice.send_raw_with_progress(image, callback).await?;
|
||||||
debug!("Image bytes written");
|
|
||||||
|
|
||||||
let res = self.idevice.read_plist().await?;
|
let res = self.idevice.read_plist().await?;
|
||||||
match res.get("Status") {
|
match res.get("Status") {
|
||||||
|
|||||||
Reference in New Issue
Block a user