@@ -47,15 +47,12 @@ class CoderRemoteProvider(
4747 private var pollJob: Job ? = null
4848 private var lastEnvironments: Set <CoderRemoteEnvironment >? = null
4949
50- private val isInitialized: MutableStateFlow <Boolean > = MutableStateFlow (false )
51-
5250 // Create our services from the Toolbox ones.
5351 private val settingsService = CoderSettingsService (context.settingsStore)
5452 private val settings: CoderSettings = CoderSettings (settingsService, context.logger)
5553 private val secrets: CoderSecretsService = CoderSecretsService (context.secretsStore)
5654 private val settingsPage: CoderSettingsPage = CoderSettingsPage (context, settingsService)
5755 private val dialogUi = DialogUi (context, settings)
58- private val linkHandler = CoderProtocolHandler (context, settings, httpClient, dialogUi, isInitialized)
5956
6057 // The REST client, if we are signed in
6158 private var client: CoderRestClient ? = null
@@ -67,6 +64,9 @@ class CoderRemoteProvider(
6764
6865 // On the first load, automatically log in if we can.
6966 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)
7070 override val environments: MutableStateFlow <LoadableState <List <RemoteProviderEnvironment >>> = MutableStateFlow (
7171 LoadableState .Value (emptyList())
7272 )
@@ -176,9 +176,10 @@ class CoderRemoteProvider(
176176 */
177177 override fun close () {
178178 pollJob?.cancel()
179- client = null
179+ client?.close()
180180 lastEnvironments = null
181181 environments.value = LoadableState .Value (emptyList())
182+ isInitialized.update { false }
182183 }
183184
184185 override val svgIcon: SvgIcon =
@@ -213,8 +214,7 @@ class CoderRemoteProvider(
213214 * Just displays the deployment URL at the moment, but we could use this as
214215 * a form for creating new environments.
215216 */
216- override fun getNewEnvironmentUiPage (): UiPage =
217- NewEnvironmentPage (context, context.i18n.pnotr(getDeploymentURL()?.first ? : " " ))
217+ override fun getNewEnvironmentUiPage (): UiPage = coderHeaderPager
218218
219219 /* *
220220 * We always show a list of environments.
@@ -234,7 +234,14 @@ class CoderRemoteProvider(
234234 */
235235 override suspend fun handleUri (uri : URI ) {
236236 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+ }
238245 }
239246
240247 /* *
0 commit comments