Upload progressbar.js
Browse files- progressbar.js +47 -33
progressbar.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
// code related to showing and updating progressbar shown as the image is being made
|
| 2 |
-
let
|
| 3 |
let timeWarning = 160;
|
| 4 |
let maxTimeWarning = 3600;
|
| 5 |
let firstTimeStart = 0;
|
| 6 |
let timeZone = 'Asia/Bangkok';
|
| 7 |
-
let
|
|
|
|
| 8 |
//const options = { timeZone };
|
| 9 |
const options = { timeZone, hour: '2-digit', minute: '2-digit' };
|
| 10 |
const formatter = new Intl.DateTimeFormat([], options);
|
|
@@ -54,28 +55,30 @@ function formatTime(secs) {
|
|
| 54 |
}
|
| 55 |
}
|
| 56 |
|
| 57 |
-
function setTitle(progress,
|
| 58 |
// var title = 'Unity';
|
| 59 |
-
var title =
|
| 60 |
-
if (
|
| 61 |
-
lastCompleteTime = getCurrentDateTimeGMTPlus7();
|
| 62 |
-
title = lastCompleteTime;
|
| 63 |
-
}
|
| 64 |
-
else if (opts.show_progress_in_title && progress) {
|
| 65 |
title = '[' + progress.trim() + '] ' + title;
|
| 66 |
}
|
| 67 |
-
else if (
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
else{
|
| 73 |
-
var durationSinceLastSuccess = curTime - lastTimeSuccess;
|
| 74 |
-
if (durationSinceLastSuccess > maxTimeWarning){ // hoangpl no need update ui
|
| 75 |
-
title = 'exceed > ' + maxTimeWarning + 's';
|
| 76 |
}
|
| 77 |
-
else
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
}
|
| 80 |
}
|
| 81 |
}
|
|
@@ -84,6 +87,13 @@ function setTitle(progress, showCurDateTIme = false) {
|
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
function getCurrentDateTimeGMTPlus7() {
|
| 88 |
// Use the global formatter to format the current date and time
|
| 89 |
return formatter.format(new Date());
|
|
@@ -116,13 +126,13 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
|
| 116 |
|
| 117 |
var livePreview = null;
|
| 118 |
|
| 119 |
-
var removeProgressBar = function(
|
| 120 |
if (!divProgress) {
|
| 121 |
-
setTitle(""
|
| 122 |
return;
|
| 123 |
}
|
| 124 |
|
| 125 |
-
setTitle(""
|
| 126 |
parentProgressbar.removeChild(divProgress);
|
| 127 |
if (gallery && livePreview) gallery.removeChild(livePreview);
|
| 128 |
atEnd();
|
|
@@ -133,28 +143,32 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
|
| 133 |
var funProgress = function(id_task) {
|
| 134 |
request("./internal/progress", {id_task: id_task, live_preview: false}, function(res) {
|
| 135 |
if (res.completed) {
|
| 136 |
-
removeProgressBar(
|
| 137 |
return;
|
| 138 |
}
|
| 139 |
-
|
| 140 |
let progressText = "";
|
| 141 |
|
| 142 |
divInner.style.width = ((res.progress || 0) * 100.0) + '%';
|
| 143 |
divInner.style.background = res.progress ? "" : "transparent";
|
| 144 |
|
| 145 |
if (res.progress > 0) {
|
|
|
|
| 146 |
progressText = ((res.progress || 0) * 100.0).toFixed(0) + '%';
|
| 147 |
}
|
| 148 |
|
| 149 |
if (res.eta) {
|
|
|
|
| 150 |
progressText += " ETA: " + formatTime(res.eta);
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
| 152 |
if (firstTimeStart <= 0){
|
| 153 |
-
firstTimeStart =
|
| 154 |
}
|
| 155 |
}
|
| 156 |
-
|
| 157 |
-
setTitle(progressText);
|
| 158 |
|
| 159 |
if (res.textinfo && res.textinfo.indexOf("\n") == -1) {
|
| 160 |
progressText = res.textinfo + " " + progressText;
|
|
@@ -167,12 +181,12 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
|
| 167 |
if (res.active) wasEverActive = true;
|
| 168 |
|
| 169 |
if (!res.active && wasEverActive) {
|
| 170 |
-
removeProgressBar(
|
| 171 |
return;
|
| 172 |
}
|
| 173 |
|
| 174 |
if (elapsedFromStart > inactivityTimeout && !res.queued && !res.active) {
|
| 175 |
-
removeProgressBar(
|
| 176 |
return;
|
| 177 |
}
|
| 178 |
|
|
@@ -184,7 +198,7 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
|
| 184 |
funProgress(id_task, res.id_live_preview);
|
| 185 |
}, opts.live_preview_refresh_period || 500);
|
| 186 |
}, function() {
|
| 187 |
-
removeProgressBar(
|
| 188 |
});
|
| 189 |
};
|
| 190 |
|
|
@@ -215,7 +229,7 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
|
| 215 |
funLivePreview(id_task, res.id_live_preview);
|
| 216 |
}, opts.live_preview_refresh_period || 500);
|
| 217 |
}, function() {
|
| 218 |
-
removeProgressBar(
|
| 219 |
});
|
| 220 |
};
|
| 221 |
|
|
|
|
| 1 |
// code related to showing and updating progressbar shown as the image is being made
|
| 2 |
+
let lastTimeGenerate = 0; //epoch time in second
|
| 3 |
let timeWarning = 160;
|
| 4 |
let maxTimeWarning = 3600;
|
| 5 |
let firstTimeStart = 0;
|
| 6 |
let timeZone = 'Asia/Bangkok';
|
| 7 |
+
let lastGenerateDateTime = 0;
|
| 8 |
+
|
| 9 |
//const options = { timeZone };
|
| 10 |
const options = { timeZone, hour: '2-digit', minute: '2-digit' };
|
| 11 |
const formatter = new Intl.DateTimeFormat([], options);
|
|
|
|
| 55 |
}
|
| 56 |
}
|
| 57 |
|
| 58 |
+
function setTitle(progress, isGenerating = false) {
|
| 59 |
// var title = 'Unity';
|
| 60 |
+
var title = lastTimeGenerate;
|
| 61 |
+
if (opts.show_progress_in_title && progress) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
title = '[' + progress.trim() + '] ' + title;
|
| 63 |
}
|
| 64 |
+
else if (!isGenerating){
|
| 65 |
+
if (lastTimeGenerate > 0){
|
| 66 |
+
var curTime = getCurTimeInSeconds();
|
| 67 |
+
if (curTime - firstTimeStart > 14400){
|
| 68 |
+
title = 'exceed 4 hours ';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
}
|
| 70 |
+
else{
|
| 71 |
+
var durationSinceLastGenerate = curTime - lastTimeGenerate;
|
| 72 |
+
if (durationSinceLastGenerate > maxTimeWarning){ // hoangpl no need update ui
|
| 73 |
+
title = 'exceed > ' + maxTimeWarning + 's';
|
| 74 |
+
}
|
| 75 |
+
else if (durationSinceLastGenerate > timeWarning){
|
| 76 |
+
title = 'warning ' + durationSinceLastGenerate + 's';
|
| 77 |
+
}
|
| 78 |
+
else{
|
| 79 |
+
//display last time generating
|
| 80 |
+
title = getFormatDateTime(lastGenerateDateTime);
|
| 81 |
+
}
|
| 82 |
}
|
| 83 |
}
|
| 84 |
}
|
|
|
|
| 87 |
}
|
| 88 |
}
|
| 89 |
|
| 90 |
+
function getFormatDateTime(currentDate){
|
| 91 |
+
var hours = currentDate.getHours();
|
| 92 |
+
var minutes = currentDate.getMinutes();
|
| 93 |
+
// Format the hours and minutes as a string
|
| 94 |
+
return `${hours}:${minutes}`;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
function getCurrentDateTimeGMTPlus7() {
|
| 98 |
// Use the global formatter to format the current date and time
|
| 99 |
return formatter.format(new Date());
|
|
|
|
| 126 |
|
| 127 |
var livePreview = null;
|
| 128 |
|
| 129 |
+
var removeProgressBar = function() {
|
| 130 |
if (!divProgress) {
|
| 131 |
+
setTitle(""); // hoangpl continue update title
|
| 132 |
return;
|
| 133 |
}
|
| 134 |
|
| 135 |
+
setTitle("");
|
| 136 |
parentProgressbar.removeChild(divProgress);
|
| 137 |
if (gallery && livePreview) gallery.removeChild(livePreview);
|
| 138 |
atEnd();
|
|
|
|
| 143 |
var funProgress = function(id_task) {
|
| 144 |
request("./internal/progress", {id_task: id_task, live_preview: false}, function(res) {
|
| 145 |
if (res.completed) {
|
| 146 |
+
removeProgressBar();
|
| 147 |
return;
|
| 148 |
}
|
| 149 |
+
let isGenerating = false;
|
| 150 |
let progressText = "";
|
| 151 |
|
| 152 |
divInner.style.width = ((res.progress || 0) * 100.0) + '%';
|
| 153 |
divInner.style.background = res.progress ? "" : "transparent";
|
| 154 |
|
| 155 |
if (res.progress > 0) {
|
| 156 |
+
isGenerating = true;
|
| 157 |
progressText = ((res.progress || 0) * 100.0).toFixed(0) + '%';
|
| 158 |
}
|
| 159 |
|
| 160 |
if (res.eta) {
|
| 161 |
+
isGenerating = true;
|
| 162 |
progressText += " ETA: " + formatTime(res.eta);
|
| 163 |
+
}
|
| 164 |
+
if (isGenerating){
|
| 165 |
+
lastTimeGenerate = getCurTimeInSeconds(); // hoangpl
|
| 166 |
+
lastGenerateDateTime = Date.now();
|
| 167 |
if (firstTimeStart <= 0){
|
| 168 |
+
firstTimeStart = lastTimeGenerate;
|
| 169 |
}
|
| 170 |
}
|
| 171 |
+
setTitle(progressText, isGenerating);
|
|
|
|
| 172 |
|
| 173 |
if (res.textinfo && res.textinfo.indexOf("\n") == -1) {
|
| 174 |
progressText = res.textinfo + " " + progressText;
|
|
|
|
| 181 |
if (res.active) wasEverActive = true;
|
| 182 |
|
| 183 |
if (!res.active && wasEverActive) {
|
| 184 |
+
removeProgressBar();
|
| 185 |
return;
|
| 186 |
}
|
| 187 |
|
| 188 |
if (elapsedFromStart > inactivityTimeout && !res.queued && !res.active) {
|
| 189 |
+
removeProgressBar();
|
| 190 |
return;
|
| 191 |
}
|
| 192 |
|
|
|
|
| 198 |
funProgress(id_task, res.id_live_preview);
|
| 199 |
}, opts.live_preview_refresh_period || 500);
|
| 200 |
}, function() {
|
| 201 |
+
removeProgressBar();
|
| 202 |
});
|
| 203 |
};
|
| 204 |
|
|
|
|
| 229 |
funLivePreview(id_task, res.id_live_preview);
|
| 230 |
}, opts.live_preview_refresh_period || 500);
|
| 231 |
}, function() {
|
| 232 |
+
removeProgressBar();
|
| 233 |
});
|
| 234 |
};
|
| 235 |
|