Skip to content

Commit 00f9ab3

Browse files
committed
fix: wait for IDE to be installed and then connect
1 parent 21f012d commit 00f9ab3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

+13-13
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import kotlinx.coroutines.delay
1515
import kotlinx.coroutines.flow.StateFlow
1616
import kotlinx.coroutines.flow.first
1717
import kotlinx.coroutines.launch
18+
import kotlinx.coroutines.runBlocking
1819
import kotlinx.coroutines.time.withTimeout
19-
import kotlinx.coroutines.yield
2020
import okhttp3.OkHttpClient
2121
import java.net.HttpURLConnection
2222
import java.net.URI
@@ -152,21 +152,21 @@ open class CoderProtocolHandler(
152152
reInitialize(restClient, cli)
153153

154154
val environmentId = "${workspace.name}.${agent.name}"
155-
context.cs.launch {
156-
context.ui.showWindow()
157-
context.envPageManager.showPluginEnvironmentsPage(true)
158-
context.envPageManager.showEnvironmentPage(environmentId, false)
159-
val productCode = params.ideProductCode()
160-
val buildNumber = params.ideBuildNumber()
161-
if (!productCode.isNullOrBlank() && !buildNumber.isNullOrBlank()) {
155+
context.ui.showWindow()
156+
context.envPageManager.showPluginEnvironmentsPage(true)
157+
context.envPageManager.showEnvironmentPage(environmentId, false)
158+
val productCode = params.ideProductCode()
159+
val buildNumber = params.ideBuildNumber()
160+
if (!productCode.isNullOrBlank() && !buildNumber.isNullOrBlank()) {
161+
context.cs.launch {
162162
val ideVersion = "$productCode-$buildNumber"
163163
context.logger.info("installing $ideVersion on $environmentId")
164-
context.ideOrchestrator.prepareClient(environmentId, ideVersion)
164+
runBlocking {
165+
context.ideOrchestrator.prepareClient(environmentId, ideVersion)
166+
}
167+
context.logger.info("launching $ideVersion on $environmentId")
168+
context.ideOrchestrator.connectToIde(environmentId, ideVersion, null)
165169
}
166-
// without a yield or a delay(0) the env page does not show up. My assumption is that
167-
// the coroutine is finishing too fast without giving enough time to compose main thread
168-
// to catch the state change. Yielding gives other coroutines the chance to run
169-
yield()
170170
}
171171
}
172172

0 commit comments

Comments
 (0)