8000 refactor: clean up patch logic for clarity · coder/modules@aebf095 · GitHub
[go: up one dir, main page]

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

Commit aebf095

Browse files
committed
refactor: clean up patch logic for clarity
1 parent b283ac3 commit aebf095

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

windows-rdp/devolutions-patch.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
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
1818
* 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+
* avoided, but avoiding this as much as possible will save you some headache.
2020
* - All the CSS should be written via custom style tags and the !important
2121
* directive (as much as that is a bad idea most of the time). We do not
2222
* control the Angular app, so we have to modify things from afar to ensure
@@ -240,16 +240,12 @@ function setupFormDetection() {
240240
/** @type {HTMLFormElement | null} */
241241
const latestForm = document.querySelector("web-client-form > form");
242242

243-
if (latestForm === null) {
244-
formValueFromLastMutation = null;
245-
return;
246-
}
247-
248243
// Only try to auto-fill if we went from having no form on screen to
249244
// having a form on screen. That way, we don't accidentally override the
250245
// form if the user is trying to customize values, and this essentially
251246
// makes the script values function as default values
252-
if (formValueFromLastMutation === null) {
247+
const mounted = formValueFromLastMutation === null && latestForm !== null;
248+
if (mounted) {
253249
autoSubmitForm(latestForm);
254250
}
255251

@@ -364,7 +360,10 @@ function hideFormForInitialSubmission() {
364360
// and over.
365361
const rootNode = document.querySelector(":root");
366362
if (!(rootNode instanceof HTMLHtmlElement)) {
367-
styleContainer.innerHTML = "";
363+
// Remove the container entirely because if the browser is busted, who knows
364+
// if the CSS variables can be applied correctly. Better to have something
365+
// be a bit more ugly/painful to use, than have it be impossible to use
366+
styleContainer.remove();
368367
return;
369368
}
370369

@@ -380,6 +379,9 @@ function hideFormForInitialSubmission() {
380379
// timeout and event listener so that if one triggers, it cancels the other,
381380
// but having restoreOpacity run more than once is a no-op for right now.
382381
// Not a big deal if these don't get cleaned up.
382+
383+
// Have the form automatically reappear no matter what, so that if something
384+
// does break, the user isn't left out to dry
383385
window.setTimeout(restoreOpacity, 5_000);
384386

385387
/** @type {HTMLFormElement | null} */

0 commit comments

Comments
 (0)
0