@@ -15,7 +15,6 @@ import com.jetbrains.toolbox.api.ui.components.UiField
1515import kotlinx.coroutines.CoroutineName
1616import kotlinx.coroutines.Job
1717import kotlinx.coroutines.channels.Channel
18- import kotlinx.coroutines.channels.ClosedSendChannelException
1918import kotlinx.coroutines.flow.MutableStateFlow
2019import kotlinx.coroutines.flow.StateFlow
2120import kotlinx.coroutines.flow.update
@@ -69,32 +68,62 @@ class CoderSettingsPage(
6968 )
7069 )
7170
72- private val enableBinaryDirectoryFallbackField =
73- CheckboxField (
74- settings.enableBinaryDirectoryFallback,
75- context.i18n.ptrl(" Enable binary directory fallback" )
76- )
77- private val headerCommandField =
78- TextField (context.i18n.ptrl(" Header command" ), settings.headerCommand ? : " " , TextType .General )
79- private val tlsCertPathField =
80- TextField (context.i18n.ptrl(" TLS cert path" ), settings.tls.certPath ? : " " , TextType .General )
81- private val tlsKeyPathField =
82- TextField (context.i18n.ptrl(" TLS key path" ), settings.tls.keyPath ? : " " , TextType .General )
71+ private val enableBinaryDirectoryFallbackField = CheckboxField (
72+ settings.enableBinaryDirectoryFallback,
73+ context.i18n.ptrl(" Enable binary directory fallback" )
74+ )
75+ private val headerCommandField = TextField (
76+ context.i18n.ptrl(" Header command" ),
77+ settings.headerCommand ? : " " ,
78+ TextType .General
79+ )
80+
81+ private val tlsCertPathField = TextField (
82+ context.i18n.ptrl(" TLS cert path" ),
83+ settings.tls.certPath ? : " " ,
84+ TextType .General
85+ )
86+ private val tlsKeyPathField = TextField (
87+ context.i18n.ptrl(" TLS key path" ),
88+ settings.tls.keyPath ? : " " , TextType .General
89+ )
8390 private val tlsCAPathField =
8491 TextField (context.i18n.ptrl(" TLS CA path" ), settings.tls.caPath ? : " " , TextType .General )
8592 private val tlsAlternateHostnameField =
8693 TextField (context.i18n.ptrl(" TLS alternate hostname" ), settings.tls.altHostname ? : " " , TextType .General )
87- private val disableAutostartField =
88- CheckboxField (settings.disableAutostart, context.i18n.ptrl(" Disable autostart" ))
89-
90- private val enableSshWildCardConfig =
91- CheckboxField (settings.isSshWildcardConfigEnabled, context.i18n.ptrl(" Enable SSH wildcard config" ))
92- private val sshExtraArgs =
93- TextField (context.i18n.ptrl(" Extra SSH options" ), settings.sshConfigOptions ? : " " , TextType .General )
94- private val sshLogDirField =
95- TextField (context.i18n.ptrl(" SSH proxy log directory" ), settings.sshLogDirectory ? : " " , TextType .General )
96- private val networkInfoDirField =
97- TextField (context.i18n.ptrl(" SSH network metrics directory" ), settings.networkInfoDir, TextType .General )
94+
95+ private val disableAutostartField = CheckboxField (
96+ settings.disableAutostart,
97+ context.i18n.ptrl(" Disable autostart" )
98+ )
99+
100+ private val enableSshWildCardConfig = CheckboxField (
101+ settings.isSshWildcardConfigEnabled,
102+ context.i18n.ptrl(" Enable SSH wildcard config" )
103+ )
104+
105+ private val sshConnectionTimeoutField = TextField (
106+ context.i18n.ptrl(" SSH connection timeout (seconds)" ),
107+ settings.sshConnectionTimeoutInSeconds.toString(),
108+ TextType .Integer
109+ )
110+
111+ private val sshExtraArgs = TextField (
112+ context.i18n.ptrl(" Extra SSH options" ),
113+ settings.sshConfigOptions ? : " " ,
114+ TextType .General
115+ )
116+
117+ private val sshLogDirField = TextField (
118+ context.i18n.ptrl(" SSH proxy log directory" ),
119+ settings.sshLogDirectory ? : " " ,
120+ TextType .General
121+ )
122+ private val networkInfoDirField = TextField (
123+ context.i18n.ptrl(" SSH network metrics directory" ),
124+ settings.networkInfoDir,
125+ TextType .General
126+ )
98127
99128 private lateinit var visibilityUpdateJob: Job
100129 override val fields: StateFlow <List <UiField >> = MutableStateFlow (
@@ -115,6 +144,7 @@ class CoderSettingsPage(
115144 tlsAlternateHostnameField,
116145 disableAutostartField,
117146 enableSshWildCardConfig,
147+ sshConnectionTimeoutField,
118148 sshLogDirField,
119149 networkInfoDirField,
120150 sshExtraArgs,
@@ -124,36 +154,43 @@ class CoderSettingsPage(
124154 override val actionButtons: StateFlow <List <RunnableActionDescription >> = MutableStateFlow (
125155 listOf (
126156 Action (context, " Save" , closesPage = true ) {
127- context.settingsStore.updateBinarySource(binarySourceField.contentState.value)
128- context.settingsStore.updateBinaryDirectory(binaryDirectoryField.contentState.value)
129- context.settingsStore.updateDataDirectory(dataDirectoryField.contentState.value)
130- context.settingsStore.updateEnableDownloads(enableDownloadsField.checkedState.value)
131- context.settingsStore.updateUseAppNameAsTitle(useAppNameField.checkedState.value)
132- context.settingsStore.updateDisableSignatureVerification(disableSignatureVerificationField.checkedState.value)
133- context.settingsStore.updateSignatureFallbackStrategy(signatureFallbackStrategyField.checkedState.value)
134- context.settingsStore.updateHttpClientLogLevel(httpLoggingField.selectedValueState.value)
135- context.settingsStore.updateBinaryDirectoryFallback(enableBinaryDirectoryFallbackField.checkedState.value)
136- context.settingsStore.updateHeaderCommand(headerCommandField.contentState.value)
137- context.settingsStore.updateCertPath(tlsCertPathField.contentState.value)
138- context.settingsStore.updateKeyPath(tlsKeyPathField.contentState.value)
139- context.settingsStore.updateCAPath(tlsCAPathField.contentState.value)
140- context.settingsStore.updateAltHostname(tlsAlternateHostnameField.contentState.value)
141- context.settingsStore.updateDisableAutostart(disableAutostartField.checkedState.value)
142- val oldIsSshWildcardConfigEnabled = settings.isSshWildcardConfigEnabled
143- context.settingsStore.updateEnableSshWildcardConfig(enableSshWildCardConfig.checkedState.value)
144-
145- if (enableSshWildCardConfig.checkedState.value != oldIsSshWildcardConfigEnabled) {
146- context.cs.launch(CoroutineName (" SSH Wildcard Setting" )) {
147- try {
157+ with (context.settingsStore) {
158+ updateBinarySource(binarySourceField.contentState.value)
159+ updateBinaryDirectory(binaryDirectoryField.contentState.value)
160+ updateDataDirectory(dataDirectoryField.contentState.value)
161+ updateEnableDownloads(enableDownloadsField.checkedState.value)
162+ updateUseAppNameAsTitle(useAppNameField.checkedState.value)
163+ updateDisableSignatureVerification(disableSignatureVerificationField.checkedState.value)
164+ updateSignatureFallbackStrategy(signatureFallbackStrategyField.checkedState.value)
165+ updateHttpClientLogLevel(httpLoggingField.selectedValueState.value)
166+ updateBinaryDirectoryFallback(enableBinaryDirectoryFallbackField.checkedState.value)
167+ updateHeaderCommand(headerCommandField.contentState.value)
168+ updateCertPath(tlsCertPathField.contentState.value)
169+ updateKeyPath(tlsKeyPathField.contentState.value)
170+ updateCAPath(tlsCAPathField.contentState.value)
171+ updateAltHostname(tlsAlternateHostnameField.contentState.value)
172+ updateDisableAutostart(disableAutostartField.checkedState.value)
173+
174+ val sshWildcardEnabled = enableSshWildCardConfig.checkedState.value
175+ val sshTimeout = sshConnectionTimeoutField.contentState.value.toInt()
176+
177+ val sshSettingsChanged = sshWildcardEnabled != settings.isSshWildcardConfigEnabled ||
178+ sshTimeout != settings.sshConnectionTimeoutInSeconds
179+
180+ updateEnableSshWildcardConfig(sshWildcardEnabled)
181+ updateSshConnectionTimeoutInSeconds(sshTimeout)
182+
183+ if (sshSettingsChanged) {
184+ runCatching {
148185 triggerSshConfig.send(true )
149- context.logger.info(" Wildcard settings have been modified from $oldIsSshWildcardConfigEnabled to ${! oldIsSshWildcardConfigEnabled} , ssh config is going to be regenerated..." )
150- } catch (_: ClosedSendChannelException ) {
186+ context.logger.info(" Settings have been modified, ssh config is going to be regenerated..." )
151187 }
152188 }
189+
190+ updateSshLogDir(sshLogDirField.contentState.value)
191+ updateNetworkInfoDir(networkInfoDirField.contentState.value)
192+ updateSshConfigOptions(sshExtraArgs.contentState.value)
153193 }
154- context.settingsStore.updateSshLogDir(sshLogDirField.contentState.value)
155- context.settingsStore.updateNetworkInfoDir(networkInfoDirField.contentState.value)
156- context.settingsStore.updateSshConfigOptions(sshExtraArgs.contentState.value)
157194 }
158195 )
159196 )
@@ -211,6 +248,10 @@ class CoderSettingsPage(
211248 settings.isSshWildcardConfigEnabled
212249 }
213250
251+ sshConnectionTimeoutField.contentState.update {
252+ settings.sshConnectionTimeoutInSeconds.toString()
253+ }
254+
214255 sshExtraArgs.contentState.update {
215256 settings.sshConfigOptions ? : " "
216257 }
0 commit comments