Add easing back to progress.js

This commit is contained in:
Ryan Huffman 2016-07-28 16:55:45 -07:00
parent 873e7b63df
commit a786224297

View file

@ -100,9 +100,11 @@
var maxSeen = 0; var maxSeen = 0;
var bestRawProgress = 0; var bestRawProgress = 0;
var wasActive = false; var wasActive = false;
var cooldown = 1000;
function onDownloadInfoChanged(info) { function onDownloadInfoChanged(info) {
var i; var i;
print("PROGRESS: DOwnload info changed ", info.downloading.length, info.pending, maxSeen);
// Update raw progress value // Update raw progress value
if (info.downloading.length + info.pending === 0) { if (info.downloading.length + info.pending === 0) {
wasActive = false; wasActive = false;
@ -112,26 +114,33 @@
var count = info.downloading.length + info.pending; var count = info.downloading.length + info.pending;
if (!wasActive) { if (!wasActive) {
wasActive = true; wasActive = true;
if (count > maxSeen) { maxSeen = count;
maxSeen = count;
}
bestRawProgress = 0; bestRawProgress = 0;
rawProgress = 0;
cooldown = 2000;
displayProgress = 0;
} }
//for (i = 0; i < info.downloading.length; i += 1) { if (count > maxSeen) {
//rawProgress += info.downloading[i]; maxSeen = count;
//} }
//rawProgress = rawProgress / (info.downloading.length + info.pending); if (cooldown < 0) {
rawProgress = ((maxSeen - count) / maxSeen) * 100; print("PROGRESS: OUT OF COOLDOWN");
//rawProgress += 1; //for (i = 0; i < info.downloading.length; i += 1) {
//if (rawProgress > 90) { //rawProgress += info.downloading[i];
//rawProgress = 20 //}
//} //rawProgress = rawProgress / (info.downloading.length + info.pending);
rawProgress = ((maxSeen - count) / maxSeen) * 100;
//rawProgress += 1;
//if (rawProgress > 90) {
//rawProgress = 20
//}
if (rawProgress > bestRawProgress) { if (rawProgress > bestRawProgress) {
bestRawProgress = rawProgress; bestRawProgress = rawProgress;
}
} }
} }
//print(rawProgress, bestRawProgress, maxSeen); print("PROGRESS:", rawProgress, bestRawProgress, maxSeen);
} }
function createOverlays() { function createOverlays() {
@ -193,6 +202,7 @@
var b = 0; var b = 0;
function update() { function update() {
cooldown -= 16;
/* /*
maxSeen = 100; maxSeen = 100;
b++; b++;
@ -216,6 +226,7 @@
//createOverlays(); //createOverlays();
//} //}
/*
// Calculate progress value to display // Calculate progress value to display
if (rawProgress === 0 && displayProgress <= DISPLAY_PROGRESS_MINOR_MAXIMUM) { if (rawProgress === 0 && displayProgress <= DISPLAY_PROGRESS_MINOR_MAXIMUM) {
displayProgress = Math.min(displayProgress + DISPLAY_PROGRESS_MINOR_INCREMENT, DISPLAY_PROGRESS_MINOR_MAXIMUM); displayProgress = Math.min(displayProgress + DISPLAY_PROGRESS_MINOR_INCREMENT, DISPLAY_PROGRESS_MINOR_MAXIMUM);
@ -224,7 +235,18 @@
} else if (rawProgress > displayProgress) { } else if (rawProgress > displayProgress) {
displayProgress = Math.min(rawProgress, displayProgress + DISPLAY_PROGRESS_MAJOR_INCREMENT); displayProgress = Math.min(rawProgress, displayProgress + DISPLAY_PROGRESS_MAJOR_INCREMENT);
} // else (rawProgress === displayProgress); do nothing. } // else (rawProgress === displayProgress); do nothing.
displayProgress = bestRawProgress; //displayProgress = bestRawProgress;
//*/
if (displayProgress < rawProgress) {
var diff = rawProgress - displayProgress;
if (diff < 0.1) {
displayProgress = rawProgress;
} else {
displayProgress += diff * 0.2;
}
}
print('PROGRESS:', displayProgress);
// Update state // Update state
if (!visible) { // Not visible because no recent downloads if (!visible) { // Not visible because no recent downloads
@ -235,7 +257,7 @@
} }
} else if (alphaDelta !== 0.0) { // Fading in or out } else if (alphaDelta !== 0.0) { // Fading in or out
if (alphaDelta > 0) { if (alphaDelta > 0) {
if (displayProgress === 100) { // Was downloading but now have finished so fade out if (rawProgress === 100) { // Was downloading but now have finished so fade out
alphaDelta = ALPHA_DELTA_OUT; alphaDelta = ALPHA_DELTA_OUT;
} }
} else { } else {
@ -245,7 +267,7 @@
} }
} else { // Fully visible because downloading or recently so } else { // Fully visible because downloading or recently so
if (fadeWaitTimer === null) { if (fadeWaitTimer === null) {
if (displayProgress === 100) { // Was downloading but have finished so fade out soon if (rawProgress === 100) { // Was downloading but have finished so fade out soon
fadeWaitTimer = Script.setTimeout(function() { fadeWaitTimer = Script.setTimeout(function() {
alphaDelta = ALPHA_DELTA_OUT; alphaDelta = ALPHA_DELTA_OUT;
fadeTimer = Script.setInterval(fade, FADE_INTERVAL); fadeTimer = Script.setInterval(fade, FADE_INTERVAL);