aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/lib
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2026-01-14 13:52:15 +0800
committerGitHub <noreply@github.com>2026-01-14 13:52:15 +0800
commite6295ae4e80e4eb31163a86815d0257ce2091d3b (patch)
treef834c2701092dd86258a9373053296e8d4e67984 /ui/src/lib
parentd559a4624efb3cf5688a3df03a77f90999c42233 (diff)
downloadDropOut-e6295ae4e80e4eb31163a86815d0257ce2091d3b.tar.gz
DropOut-e6295ae4e80e4eb31163a86815d0257ce2091d3b.zip
Update ui/src/lib/DownloadMonitor.svelte
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Diffstat (limited to 'ui/src/lib')
-rw-r--r--ui/src/lib/DownloadMonitor.svelte19
1 files changed, 13 insertions, 6 deletions
diff --git a/ui/src/lib/DownloadMonitor.svelte b/ui/src/lib/DownloadMonitor.svelte
index 5dc8269..79adff5 100644
--- a/ui/src/lib/DownloadMonitor.svelte
+++ b/ui/src/lib/DownloadMonitor.svelte
@@ -83,12 +83,19 @@
const timeDiff = (now - lastUpdateTime) / 1000; // seconds
if (timeDiff >= 0.5) { // Update speed every 0.5 seconds
- const bytesDiff = totalDownloadedBytes - lastTotalBytes;
- const instantSpeed = bytesDiff / timeDiff;
- // Smooth the speed with exponential moving average
- downloadSpeed = downloadSpeed === 0 ? instantSpeed : downloadSpeed * 0.7 + instantSpeed * 0.3;
- lastUpdateTime = now;
- lastTotalBytes = totalDownloadedBytes;
+ // On the first update, initialize lastTotalBytes to avoid counting
+ // bytes downloaded before the timer window started.
+ if (lastTotalBytes === 0 && totalDownloadedBytes > 0) {
+ lastTotalBytes = totalDownloadedBytes;
+ lastUpdateTime = now;
+ } else {
+ const bytesDiff = totalDownloadedBytes - lastTotalBytes;
+ const instantSpeed = bytesDiff / timeDiff;
+ // Smooth the speed with exponential moving average
+ downloadSpeed = downloadSpeed === 0 ? instantSpeed : downloadSpeed * 0.7 + instantSpeed * 0.3;
+ lastUpdateTime = now;
+ lastTotalBytes = totalDownloadedBytes;
+ }
}
// Estimate remaining time based on files remaining