Skip to content

Commit 069277c

Browse files
committed
Fix connection not running from editor
I think we could get it working with the same trick as the IDE resolving job but it seems like there is no need for the launches anyway?
1 parent b80e8c2 commit 069277c

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

src/main/kotlin/com/coder/gateway/CoderRemoteConnectionHandle.kt

+6-10
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import com.jetbrains.gateway.ssh.SshDeployFlowUtil
3131
import com.jetbrains.gateway.ssh.SshMultistagePanelContext
3232
import com.jetbrains.gateway.ssh.deploy.DeployException
3333
import com.jetbrains.rd.util.lifetime.LifetimeDefinition
34-
import kotlinx.coroutines.GlobalScope
35-
import kotlinx.coroutines.launch
3634
import net.schmizz.sshj.common.SSHException
3735
import net.schmizz.sshj.connection.ConnectionException
3836
import java.awt.Dimension
@@ -48,7 +46,7 @@ import javax.net.ssl.SSLHandshakeException
4846
class CoderRemoteConnectionHandle {
4947
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService>()
5048

51-
suspend fun connect(getParameters: (indicator: ProgressIndicator) -> Map<String, String>) {
49+
fun connect(getParameters: (indicator: ProgressIndicator) -> Map<String, String>) {
5250
val clientLifetime = LifetimeDefinition()
5351
clientLifetime.launchUnderBackgroundProgress(CoderGatewayBundle.message("gateway.connector.coder.connection.provider.title")) {
5452
try {
@@ -79,13 +77,11 @@ class CoderRemoteConnectionHandle {
7977
indicator.text = CoderGatewayBundle.message("gateway.connector.coder.connecting.failed.retry", humanizeDuration(remainingMs))
8078
},
8179
)
82-
GlobalScope.launch {
83-
logger.info("Deploying and starting IDE with $context")
84-
// At this point JetBrains takes over with their own UI.
85-
@Suppress("UnstableApiUsage") SshDeployFlowUtil.fullDeployCycle(
86-
clientLifetime, context, Duration.ofMinutes(10)
87-
)
88-
}
80+
logger.info("Deploying and starting IDE with $context")
81+
// At this point JetBrains takes over with their own UI.
82+
@Suppress("UnstableApiUsage") SshDeployFlowUtil.fullDeployCycle(
83+
clientLifetime, context, Duration.ofMinutes(10)
84+
)
8985
recentConnectionsService.addRecentConnection(parameters.toRecentWorkspaceConnection())
9086
} catch (e: Exception) {
9187
if (isCancellation(e)) {

src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,8 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
212212
row {
213213
icon(product.icon)
214214
cell(ActionLink(connectionDetails.projectPath!!) {
215-
cs.launch {
216-
CoderRemoteConnectionHandle().connect{ connectionDetails.toWorkspaceParams() }
217-
GatewayUI.getInstance().reset()
218-
}
215+
CoderRemoteConnectionHandle().connect{ connectionDetails.toWorkspaceParams() }
216+
GatewayUI.getInstance().reset()
219217
})
220218
label("").resizableColumn().align(AlignX.FILL)
221219
label("Last opened: ${connectionDetails.lastOpened}").applyToComponent {

src/main/kotlin/com/coder/gateway/views/steps/CoderLocateRemoteProjectStepView.kt

+9-12
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import kotlinx.coroutines.Dispatchers
6767
import kotlinx.coroutines.Job
6868
import kotlinx.coroutines.async
6969
import kotlinx.coroutines.cancel
70-
import kotlinx.coroutines.cancelAndJoin
7170
import kotlinx.coroutines.launch
7271
import kotlinx.coroutines.runBlocking
7372
import kotlinx.coroutines.withContext
@@ -340,18 +339,16 @@ class CoderLocateRemoteProjectStepView(private val setNextButtonEnabled: (Boolea
340339
logger.warn("No workspace was selected. Please go back to the previous step and select a workspace")
341340
return false
342341
}
343-
cs.launch {
344-
CoderRemoteConnectionHandle().connect{
345-
selectedIDE
346-
.toWorkspaceParams()
347-
.withWorkspaceHostname(CoderCLIManager.getHostName(deploymentURL, selectedWorkspace))
348-
.withProjectPath(tfProject.text)
349-
.withWebTerminalLink("${terminalLink.url}")
350-
.withConfigDirectory(wizardModel.configDirectory)
351-
.withName(selectedWorkspace.name)
352-
}
353-
GatewayUI.getInstance().reset()
342+
CoderRemoteConnectionHandle().connect{
343+
selectedIDE
344+
.toWorkspaceParams()
345+
.withWorkspaceHostname(CoderCLIManager.getHostName(deploymentURL, selectedWorkspace))
346+
.withProjectPath(tfProject.text)
347+
.withWebTerminalLink("${terminalLink.url}")
348+
.withConfigDirectory(wizardModel.configDirectory)
349+
.withName(selectedWorkspace.name)
354350
}
351+
GatewayUI.getInstance().reset()
355352
return true
356353
}
357354

0 commit comments

Comments
 (0)