From ef4c87e48e3e515ed10948101492a0fad6abdb0f Mon Sep 17 00:00:00 2001 From: Parkreiner Date: Tue, 25 Jun 2024 20:45:39 +0000 Subject: [PATCH] fix: simplify code for hiding form --- windows-rdp/devolutions-patch.js | 39 +++++++------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/windows-rdp/devolutions-patch.js b/windows-rdp/devolutions-patch.js index fd97cfb..5adcd38 100644 --- a/windows-rdp/devolutions-patch.js +++ b/windows-rdp/devolutions-patch.js @@ -408,38 +408,15 @@ function hideFormForInitialSubmission() { rootNode.style.setProperty(opacityVariableName, "1"); }; - /** @type {number | undefined} */ - let intervalId = undefined; - const pollingTimeoutMs = 5_000; - let pollAttempts = 0; - - 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 }); - }; + // 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. - intervalId = window.setInterval( - checkIfSafeToHideForm, - SCREEN_POLL_INTERVAL_MS, - ); + /** @type {HTMLFormElement | null} */ + const form = document.querySelector("web-client-form > form"); + form?.addEventListener("submit", restoreOpacity, { once: true }); + window.setTimeout(restoreOpacity, 5_000); } function setupFormOverrides() {