From 3af4ea1d0033bd61512ee0460e32343819ac2365 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Tue, 17 Dec 2024 17:49:09 -0300 Subject: [PATCH] feat: Emit ImexProgress(1) after receiving backup size UIs may want to display smth like "Transferring..." after "Establishing connection between devices..." on nonzero progress. Before, progress on the receiver side was starting with 2 after receiving enough data. --- src/imex/transfer.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/imex/transfer.rs b/src/imex/transfer.rs index 7298834a2b..297bed6af3 100644 --- a/src/imex/transfer.rs +++ b/src/imex/transfer.rs @@ -178,6 +178,7 @@ impl BackupProvider { } info!(context, "Received valid backup authentication token."); + // Emit a nonzero progress so that UIs can display smth like "Transferring...". context.emit_event(EventType::ImexProgress(1)); let blobdir = BlobDirContents::new(&context).await?; @@ -309,6 +310,10 @@ pub async fn get_backup2( let mut file_size_buf = [0u8; 8]; recv_stream.read_exact(&mut file_size_buf).await?; let file_size = u64::from_be_bytes(file_size_buf); + info!(context, "Received backup file size."); + // Emit a nonzero progress so that UIs can display smth like "Transferring...". + context.emit_event(EventType::ImexProgress(1)); + import_backup_stream(context, recv_stream, file_size, passphrase) .await .context("Failed to import backup from QUIC stream")?; @@ -434,12 +439,14 @@ mod tests { assert!(msg.save_file(&ctx1, &path).await.is_err()); // Check that both received the ImexProgress events. - ctx0.evtracker - .get_matching(|ev| matches!(ev, EventType::ImexProgress(1000))) - .await; - ctx1.evtracker - .get_matching(|ev| matches!(ev, EventType::ImexProgress(1000))) - .await; + for ctx in [&ctx0, &ctx1] { + ctx.evtracker + .get_matching(|ev| matches!(ev, EventType::ImexProgress(1))) + .await; + ctx.evtracker + .get_matching(|ev| matches!(ev, EventType::ImexProgress(1000))) + .await; + } } #[tokio::test(flavor = "multi_thread", worker_threads = 2)]