Skip to content

Commit fc5aca1

Browse files
committed
feat: puter.js's showSpinner() will keep the spinner active for at least 1200ms
1 parent 966d98e commit fc5aca1

File tree

1 file changed

+28
-3
lines changed
  • src/puter-js/src/modules

1 file changed

+28
-3
lines changed

src/puter-js/src/modules/UI.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,9 @@ class UI extends EventListener {
12821282
}
12831283
}
12841284

1285+
#showTime = null;
1286+
#hideTimeout = null;
1287+
12851288
showSpinner() {
12861289
if (this.#overlayActive) return;
12871290

@@ -1301,7 +1304,6 @@ class UI extends EventListener {
13011304
}
13021305
13031306
.puter-loading-text {
1304-
color: white;
13051307
font-family: Arial, sans-serif;
13061308
font-size: 16px;
13071309
margin-top: 10px;
@@ -1332,7 +1334,7 @@ class UI extends EventListener {
13321334
left: '0',
13331335
width: '100%',
13341336
height: '100%',
1335-
backgroundColor: 'rgba(0, 0, 0, 0.5)',
1337+
backgroundColor: 'rgba(255, 255, 255, 0.9)',
13361338
zIndex: '2147483647',
13371339
display: 'flex',
13381340
justifyContent: 'center',
@@ -1356,11 +1358,12 @@ class UI extends EventListener {
13561358
document.body.appendChild(overlay);
13571359

13581360
this.#overlayActive = true;
1361+
this.#showTime = Date.now(); // Add show time tracking
13591362
this.#overlayTimer = setTimeout(() => {
13601363
this.#overlayTimer = null;
13611364
}, 1000);
13621365
}
1363-
1366+
13641367
hideSpinner() {
13651368
if (!this.#overlayActive) return;
13661369

@@ -1369,12 +1372,34 @@ class UI extends EventListener {
13691372
this.#overlayTimer = null;
13701373
}
13711374

1375+
// Calculate how long the spinner has been shown
1376+
const elapsedTime = Date.now() - this.#showTime;
1377+
const remainingTime = Math.max(0, 1200 - elapsedTime);
1378+
1379+
// If less than 1 second has passed, delay the hide
1380+
if (remainingTime > 0) {
1381+
if (this.#hideTimeout) {
1382+
clearTimeout(this.#hideTimeout);
1383+
}
1384+
1385+
this.#hideTimeout = setTimeout(() => {
1386+
this.#removeSpinner();
1387+
}, remainingTime);
1388+
} else {
1389+
this.#removeSpinner();
1390+
}
1391+
}
1392+
1393+
// Add private method to handle spinner removal
1394+
#removeSpinner() {
13721395
const overlay = document.querySelector('.puter-loading-overlay');
13731396
if (overlay) {
13741397
overlay.parentNode?.removeChild(overlay);
13751398
}
13761399

13771400
this.#overlayActive = false;
1401+
this.#showTime = null;
1402+
this.#hideTimeout = null;
13781403
}
13791404

13801405
isWorkingActive() {

0 commit comments

Comments
 (0)