Upload progressbar.js
Browse files- progressbar.js +20 -60
progressbar.js
CHANGED
@@ -1,18 +1,10 @@
|
|
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 lastGenerateTimeStamp = 0; // timestamp
|
8 |
-
let cacheLastGenerateTimeStamp = 0;
|
9 |
-
let cacheLastStringHourMin = null; //string
|
10 |
|
11 |
|
12 |
-
//const options = { timeZone };
|
13 |
-
const options = { timeZone, hour: '2-digit', minute: '2-digit' };
|
14 |
-
const formatter = new Intl.DateTimeFormat([], options);
|
15 |
-
|
16 |
function rememberGallerySelection() {
|
17 |
|
18 |
}
|
@@ -58,37 +50,24 @@ function formatTime(secs) {
|
|
58 |
}
|
59 |
}
|
60 |
|
61 |
-
function setTitle(progress
|
62 |
-
|
63 |
-
|
64 |
if (opts.show_progress_in_title && progress) {
|
65 |
title = '[' + progress.trim() + '] ' + title;
|
66 |
}
|
67 |
-
else if (
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
-
else{
|
74 |
-
|
75 |
-
if (durationSinceLastGenerate > maxTimeWarning){ // hoangpl no need update ui
|
76 |
-
title = 'exceed > ' + maxTimeWarning + 's';
|
77 |
-
}
|
78 |
-
else if (durationSinceLastGenerate > timeWarning){
|
79 |
-
title = 'warning ' + durationSinceLastGenerate + 's';
|
80 |
-
}
|
81 |
-
else{
|
82 |
-
//display last time generating
|
83 |
-
if (lastGenerateTimeStamp == cacheLastGenerateTimeStamp && cacheLastStringHourMin != null){
|
84 |
-
|
85 |
-
}
|
86 |
-
else{
|
87 |
-
cacheLastStringHourMin = getFormatDateTime(lastGenerateTimeStamp);
|
88 |
-
cacheLastGenerateTimeStamp = lastGenerateTimeStamp;
|
89 |
-
}
|
90 |
-
title = cacheLastStringHourMin;
|
91 |
-
}
|
92 |
}
|
93 |
}
|
94 |
}
|
@@ -97,21 +76,6 @@ function setTitle(progress, isGenerating = false) {
|
|
97 |
}
|
98 |
}
|
99 |
|
100 |
-
function getFormatDateTime(timeStamp){
|
101 |
-
var currentDate = new Date(timeStamp);
|
102 |
-
var hours = currentDate.getHours();
|
103 |
-
var minutes = currentDate.getMinutes();
|
104 |
-
var formattedHours = hours.toString().padStart(2, '0');
|
105 |
-
var formattedMinutes = minutes.toString().padStart(2, '0');
|
106 |
-
// Format the hours and minutes as a string
|
107 |
-
return `${formattedHours}:${mormattedMinutes}`;
|
108 |
-
}
|
109 |
-
|
110 |
-
function getCurrentDateTimeGMTPlus7() {
|
111 |
-
// Use the global formatter to format the current date and time
|
112 |
-
return formatter.format(new Date());
|
113 |
-
}
|
114 |
-
|
115 |
function getCurTimeInSeconds(){
|
116 |
return Math.floor(Date.now() / 1000);
|
117 |
}
|
@@ -159,29 +123,25 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
|
159 |
removeProgressBar();
|
160 |
return;
|
161 |
}
|
162 |
-
|
163 |
let progressText = "";
|
164 |
|
165 |
divInner.style.width = ((res.progress || 0) * 100.0) + '%';
|
166 |
divInner.style.background = res.progress ? "" : "transparent";
|
167 |
|
168 |
if (res.progress > 0) {
|
169 |
-
isGenerating = true;
|
170 |
progressText = ((res.progress || 0) * 100.0).toFixed(0) + '%';
|
171 |
}
|
172 |
|
173 |
if (res.eta) {
|
174 |
-
isGenerating = true;
|
175 |
progressText += " ETA: " + formatTime(res.eta);
|
176 |
-
|
177 |
-
if (isGenerating){
|
178 |
-
lastTimeGenerate = getCurTimeInSeconds(); // hoangpl
|
179 |
-
lastGenerateTimeStamp = Date.now();
|
180 |
if (firstTimeStart <= 0){
|
181 |
-
firstTimeStart =
|
182 |
}
|
183 |
}
|
184 |
-
|
|
|
185 |
|
186 |
if (res.textinfo && res.textinfo.indexOf("\n") == -1) {
|
187 |
progressText = res.textinfo + " " + progressText;
|
|
|
1 |
// code related to showing and updating progressbar shown as the image is being made
|
2 |
+
let lastTimeSuccess = 0; //epoch time in second
|
3 |
let timeWarning = 160;
|
4 |
let maxTimeWarning = 3600;
|
5 |
let firstTimeStart = 0;
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
|
|
|
|
|
|
|
|
8 |
function rememberGallerySelection() {
|
9 |
|
10 |
}
|
|
|
50 |
}
|
51 |
}
|
52 |
|
53 |
+
function setTitle(progress) {
|
54 |
+
var title = 'Unity';
|
55 |
+
|
56 |
if (opts.show_progress_in_title && progress) {
|
57 |
title = '[' + progress.trim() + '] ' + title;
|
58 |
}
|
59 |
+
else if (lastTimeSuccess > 0){ // hoangpl display duration since last time success
|
60 |
+
var curTime = getCurTimeInSeconds();
|
61 |
+
if (curTime - firstTimeStart > 14400){
|
62 |
+
title = 'exceed 4 hours ';
|
63 |
+
}
|
64 |
+
else{
|
65 |
+
var durationSinceLastSuccess = curTime - lastTimeSuccess;
|
66 |
+
if (durationSinceLastSuccess > maxTimeWarning){ // hoangpl no need update ui
|
67 |
+
title = 'exceed > ' + maxTimeWarning + 's';
|
68 |
}
|
69 |
+
else if (durationSinceLastSuccess > timeWarning){
|
70 |
+
title = 'warning ' + durationSinceLastSuccess + 's';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
}
|
72 |
}
|
73 |
}
|
|
|
76 |
}
|
77 |
}
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
function getCurTimeInSeconds(){
|
80 |
return Math.floor(Date.now() / 1000);
|
81 |
}
|
|
|
123 |
removeProgressBar();
|
124 |
return;
|
125 |
}
|
126 |
+
|
127 |
let progressText = "";
|
128 |
|
129 |
divInner.style.width = ((res.progress || 0) * 100.0) + '%';
|
130 |
divInner.style.background = res.progress ? "" : "transparent";
|
131 |
|
132 |
if (res.progress > 0) {
|
|
|
133 |
progressText = ((res.progress || 0) * 100.0).toFixed(0) + '%';
|
134 |
}
|
135 |
|
136 |
if (res.eta) {
|
|
|
137 |
progressText += " ETA: " + formatTime(res.eta);
|
138 |
+
lastTimeSuccess = getCurTimeInSeconds(); // hoangpl
|
|
|
|
|
|
|
139 |
if (firstTimeStart <= 0){
|
140 |
+
firstTimeStart = lastTimeSuccess;
|
141 |
}
|
142 |
}
|
143 |
+
|
144 |
+
setTitle(progressText);
|
145 |
|
146 |
if (res.textinfo && res.textinfo.indexOf("\n") == -1) {
|
147 |
progressText = res.textinfo + " " + progressText;
|