Skip to content

Commit c75289b

Browse files
committed
fix: URI handling when Toolbox is already opened
The IDE resolution can start before the workspace are polled and the remote provider is initialized. This commit waits for the first poll to run before continuing to installing and launching the IDE. Otherwise, Toolbox will raise an error that the env. does not exist.
1 parent 1802cdf commit c75289b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.coder.toolbox.sdk.ex.APIResponseException
77
import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
88
import com.coder.toolbox.util.CoderProtocolHandler
99
import com.coder.toolbox.util.DialogUi
10+
import com.coder.toolbox.util.waitForTrue
1011
import com.coder.toolbox.util.withPath
1112
import com.coder.toolbox.views.Action
1213
import com.coder.toolbox.views.CoderCliSetupWizardPage
@@ -316,12 +317,16 @@ class CoderRemoteProvider(
316317
) { restClient, cli ->
317318
// stop polling and de-initialize resources
318319
close()
320+
isInitialized.update {
321+
false
322+
}
319323
// start initialization with the new settings
320324
this@CoderRemoteProvider.client = restClient
321325
coderHeaderPage.setTitle(context.i18n.pnotr(restClient.url.toString()))
322326

323327
environments.showLoadingMessage()
324328
pollJob = poll(restClient, cli)
329+
isInitialized.waitForTrue()
325330
}
326331
}
327332

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ open class CoderProtocolHandler(
6767
val workspace = restClient.workspaces().matchName(workspaceName, deploymentURL) ?: return
6868

6969
val cli = configureCli(deploymentURL, restClient)
70-
reInitialize(restClient, cli)
7170

7271
var agent: WorkspaceAgent
7372
try {
7473
markAsBusy()
74+
reInitialize(restClient, cli)
7575
context.refreshMainPage()
7676
if (!prepareWorkspace(workspace, restClient, workspaceName, deploymentURL)) return
7777
// we resolve the agent after the workspace is started otherwise we can get misleading
@@ -86,6 +86,7 @@ open class CoderProtocolHandler(
8686
} finally {
8787
unmarkAsBusy()
8888
}
89+
delay(2.seconds)
8990
val environmentId = "${workspace.name}.${agent.name}"
9091
context.showEnvironmentPage(environmentId)
9192

0 commit comments

Comments
 (0)