Skip to content

Commit dd8bc4a

Browse files
committed
fix(upload) reduce amount of emitted tauri events
1 parent 8d60454 commit dd8bc4a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

plugins/upload/src/lib.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,27 @@ async fn download<R: Runtime>(
7070
let mut file = BufWriter::new(File::create(file_path).await?);
7171
let mut stream = response.bytes_stream();
7272

73+
let mut i = 0;
74+
let mut temp_progress = 0;
75+
7376
while let Some(chunk) = stream.try_next().await? {
77+
i = i + 1;
7478
file.write_all(&chunk).await?;
75-
let _ = window.emit(
76-
"download://progress",
77-
ProgressPayload {
78-
id,
79-
progress: chunk.len() as u64,
80-
total,
81-
},
82-
);
79+
temp_progress = temp_progress + chunk.len();
80+
if i >= 10 {
81+
window
82+
.emit(
83+
"download://progress",
84+
ProgressPayload {
85+
id,
86+
progress: temp_progress as u64,
87+
total,
88+
},
89+
)
90+
.unwrap(); // TODO: remove the unwrap again.
91+
i = 0;
92+
temp_progress = 0;
93+
}
8394
}
8495
file.flush().await?;
8596

0 commit comments

Comments
 (0)