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:
+7
-3
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user