fix: simplify code for hiding form

web-rdp-cloud-fixes
Parkreiner 10 months ago
parent 1a0a8659cc
commit ef4c87e48e

@ -408,38 +408,15 @@ function hideFormForInitialSubmission() {
rootNode.style.setProperty(opacityVariableName, "1"); rootNode.style.setProperty(opacityVariableName, "1");
}; };
/** @type {number | undefined} */ // If this file gets more complicated, it might make sense to set up the
let intervalId = undefined; // timeout and event listener so that if one triggers, it cancels the other,
const pollingTimeoutMs = 5_000; // but having restoreOpacity run more than once is a no-op for right now.
let pollAttempts = 0; // Not a big deal if these don't get cleaned up.
const checkIfSafeToHideForm = () => {
/** @type {HTMLFormElement | null} */
const form = document.querySelector("web-client-form > form");
if (form === null) {
pollAttempts++;
const elapsedTime = pollAttempts * SCREEN_POLL_INTERVAL_MS;
if (elapsedTime >= pollingTimeoutMs) {
restoreOpacity();
window.clearInterval(intervalId);
}
return;
}
// If this file gets more complicated, it might make sense to set up the
// timeout and event listener so that if one triggers, it cancels the other,
// but having restoreOpacity run more than once is a no-op for right now.
// Not a big deal if these don't get cleaned up.
window.setTimeout(restoreOpacity, 5_000);
form.addEventListener("submit", restoreOpacity, { once: true });
};
intervalId = window.setInterval( /** @type {HTMLFormElement | null} */
checkIfSafeToHideForm, const form = document.querySelector("web-client-form > form");
SCREEN_POLL_INTERVAL_MS, form?.addEventListener("submit", restoreOpacity, { once: true });
); window.setTimeout(restoreOpacity, 5_000);
} }
function setupFormOverrides() { function setupFormOverrides() {

Loading…
Cancel
Save