use requestAnimationFrame for cleaner progress bar updates

main
xenofem 2024-03-07 14:34:10 -05:00
parent 41856c7ff9
commit 7a9dcfb6ec
1 changed files with 6 additions and 1 deletions

View File

@ -31,6 +31,7 @@ let progressSize;
let progressRate; let progressRate;
let progressEta; let progressEta;
let progressBar; let progressBar;
let animationID = null;
window.addEventListener('beforeunload', (event) => { window.addEventListener('beforeunload', (event) => {
if (socket && socket.readyState !== 3) { if (socket && socket.readyState !== 3) {
@ -291,7 +292,9 @@ function sendData() {
if (timestamps.length > SAMPLE_WINDOW) { timestamps.shift(); } if (timestamps.length > SAMPLE_WINDOW) { timestamps.shift(); }
} }
updateProgress(); if (animationID === null) {
animationID = requestAnimationFrame(updateProgress);
}
} else { } else {
fileIndex += 1; fileIndex += 1;
byteIndex = 0; byteIndex = 0;
@ -300,6 +303,8 @@ function sendData() {
} }
function updateProgress() { function updateProgress() {
animationID = null;
let percentage; let percentage;
if (totalBytes === 0) { if (totalBytes === 0) {
percentage = "0%"; percentage = "0%";