use requestAnimationFrame for cleaner progress bar updates

This commit is contained in:
xenofem 2024-03-07 14:34:10 -05:00
parent 41856c7ff9
commit 7a9dcfb6ec

View file

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