Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 1a0a865

Browse files
committed
wip: update logic for hiding form to avoid whiffs
1 parent c7a4fce commit 1a0a865

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

windows-rdp/devolutions-patch.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* placeholder syntax via the dollar sign. The Terraform script looks for
1616
* these characters so that it can inject Coder-specific values, so any
1717
* template literal that uses the character actually needs to double up each
18-
* of them
18+
* of them. There are already a few places in this file where it couldn't be
19+
* avoided, but it will save you some headache.
1920
* - All the CSS should be written via custom style tags and the !important
2021
* directive (as much as that is a bad idea most of the time). We do not
2122
* control the Angular app, so we have to modify things from afar to ensure
@@ -359,6 +360,7 @@ function setupAlwaysOnStyles() {
359360

360361
function hideFormForInitialSubmission() {
361362
const styleId = "coder-patch--styles-initial-submission";
363+
const opacityVariableName = "--coder-opacity-multiplier";
362364

363365
/** @type {HTMLStyleElement | null} */
364366
let styleContainer = document.querySelector("#" + styleId);
@@ -376,12 +378,12 @@ function hideFormForInitialSubmission() {
376378
but the rest of the function should be in charge of making the form
377379
container visible again if something goes wrong during setup.
378380
*/
379-
--coder-opacity-multiplier: 1;
381+
$${opacityVariableName}: 0;
380382
}
381383
382384
/* web-client-form is the container for the main session form */
383385
web-client-form {
384-
opacity: calc(100% * var(--coder-opacity-multiplier)) !important;
386+
opacity: calc(100% * var($${opacityVariableName})) !important;
385387
}
386388
`;
387389

@@ -398,34 +400,34 @@ function hideFormForInitialSubmission() {
398400
return;
399401
}
400402

403+
// It's safe to make the form visible preemptively because Devolutions
404+
// outputs the Windows view through an HTML canvas that it overlays on top
405+
// of the rest of the app. Even if the form isn't hidden at the style level,
406+
// it will still be covered up.
407+
const restoreOpacity = () => {
408+
rootNode.style.setProperty(opacityVariableName, "1");
409+
};
410+
401411
/** @type {number | undefined} */
402412
let intervalId = undefined;
403-
const maxScreenPolls = 3;
413+
const pollingTimeoutMs = 5_000;
404414
let pollAttempts = 0;
405415

406416
const checkIfSafeToHideForm = () => {
407417
/** @type {HTMLFormElement | null} */
408418
const form = document.querySelector("web-client-form > form");
409419
if (form === null) {
410420
pollAttempts++;
411-
if (pollAttempts === maxScreenPolls) {
421+
const elapsedTime = pollAttempts * SCREEN_POLL_INTERVAL_MS;
422+
423+
if (elapsedTime >= pollingTimeoutMs) {
424+
restoreOpacity();
412425
window.clearInterval(intervalId);
413426
}
414427

415428
return;
416429
}
417430

418-
// Now that we know the container exists, it's safe to hide it
419-
rootNode.style.setProperty("--coder-opacity-multiplier", "0");
420-
421-
// It's safe to make the form visible preemptively because Devolutions
422-
// outputs the Windows view through an HTML canvas that it overlays on top
423-
// of the rest of the app. Even if the form isn't hidden at the style level,
424-
// it will still be covered up.
425-
const restoreOpacity = () => {
426-
rootNode.style.setProperty("--coder-opacity-multiplier", "1");
427-
};
428-
429431
// If this file gets more complicated, it might make sense to set up the
430432
// timeout and event listener so that if one triggers, it cancels the other,
431433
// but having restoreOpacity run more than once is a no-op for right now.

0 commit comments

Comments
 (0)