mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-03 07:48:46 +08:00
feat: puter.js's showSpinner() will keep the spinner active for at least 1200ms
This commit is contained in:
parent
966d98e469
commit
fc5aca1f72
@ -1282,6 +1282,9 @@ class UI extends EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#showTime = null;
|
||||||
|
#hideTimeout = null;
|
||||||
|
|
||||||
showSpinner() {
|
showSpinner() {
|
||||||
if (this.#overlayActive) return;
|
if (this.#overlayActive) return;
|
||||||
|
|
||||||
@ -1301,7 +1304,6 @@ class UI extends EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.puter-loading-text {
|
.puter-loading-text {
|
||||||
color: white;
|
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
@ -1332,7 +1334,7 @@ class UI extends EventListener {
|
|||||||
left: '0',
|
left: '0',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
backgroundColor: 'rgba(255, 255, 255, 0.9)',
|
||||||
zIndex: '2147483647',
|
zIndex: '2147483647',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
@ -1356,11 +1358,12 @@ class UI extends EventListener {
|
|||||||
document.body.appendChild(overlay);
|
document.body.appendChild(overlay);
|
||||||
|
|
||||||
this.#overlayActive = true;
|
this.#overlayActive = true;
|
||||||
|
this.#showTime = Date.now(); // Add show time tracking
|
||||||
this.#overlayTimer = setTimeout(() => {
|
this.#overlayTimer = setTimeout(() => {
|
||||||
this.#overlayTimer = null;
|
this.#overlayTimer = null;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
hideSpinner() {
|
hideSpinner() {
|
||||||
if (!this.#overlayActive) return;
|
if (!this.#overlayActive) return;
|
||||||
|
|
||||||
@ -1369,12 +1372,34 @@ class UI extends EventListener {
|
|||||||
this.#overlayTimer = null;
|
this.#overlayTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate how long the spinner has been shown
|
||||||
|
const elapsedTime = Date.now() - this.#showTime;
|
||||||
|
const remainingTime = Math.max(0, 1200 - elapsedTime);
|
||||||
|
|
||||||
|
// If less than 1 second has passed, delay the hide
|
||||||
|
if (remainingTime > 0) {
|
||||||
|
if (this.#hideTimeout) {
|
||||||
|
clearTimeout(this.#hideTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.#hideTimeout = setTimeout(() => {
|
||||||
|
this.#removeSpinner();
|
||||||
|
}, remainingTime);
|
||||||
|
} else {
|
||||||
|
this.#removeSpinner();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add private method to handle spinner removal
|
||||||
|
#removeSpinner() {
|
||||||
const overlay = document.querySelector('.puter-loading-overlay');
|
const overlay = document.querySelector('.puter-loading-overlay');
|
||||||
if (overlay) {
|
if (overlay) {
|
||||||
overlay.parentNode?.removeChild(overlay);
|
overlay.parentNode?.removeChild(overlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#overlayActive = false;
|
this.#overlayActive = false;
|
||||||
|
this.#showTime = null;
|
||||||
|
this.#hideTimeout = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
isWorkingActive() {
|
isWorkingActive() {
|
||||||
|
Loading…
Reference in New Issue
Block a user