Skip to content

Commit

Permalink
feat: Emit ImexProgress(1) after receiving backup size
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iequidoo committed Dec 18, 2024
1 parent a9e38aa commit 3af4ea1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/imex/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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")?;
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 3af4ea1

Please sign in to comment.