Skip to content

Commit

Permalink
fix(upload) reduce amount of emitted tauri events
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianLars committed Oct 31, 2023
1 parent 8d60454 commit dd8bc4a
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions plugins/upload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,27 @@ async fn download<R: Runtime>(
let mut file = BufWriter::new(File::create(file_path).await?);
let mut stream = response.bytes_stream();

let mut i = 0;
let mut temp_progress = 0;

while let Some(chunk) = stream.try_next().await? {
i = i + 1;
file.write_all(&chunk).await?;
let _ = window.emit(
"download://progress",
ProgressPayload {
id,
progress: chunk.len() as u64,
total,
},
);
temp_progress = temp_progress + chunk.len();
if i >= 10 {
window
.emit(
"download://progress",
ProgressPayload {
id,
progress: temp_progress as u64,
total,
},
)
.unwrap(); // TODO: remove the unwrap again.
i = 0;
temp_progress = 0;
}
}
file.flush().await?;

Expand Down

0 comments on commit dd8bc4a

Please sign in to comment.