Skip to content

Commit 3af4ea1

Browse files
committed
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.
1 parent a9e38aa commit 3af4ea1

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/imex/transfer.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ impl BackupProvider {
178178
}
179179

180180
info!(context, "Received valid backup authentication token.");
181+
// Emit a nonzero progress so that UIs can display smth like "Transferring...".
181182
context.emit_event(EventType::ImexProgress(1));
182183

183184
let blobdir = BlobDirContents::new(&context).await?;
@@ -309,6 +310,10 @@ pub async fn get_backup2(
309310
let mut file_size_buf = [0u8; 8];
310311
recv_stream.read_exact(&mut file_size_buf).await?;
311312
let file_size = u64::from_be_bytes(file_size_buf);
313+
info!(context, "Received backup file size.");
314+
// Emit a nonzero progress so that UIs can display smth like "Transferring...".
315+
context.emit_event(EventType::ImexProgress(1));
316+
312317
import_backup_stream(context, recv_stream, file_size, passphrase)
313318
.await
314319
.context("Failed to import backup from QUIC stream")?;
@@ -434,12 +439,14 @@ mod tests {
434439
assert!(msg.save_file(&ctx1, &path).await.is_err());
435440

436441
// Check that both received the ImexProgress events.
437-
ctx0.evtracker
438-
.get_matching(|ev| matches!(ev, EventType::ImexProgress(1000)))
439-
.await;
440-
ctx1.evtracker
441-
.get_matching(|ev| matches!(ev, EventType::ImexProgress(1000)))
442-
.await;
442+
for ctx in [&ctx0, &ctx1] {
443+
ctx.evtracker
444+
.get_matching(|ev| matches!(ev, EventType::ImexProgress(1)))
445+
.await;
446+
ctx.evtracker
447+
.get_matching(|ev| matches!(ev, EventType::ImexProgress(1000)))
448+
.await;
449+
}
443450
}
444451

445452
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]

0 commit comments

Comments
 (0)