Skip to content

Commit a8767d2

Browse files
committed
fix: the settings page doesn't see changes done from other screens
Unless we restart toolbox. This happens because the UI fields are initialized only once when the page is created. If we switch to a different page that can update the settings (for example the login screen can alter the fallback strategy when signature are missing) and then come back to the settings page - in that case Toolbox does not request the settings again from the settings store.
1 parent dcba5ec commit a8767d2

File tree

1 file changed

+75
-11
lines changed

1 file changed

+75
-11
lines changed

src/main/kotlin/com/coder/toolbox/views/CoderSettingsPage.kt

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import kotlinx.coroutines.channels.Channel
1010
import kotlinx.coroutines.channels.ClosedSendChannelException
1111
import kotlinx.coroutines.flow.MutableStateFlow
1212
import kotlinx.coroutines.flow.StateFlow
13+
import kotlinx.coroutines.flow.update
1314
import kotlinx.coroutines.launch
1415

1516
/**
@@ -89,17 +90,17 @@ class CoderSettingsPage(context: CoderToolboxContext, triggerSshConfig: Channel<
8990
override val actionButtons: StateFlow<List<RunnableActionDescription>> = MutableStateFlow(
9091
listOf(
9192
Action(context.i18n.ptrl("Save"), closesPage = true) {
92-
context.settingsStore.updateBinarySource(binarySourceField.textState.value)
93-
context.settingsStore.updateBinaryDirectory(binaryDirectoryField.textState.value)
94-
context.settingsStore.updateDataDirectory(dataDirectoryField.textState.value)
93+
context.settingsStore.updateBinarySource(binarySourceField.contentState.value)
94+
context.settingsStore.updateBinaryDirectory(binaryDirectoryField.contentState.value)
95+
context.settingsStore.updateDataDirectory(dataDirectoryField.contentState.value)
9596
context.settingsStore.updateEnableDownloads(enableDownloadsField.checkedState.value)
9697
context.settingsStore.updateSignatureFallbackStrategy(signatureFallbackStrategyField.checkedState.value)
9798
context.settingsStore.updateBinaryDirectoryFallback(enableBinaryDirectoryFallbackField.checkedState.value)
98-
context.settingsStore.updateHeaderCommand(headerCommandField.textState.value)
99-
context.settingsStore.updateCertPath(tlsCertPathField.textState.value)
100-
context.settingsStore.updateKeyPath(tlsKeyPathField.textState.value)
101-
context.settingsStore.updateCAPath(tlsCAPathField.textState.value)
102-
context.settingsStore.updateAltHostname(tlsAlternateHostnameField.textState.value)
99+
context.settingsStore.updateHeaderCommand(headerCommandField.contentState.value)
100+
context.settingsStore.updateCertPath(tlsCertPathField.contentState.value)
101+
context.settingsStore.updateKeyPath(tlsKeyPathField.contentState.value)
102+
context.settingsStore.updateCAPath(tlsCAPathField.contentState.value)
103+
context.settingsStore.updateAltHostname(tlsAlternateHostnameField.contentState.value)
103104
context.settingsStore.updateDisableAutostart(disableAutostartField.checkedState.value)
104105
val oldIsSshWildcardConfigEnabled = settings.isSshWildcardConfigEnabled
105106
context.settingsStore.updateEnableSshWildcardConfig(enableSshWildCardConfig.checkedState.value)
@@ -113,10 +114,73 @@ class CoderSettingsPage(context: CoderToolboxContext, triggerSshConfig: Channel<
113114
}
114115
}
115116
}
116-
context.settingsStore.updateSshLogDir(sshLogDirField.textState.value)
117-
context.settingsStore.updateNetworkInfoDir(networkInfoDirField.textState.value)
118-
context.settingsStore.updateSshConfigOptions(sshExtraArgs.textState.value)
117+
context.settingsStore.updateSshLogDir(sshLogDirField.contentState.value)
118+
context.settingsStore.updateNetworkInfoDir(networkInfoDirField.contentState.value)
119+
context.settingsStore.updateSshConfigOptions(sshExtraArgs.contentState.value)
119120
}
120121
)
121122
)
123+
124+
override fun beforeShow() {
125+
// update the value of all fields
126+
binarySourceField.contentState.update {
127+
settings.binarySource ?: ""
128+
}
129+
binaryDirectoryField.contentState.update {
130+
settings.binaryDirectory ?: ""
131+
}
132+
dataDirectoryField.contentState.update {
133+
settings.dataDirectory ?: ""
134+
}
135+
enableDownloadsField.checkedState.update {
136+
settings.enableDownloads
137+
}
138+
signatureFallbackStrategyField.checkedState.update {
139+
settings.fallbackOnCoderForSignatures.isAllowed()
140+
}
141+
142+
enableBinaryDirectoryFallbackField.checkedState.update {
143+
settings.enableBinaryDirectoryFallback
144+
}
145+
146+
headerCommandField.contentState.update {
147+
settings.headerCommand ?: ""
148+
}
149+
150+
tlsCertPathField.contentState.update {
151+
settings.tls.certPath ?: ""
152+
}
153+
154+
tlsKeyPathField.contentState.update {
155+
settings.tls.keyPath ?: ""
156+
}
157+
158+
tlsCAPathField.contentState.update {
159+
settings.tls.caPath ?: ""
160+
}
161+
162+
tlsAlternateHostnameField.contentState.update {
163+
settings.tls.altHostname ?: ""
164+
}
165+
166+
disableAutostartField.checkedState.update {
167+
settings.disableAutostart
168+
}
169+
170+
enableSshWildCardConfig.checkedState.update {
171+
settings.isSshWildcardConfigEnabled
172+
}
173+
174+
sshExtraArgs.contentState.update {
175+
settings.sshConfigOptions ?: ""
176+
}
177+
178+
sshLogDirField.contentState.update {
179+
settings.sshLogDirectory ?: ""
180+
}
181+
182+
networkInfoDirField.contentState.update {
183+
settings.networkInfoDir
184+
}
185+
}
122186
}

0 commit comments

Comments
 (0)