15
15
* placeholder syntax via the dollar sign. The Terraform script looks for
16
16
* these characters so that it can inject Coder-specific values, so any
17
17
* 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.
19
20
* - All the CSS should be written via custom style tags and the !important
20
21
* directive (as much as that is a bad idea most of the time). We do not
21
22
* control the Angular app, so we have to modify things from afar to ensure
@@ -359,6 +360,7 @@ function setupAlwaysOnStyles() {
359
360
360
361
function hideFormForInitialSubmission ( ) {
361
362
const styleId = "coder-patch--styles-initial-submission" ;
363
+ const opacityVariableName = "--coder-opacity-multiplier" ;
362
364
363
365
/** @type {HTMLStyleElement | null } */
364
366
let styleContainer = document . querySelector ( "#" + styleId ) ;
@@ -376,12 +378,12 @@ function hideFormForInitialSubmission() {
376
378
but the rest of the function should be in charge of making the form
377
379
container visible again if something goes wrong during setup.
378
380
*/
379
- --coder-opacity-multiplier: 1 ;
381
+ $ ${ opacityVariableName } : 0 ;
380
382
}
381
383
382
384
/* web-client-form is the container for the main session form */
383
385
web-client-form {
384
- opacity: calc(100% * var(--coder-opacity-multiplier )) !important;
386
+ opacity: calc(100% * var($ ${ opacityVariableName } )) !important;
385
387
}
386
388
` ;
387
389
@@ -398,34 +400,34 @@ function hideFormForInitialSubmission() {
398
400
return ;
399
401
}
400
402
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
+
401
411
/** @type {number | undefined } */
402
412
let intervalId = undefined ;
403
- const maxScreenPolls = 3 ;
413
+ const pollingTimeoutMs = 5_000 ;
404
414
let pollAttempts = 0 ;
405
415
406
416
const checkIfSafeToHideForm = ( ) => {
407
417
/** @type {HTMLFormElement | null } */
408
418
const form = document . querySelector ( "web-client-form > form" ) ;
409
419
if ( form === null ) {
410
420
pollAttempts ++ ;
411
- if ( pollAttempts === maxScreenPolls ) {
421
+ const elapsedTime = pollAttempts * SCREEN_POLL_INTERVAL_MS ;
422
+
423
+ if ( elapsedTime >= pollingTimeoutMs ) {
424
+ restoreOpacity ( ) ;
412
425
window . clearInterval ( intervalId ) ;
413
426
}
414
427
415
428
return ;
416
429
}
417
430
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
-
429
431
// If this file gets more complicated, it might make sense to set up the
430
432
// timeout and event listener so that if one triggers, it cancels the other,
431
433
// but having restoreOpacity run more than once is a no-op for right now.
0 commit comments