@@ -47,15 +47,12 @@ class CoderRemoteProvider(
47
47
private var pollJob: Job ? = null
48
48
private var lastEnvironments: Set <CoderRemoteEnvironment >? = null
49
49
50
- private val isInitialized: MutableStateFlow <Boolean > = MutableStateFlow (false )
51
-
52
50
// Create our services from the Toolbox ones.
53
51
private val settingsService = CoderSettingsService (context.settingsStore)
54
52
private val settings: CoderSettings = CoderSettings (settingsService, context.logger)
55
53
private val secrets: CoderSecretsService = CoderSecretsService (context.secretsStore)
56
54
private val settingsPage: CoderSettingsPage = CoderSettingsPage (context, settingsService)
57
55
private val dialogUi = DialogUi (context, settings)
58
- private val linkHandler = CoderProtocolHandler (context, settings, httpClient, dialogUi, isInitialized)
59
56
60
57
// The REST client, if we are signed in
61
58
private var client: CoderRestClient ? = null
@@ -67,6 +64,9 @@ class CoderRemoteProvider(
67
64
68
65
// On the first load, automatically log in if we can.
69
66
private var firstRun = true
67
+ private val isInitialized: MutableStateFlow <Boolean > = MutableStateFlow (false )
68
+ private var coderHeaderPager = NewEnvironmentPage (context, context.i18n.pnotr(getDeploymentURL()?.first ? : " " ))
69
+ private val linkHandler = CoderProtocolHandler (context, settings, httpClient, dialogUi, isInitialized)
70
70
override val environments: MutableStateFlow <LoadableState <List <RemoteProviderEnvironment >>> = MutableStateFlow (
71
71
LoadableState .Value (emptyList())
72
72
)
@@ -176,9 +176,10 @@ class CoderRemoteProvider(
176
176
*/
177
177
override fun close () {
178
178
pollJob?.cancel()
179
- client = null
179
+ client?.close()
180
180
lastEnvironments = null
181
181
environments.value = LoadableState .Value (emptyList())
182
+ isInitialized.update { false }
182
183
}
183
184
184
185
override val svgIcon: SvgIcon =
@@ -213,8 +214,7 @@ class CoderRemoteProvider(
213
214
* Just displays the deployment URL at the moment, but we could use this as
214
215
* a form for creating new environments.
215
216
*/
216
- override fun getNewEnvironmentUiPage (): UiPage =
217
- NewEnvironmentPage (context, context.i18n.pnotr(getDeploymentURL()?.first ? : " " ))
217
+ override fun getNewEnvironmentUiPage (): UiPage = coderHeaderPager
218
218
219
219
/* *
220
220
* We always show a list of environments.
@@ -234,7 +234,14 @@ class CoderRemoteProvider(
234
234
*/
235
235
override suspend fun handleUri (uri : URI ) {
236
236
val params = uri.toQueryParameters()
237
- linkHandler.handle(params)
237
+ linkHandler.handle(params) { restClient, cli ->
238
+ // stop polling and de-initialize resources
239
+ close()
240
+ // start initialization with the new settings
241
+ this @CoderRemoteProvider.client = restClient
242
+ coderHeaderPager = NewEnvironmentPage (context, context.i18n.pnotr(restClient.url.toString()))
243
+ poll(restClient, cli)
244
+ }
238
245
}
239
246
240
247
/* *
0 commit comments