Skip to content

Commit 9097242

Browse files
committed
impl: improve URI flow when Toolbox is closed
When Toolbox is closed and URI is executed the handler waits for the plugin to fully initialize with the last successful deployment after which it goes on with the URI handling logic. We can improve this situation by skipping the last successful deployment which anyway. This reduces a lot the time to an actual IDE connection.
1 parent 451aa74 commit 9097242

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import kotlinx.coroutines.selects.onTimeout
4747
import kotlinx.coroutines.selects.select
4848
import java.net.URI
4949
import java.net.URL
50+
import java.util.concurrent.atomic.AtomicBoolean
5051
import kotlin.coroutines.cancellation.CancellationException
5152
import kotlin.time.Duration.Companion.seconds
5253
import kotlin.time.TimeSource
@@ -78,6 +79,7 @@ class CoderRemoteProvider(
7879
private var firstRun = true
7980

8081
private val isInitialized: MutableStateFlow<Boolean> = MutableStateFlow(false)
82+
private val isHandlingUri: AtomicBoolean = AtomicBoolean(false)
8183
private val coderHeaderPage = NewEnvironmentPage(context.i18n.pnotr(context.deploymentUrl.toString()))
8284
private val settingsPage: CoderSettingsPage = CoderSettingsPage(context, triggerSshConfig) {
8385
client?.let { restClient ->
@@ -354,13 +356,11 @@ class CoderRemoteProvider(
354356
context.logAndShowInfo("URI will not be handled", "No query parameters were provided")
355357
return
356358
}
359+
isHandlingUri.set(true)
357360
// this switches to the main plugin screen, even
358361
// if last opened provider was not Coder
359362
context.envPageManager.showPluginEnvironmentsPage()
360363
coderHeaderPage.isBusy.update { true }
361-
if (shouldDoAutoSetup()) {
362-
isInitialized.waitForTrue()
363-
}
364364
context.logger.info("Handling $uri...")
365365
val newUrl = resolveDeploymentUrl(params)?.toURL() ?: return
366366
val newToken = if (context.settingsStore.requiresMTlsAuth) null else resolveToken(params) ?: return
@@ -386,8 +386,9 @@ class CoderRemoteProvider(
386386
beforeShow()
387387
}
388388
}
389-
// TODO - do I really need these two lines? I'm anyway doing a workspace call
389+
// force the poll loop to run
390390
triggerProviderVisible.send(true)
391+
// wait for environments to be populated
391392
isInitialized.waitForTrue()
392393

393394
linkHandler.handle(params, newUrl, this.client!!, this.cli!!)
@@ -405,6 +406,7 @@ class CoderRemoteProvider(
405406
context.envPageManager.showPluginEnvironmentsPage()
406407
} finally {
407408
coderHeaderPage.isBusy.update { false }
409+
isHandlingUri.set(false)
408410
}
409411
}
410412

@@ -467,6 +469,9 @@ class CoderRemoteProvider(
467469
* list.
468470
*/
469471
override fun getOverrideUiPage(): UiPage? {
472+
if (isHandlingUri.get()) {
473+
return null
474+
}
470475
// Show the setup page if we have not configured the client yet.
471476
if (client == null) {
472477
// When coming back to the application, initializeSession immediately.

0 commit comments

Comments
 (0)