fix: render update download progress incrementally

Use the verified manifest size for percentage calculations, suppress duplicate percentage events, and yield between buffered download updates so Electron can paint intermediate progress before completion. Add a regression test that proves renderer-observable progress during an immediately buffered download.
This commit is contained in:
Sucukdeluxe
2026-08-20 14:01:07 +02:00
parent 7074e6662d
commit 990d4c4ffa
2 changed files with 72 additions and 3 deletions
+7 -3
View File
@@ -281,8 +281,9 @@ async function prepareUpdate(onProgress, options = {}) {
throw new Error(`Download fehlgeschlagen: HTTP ${res.status}`);
}
const totalBytes = check.assetSize || 0;
const totalBytes = manifest.size;
let downloadedBytes = 0;
let lastReportedPercent = -1;
const chunks = [];
const DOWNLOAD_STALL_MS = 45000;
@@ -309,13 +310,16 @@ async function prepareUpdate(onProgress, options = {}) {
if (done) break;
chunks.push(value);
downloadedBytes += value.length;
if (onProgress) {
const percent = Math.max(0, Math.min(100, Math.floor((downloadedBytes / totalBytes) * 100)));
if (onProgress && percent !== lastReportedPercent) {
lastReportedPercent = percent;
onProgress({
stage: 'downloading',
percent: totalBytes > 0 ? Math.round((downloadedBytes / totalBytes) * 100) : 0,
percent,
bytesDownloaded: downloadedBytes,
bytesTotal: totalBytes
});
await new Promise(resolve => setImmediate(resolve));
}
}