From 08e9ab399aa1bd0b7760999b6e263f8a1ba33eff Mon Sep 17 00:00:00 2001 From: KernelDeimos <7225168+KernelDeimos@users.noreply.github.com> Date: Thu, 30 Oct 2025 19:11:09 -0400 Subject: [PATCH] clean: use window.sleep in place of setTimeout Also another change to make duration handling consistent for the two blocks of code that have the "ensure 2 seconds" logic. --- src/gui/src/initgui.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/gui/src/initgui.js b/src/gui/src/initgui.js index 343d70da7..5c6b1a92a 100644 --- a/src/gui/src/initgui.js +++ b/src/gui/src/initgui.js @@ -990,21 +990,15 @@ window.initgui = async function(options){ contentType: "application/json", data: JSON.stringify(requestData), success: async function (data){ - // We want to show the spinner for at least 2 seconds so it - // doesn't look like a flicker. - let timeRemaining = 2000; - - // Subtract time taken for turnstile to succeed - timeRemaining -= Date.now() - window.turnstile_success_ts; - - if (timeRemaining > 0) { + /*eslint-disable*/ + const turnstile_duration = Date.now() - window.turnstile_success_ts; + if (turnstile_duration < 2000) { // Sleep until 2 seconds have passed - await new Promise(rslv => setTimeout(rslv, timeRemaining)); + await window.sleep(2000 - turnstile_duration); } - /*eslint-disable*/ const $captchaModal = $('.captcha-modal'); - if ( $captchaModal.length > 0 ) await new Promise(resolve => { + if ( $captchaModal.length > 0 ) await new Promise(async resolve => { // The callback operand for fadeOut could be called // more than once if there are multiple `.captcha-modal` // elements, but only the first call to `resolve()` will @@ -1015,16 +1009,17 @@ window.initgui = async function(options){ }); // Just in case anything fails, also resolve after 500ms - setTimeout(() => resolve(), 500); + await window.sleep(500); + resolve(); }); // if this is a popup, hide the spinner, make sure it was visible for at least 2 seconds - if(window.embedded_in_popup) await new Promise(resolve => { + if(window.embedded_in_popup) await new Promise(async resolve => { let spinner_duration = (Date.now() - spinner_init_ts); - setTimeout(() => { - puter.ui.hideSpinner(); - resolve(); - }, spinner_duration > 2000 ? 10 : 2000 - spinner_duration); + if (spinner_duration < 2000) { + await window.sleep(2000 - spinner_duration); + } + puter.ui.hideSpinner(); }); /*eslint-enable*/