diff --git a/src/lib.rs b/src/lib.rs index 20581f4..dbe5206 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,15 +102,23 @@ pub async fn console_print(buf: &[u8]) { } #[allow(clippy::explicit_write)] -pub async fn send_image(write_sink: &mut Arc>, buf: &[u8]) -> anyhow::Result<()> { +pub async fn send_image( + write_sink: &mut Arc>, + buf: &[u8], + quit: &Arc>, +) -> anyhow::Result<()> { let mut last_percent_done: usize = 0; let mut bytes_sent = 0; for chunk in buf.chunks(2048) { let percent_done = 100 * bytes_sent / buf.len(); + if *quit.lock().await { + return Ok(()); + } + if percent_done != last_percent_done { - let s = format!(" Sending image: {}%\r", percent_done); + let s = format!("Sending image: {}%\r", percent_done); print!("{}", s.green()); stdout().flush()?; } diff --git a/src/main.rs b/src/main.rs index 6a3c870..c224474 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,7 +160,7 @@ async fn main() -> anyhow::Result<()> { Ok(Sk8brdMsgs::MsgPowerOff) => (), Ok(Sk8brdMsgs::MsgFastbootPresent) => { if !msgbuf.is_empty() && msgbuf[0] != 0 { - send_image(&mut chan, &fastboot_image).await? + send_image(&mut chan, &fastboot_image, &quit).await? } } Ok(Sk8brdMsgs::MsgFastbootDownload) => (), @@ -197,6 +197,6 @@ async fn main() -> anyhow::Result<()> { ) .context("Couldn't disconnect cleanly")?; - println!("Goodbye"); + println!("\nGoodbye"); Ok(()) }