Skip to content

Commit 4e5ef77

Browse files
committed
impl: support for Toolbox 2.6.0.38881 (5)
- fix compiler errors for Coder main page - associated strings converted to LocalizedString instances - observable properties are now moved to Kotlin's StateFlow
1 parent 7cfd6f5 commit 4e5ef77

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,12 @@ class CoderRemoteProvider(
307307
* Create a connect page that starts polling and resets the UI on success.
308308
*/
309309
private fun createConnectPage(deploymentURL: URL, token: String?): ConnectPage = ConnectPage(
310+
serviceLocator,
310311
deploymentURL,
311312
token,
312313
settings,
313314
httpClient,
314-
coroutineScope,
315+
i18n.ptrl("Connecting to Coder"),
315316
::goToEnvironmentsPage,
316317
) { client, cli ->
317318
// Store the URL and token for use next time.

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import com.coder.toolbox.plugin.PluginManager
66
import com.coder.toolbox.sdk.CoderRestClient
77
import com.coder.toolbox.settings.CoderSettings
88
import com.coder.toolbox.util.humanizeConnectionError
9+
import com.jetbrains.toolbox.api.core.ServiceLocator
10+
import com.jetbrains.toolbox.api.localization.LocalizableString
11+
import com.jetbrains.toolbox.api.localization.LocalizableStringFactory
912
import com.jetbrains.toolbox.api.ui.actions.RunnableActionDescription
1013
import com.jetbrains.toolbox.api.ui.components.LabelField
1114
import com.jetbrains.toolbox.api.ui.components.UiField
1215
import kotlinx.coroutines.CoroutineScope
1316
import kotlinx.coroutines.Job
17+
import kotlinx.coroutines.flow.MutableStateFlow
18+
import kotlinx.coroutines.flow.StateFlow
1419
import kotlinx.coroutines.launch
1520
import okhttp3.OkHttpClient
1621
import java.net.URL
@@ -19,22 +24,26 @@ import java.net.URL
1924
* A page that connects a REST client and cli to Coder.
2025
*/
2126
class ConnectPage(
27+
private val serviceLocator: ServiceLocator,
2228
private val url: URL,
2329
private val token: String?,
2430
private val settings: CoderSettings,
2531
private val httpClient: OkHttpClient,
26-
private val coroutineScope: CoroutineScope,
32+
title: LocalizableString,
2733
private val onCancel: () -> Unit,
2834
private val onConnect: (
2935
client: CoderRestClient,
3036
cli: CoderCLIManager,
3137
) -> Unit,
32-
) : CoderPage("Connecting to Coder") {
38+
) : CoderPage(serviceLocator, title) {
39+
private val coroutineScope = serviceLocator.getService(CoroutineScope::class.java)
40+
private val i18n = serviceLocator.getService(LocalizableStringFactory::class.java)
41+
3342
private var signInJob: Job? = null
3443

35-
private var statusField = LabelField("Connecting to ${url.host}...")
44+
private var statusField = LabelField(i18n.pnotr("Connecting to ${url.host}..."))
3645

37-
override val description: String = "Please wait while we configure Toolbox for ${url.host}."
46+
override val description: LocalizableString = i18n.pnotr("Please wait while we configure Toolbox for ${url.host}.")
3847

3948
init {
4049
connect()
@@ -45,23 +54,26 @@ class ConnectPage(
4554
*
4655
* TODO@JB: This looks kinda sparse. A centered spinner would be welcome.
4756
*/
48-
override val fields: MutableList<UiField> = listOfNotNull(
57+
override val fields: StateFlow<List<UiField>> = MutableStateFlow(
58+
listOfNotNull(
4959
statusField,
50-
errorField,
51-
).toMutableList()
60+
errorField
61+
)
62+
)
5263

5364
/**
5465
* Show a retry button on error.
5566
*/
56-
override val actionButtons: MutableList<RunnableActionDescription> = listOfNotNull(
57-
if (errorField != null) Action("Retry", closesPage = false) { retry() } else null,
58-
if (errorField != null) Action("Cancel", closesPage = false) { onCancel() } else null,
59-
).toMutableList()
67+
override val actionButtons: StateFlow<List<RunnableActionDescription>> = MutableStateFlow(
68+
listOfNotNull(
69+
if (errorField != null) Action(i18n.ptrl("Retry"), closesPage = false) { retry() } else null,
70+
if (errorField != null) Action(i18n.ptrl("Cancel"), closesPage = false) { onCancel() } else null,
71+
))
6072

6173
/**
6274
* Update the status and error fields then refresh.
6375
*/
64-
private fun updateStatus(newStatus: String, error: String?) {
76+
private fun updateStatus(newStatus: LocalizableString, error: String?) {
6577
statusField = LabelField(newStatus)
6678
updateError(error) // Will refresh.
6779
}
@@ -70,7 +82,7 @@ class ConnectPage(
7082
* Try connecting again after an error.
7183
*/
7284
private fun retry() {
73-
updateStatus("Connecting to ${url.host}...", null)
85+
updateStatus(i18n.pnotr("Connecting to ${url.host}..."), null)
7486
connect()
7587
}
7688

@@ -92,21 +104,21 @@ class ConnectPage(
92104
httpClient
93105
)
94106
client.authenticate()
95-
updateStatus("Checking Coder binary...", error = null)
107+
updateStatus(i18n.ptrl("Checking Coder binary..."), error = null)
96108
val cli = ensureCLI(client.url, client.buildVersion, settings) { status ->
97-
updateStatus(status, error = null)
109+
updateStatus(i18n.pnotr(status), error = null)
98110
}
99111
// We only need to log in if we are using token-based auth.
100112
if (client.token != null) {
101-
updateStatus("Configuring CLI...", error = null)
113+
updateStatus(i18n.ptrl("Configuring CLI..."), error = null)
102114
cli.login(client.token)
103115
}
104116
onConnect(client, cli)
105117

106118
} catch (ex: Exception) {
107119
val msg = humanizeConnectionError(url, settings.requireTokenAuth, ex)
108120
notify("Failed to configure ${url.host}", ex)
109-
updateStatus("Failed to configure ${url.host}", msg)
121+
updateStatus(i18n.pnotr("Failed to configure ${url.host}"), msg)
110122
}
111123
}
112124
}

src/main/resources/localization/defaultMessages.po

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,14 @@ msgstr ""
115115
msgid "Disable autostart"
116116
msgstr ""
117117

118+
msgid "Connecting to Coder"
119+
msgstr ""
120+
121+
msgid "Checking Coder binary..."
122+
msgstr ""
118123

124+
msgid "Configuring CLI..."
125+
msgstr ""
126+
127+
msgid "Retry"
128+
msgstr ""

0 commit comments

Comments
 (0)