@@ -24,6 +24,8 @@ const LINGUAS = ["cs", "de", "el", "es", "fr", "it", "ja", "ko", "nl", "pl", "pt
24
24
25
25
const UI = {
26
26
27
+ customSettings : { } ,
28
+
27
29
connected : false ,
28
30
desktopName : "" ,
29
31
@@ -44,7 +46,15 @@ const UI = {
44
46
reconnectCallback : null ,
45
47
reconnectPassword : null ,
46
48
47
- async start ( ) {
49
+ async start ( options = { } ) {
50
+ UI . customSettings = options . settings || { } ;
51
+ if ( UI . customSettings . defaults === undefined ) {
52
+ UI . customSettings . defaults = { } ;
53
+ }
54
+ if ( UI . customSettings . mandatory === undefined ) {
55
+ UI . customSettings . mandatory = { } ;
56
+ }
57
+
48
58
// Set up translations
49
59
try {
50
60
await l10n . setup ( LINGUAS , "app/locale/" ) ;
@@ -159,6 +169,8 @@ const UI = {
159
169
UI . initSetting ( 'logging' , 'warn' ) ;
160
170
UI . updateLogging ( ) ;
161
171
172
+ UI . setupSettingLabels ( ) ;
173
+
162
174
/* Populate the controls if defaults are provided in the URL */
163
175
UI . initSetting ( 'encrypt' , ( window . location . protocol === "https:" ) ) ;
164
176
UI . initSetting ( 'password' ) ;
@@ -175,8 +187,6 @@ const UI = {
175
187
UI . initSetting ( 'repeaterID' , '' ) ;
176
188
UI . initSetting ( 'reconnect' , false ) ;
177
189
UI . initSetting ( 'reconnect_delay' , 5000 ) ;
178
-
179
- UI . setupSettingLabels ( ) ;
180
190
} ,
181
191
// Adds a link to the label elements on the corresponding input elements
182
192
setupSettingLabels ( ) {
@@ -738,13 +748,22 @@ const UI = {
738
748
739
749
// Initial page load read/initialization of settings
740
750
initSetting ( name , defVal ) {
751
+ // Has the user overridden the default value?
752
+ if ( name in UI . customSettings . defaults ) {
753
+ defVal = UI . customSettings . defaults [ name ] ;
754
+ }
741
755
// Check Query string followed by cookie
742
756
let val = WebUtil . getConfigVar ( name ) ;
743
757
if ( val === null ) {
744
758
val = WebUtil . readSetting ( name , defVal ) ;
745
759
}
746
760
WebUtil . setSetting ( name , val ) ;
747
761
UI . updateSetting ( name ) ;
762
+ // Has the user forced a value?
763
+ if ( name in UI . customSettings . mandatory ) {
764
+ val = UI . customSettings . mandatory [ name ] ;
765
+ UI . forceSetting ( name , val ) ;
766
+ }
748
767
return val ;
749
768
} ,
750
769
@@ -817,17 +836,21 @@ const UI = {
817
836
// disable the labels that belong to disabled input elements.
818
837
disableSetting ( name ) {
819
838
const ctrl = document . getElementById ( 'noVNC_setting_' + name ) ;
820
- ctrl . disabled = true ;
821
- if ( ctrl . label !== undefined ) {
822
- ctrl . label . classList . add ( 'noVNC_disabled' ) ;
839
+ if ( ctrl !== null ) {
840
+ ctrl . disabled = true ;
841
+ if ( ctrl . label !== undefined ) {
842
+ ctrl . label . classList . add ( 'noVNC_disabled' ) ;
843
+ }
823
844
}
824
845
} ,
825
846
826
847
enableSetting ( name ) {
827
848
const ctrl = document . getElementById ( 'noVNC_setting_' + name ) ;
828
- ctrl . disabled = false ;
829
- if ( ctrl . label !== undefined ) {
830
- ctrl . label . classList . remove ( 'noVNC_disabled' ) ;
849
+ if ( ctrl !== null ) {
850
+ ctrl . disabled = false ;
851
+ if ( ctrl . label !== undefined ) {
852
+ ctrl . label . classList . remove ( 'noVNC_disabled' ) ;
853
+ }
831
854
}
832
855
} ,
833
856
@@ -1771,6 +1794,4 @@ const UI = {
1771
1794
*/
1772
1795
} ;
1773
1796
1774
- UI . start ( ) ;
1775
-
1776
1797
export default UI ;
0 commit comments