feat: show update download telemetry

Calculate download throughput and remaining time from verified installer bytes and display downloaded size, total size, speed, and ETA beneath the progress track while retaining the last values after cancellation.
This commit is contained in:
Sucukdeluxe
2026-08-21 00:28:48 +02:00
parent e7d30edab5
commit 4d3a4f1a8a
7 changed files with 67 additions and 7 deletions
+8 -1
View File
@@ -241,6 +241,7 @@ async function prepareUpdate(onProgress, options = {}) {
activeAbort = new AbortController();
const signal = activeAbort.signal;
const fetchImpl = options.fetchImpl || fetch;
const now = typeof options.now === 'function' ? options.now : Date.now;
let stagedInstallerPath = '';
try {
@@ -284,6 +285,7 @@ async function prepareUpdate(onProgress, options = {}) {
const totalBytes = manifest.size;
let downloadedBytes = 0;
let lastReportedPercent = -1;
const downloadStartedAt = now();
const chunks = [];
const DOWNLOAD_STALL_MS = 45000;
@@ -312,12 +314,17 @@ async function prepareUpdate(onProgress, options = {}) {
downloadedBytes += value.length;
const percent = Math.max(0, Math.min(100, Math.floor((downloadedBytes / totalBytes) * 100)));
if (onProgress && percent !== lastReportedPercent) {
const elapsedMs = Math.max(1, now() - downloadStartedAt);
const bytesPerSecond = Math.round((downloadedBytes * 1000) / elapsedMs);
const etaSeconds = bytesPerSecond > 0 ? Math.ceil(Math.max(0, totalBytes - downloadedBytes) / bytesPerSecond) : null;
lastReportedPercent = percent;
onProgress({
stage: 'downloading',
percent,
bytesDownloaded: downloadedBytes,
bytesTotal: totalBytes
bytesTotal: totalBytes,
bytesPerSecond,
etaSeconds
});
await new Promise(resolve => setImmediate(resolve));
}