Compare commits

...

3 Commits

Author SHA1 Message Date
FabianLars a71a0192b8 check progress size in last event instead 2023-10-31 13:29:38 +01:00
FabianLars e7d9efee37 emitlast event 2023-10-31 13:28:31 +01:00
FabianLars dd8bc4ab39 fix(upload) reduce amount of emitted tauri events 2023-10-31 13:23:16 +01:00
+31 -8
View File
@@ -70,16 +70,39 @@ 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;
}
}
if temp_progress != 0 {
window
.emit(
"download://progress",
ProgressPayload {
id,
progress: temp_progress as u64,
total,
},
)
.unwrap(); // TODO: remove the unwrap again.
}
file.flush().await?;