Skip to content

Commit 2cd3565

Browse files
committed
fix: handle the uri when we don't do autologin
- currently the uri handling waits for the plugin to fully initialize i.e. to sign in to the coder deployment and have the list of workspaces retrieved. - this is done in order to avoid scenarios were uri handling moves faster than autologin and polling and potentially ending up with more than one polling job - however if there is a manual login flow (for example if the user logs from the coder deployment we no longer autologin at the next startup) we don't have to wait for the initial polling job to be initialized.
1 parent 9f096cf commit 2cd3565

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class CoderRemoteProvider(
238238
* Handle incoming links (like from the dashboard).
239239
*/
240240
override suspend fun handleUri(uri: URI) {
241-
linkHandler.handle(uri) { restClient, cli ->
241+
linkHandler.handle(uri, shouldDoAutoLogin()) { restClient, cli ->
242242
// stop polling and de-initialize resources
243243
close()
244244
// start initialization with the new settings
@@ -270,7 +270,7 @@ class CoderRemoteProvider(
270270
// Show sign in page if we have not configured the client yet.
271271
if (client == null) {
272272
// When coming back to the application, authenticate immediately.
273-
val autologin = firstRun && secrets.rememberMe == "true"
273+
val autologin = shouldDoAutoLogin()
274274
var autologinEx: Exception? = null
275275
secrets.lastToken.let { lastToken ->
276276
secrets.lastDeploymentURL.let { lastDeploymentURL ->
@@ -309,6 +309,8 @@ class CoderRemoteProvider(
309309
return null
310310
}
311311

312+
private fun shouldDoAutoLogin(): Boolean = firstRun && secrets.rememberMe == "true"
313+
312314
/**
313315
* Create a connect page that starts polling and resets the UI on success.
314316
*/

src/main/kotlin/com/coder/toolbox/util/CoderProtocolHandler.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ open class CoderProtocolHandler(
4040
*/
4141
suspend fun handle(
4242
uri: URI,
43+
shouldWaitForAutoLogin: Boolean,
4344
reInitialize: suspend (CoderRestClient, CoderCLIManager) -> Unit
4445
) {
4546
val params = uri.toQueryParameters()
@@ -147,7 +148,9 @@ open class CoderProtocolHandler(
147148
context.logger.info("Configuring Coder CLI...")
148149
cli.configSsh(restClient.agentNames(workspaces))
149150

150-
isInitialized.waitForTrue()
151+
if (shouldWaitForAutoLogin) {
152+
isInitialized.waitForTrue()
153+
}
151154
reInitialize(restClient, cli)
152155

153156
val environmentId = "${workspace.name}.${agent.name}"

0 commit comments

Comments
 (0)