@@ -3,7 +3,6 @@ package com.coder.gateway.views.steps
3
3
import com.coder.gateway.CoderGatewayBundle
4
4
import com.coder.gateway.CoderRemoteConnectionHandle
5
5
import com.coder.gateway.CoderSupportedVersions
6
- import com.coder.gateway.cli.CoderCLIManager
7
6
import com.coder.gateway.cli.ensureCLI
8
7
import com.coder.gateway.cli.ex.ResponseException
9
8
import com.coder.gateway.icons.CoderIcons
@@ -88,8 +87,6 @@ private const val SESSION_TOKEN = "session-token"
88
87
class CoderWorkspacesStepView (val setNextButtonEnabled : (Boolean ) -> Unit ) : CoderWorkspacesWizardStep, Disposable {
89
88
private val cs = CoroutineScope (Dispatchers .Main )
90
89
private var localWizardModel = CoderWorkspacesWizardModel ()
91
- private var client: CoderRestClient ? = null
92
- private var cliManager: CoderCLIManager ? = null
93
90
private val settings: CoderSettingsService = service<CoderSettingsService >()
94
91
95
92
private val appPropertiesService: PropertiesComponent = service()
@@ -227,7 +224,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
227
224
private inner class GoToDashboardAction :
228
225
AnActionButton (CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.dashboard.text" ), CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.dashboard.text" ), CoderIcons .HOME ) {
229
226
override fun actionPerformed (p0 : AnActionEvent ) {
230
- val c = client
227
+ val c = localWizardModel. client
231
228
if (c != null ) {
232
229
BrowserUtil .browse(c.url)
233
230
}
@@ -237,7 +234,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
237
234
private inner class GoToTemplateAction :
238
235
AnActionButton (CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.template.text" ), CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.template.text" ), AllIcons .Nodes .Template ) {
239
236
override fun actionPerformed (p0 : AnActionEvent ) {
240
- val c = client
237
+ val c = localWizardModel. client
241
238
if (tableOfWorkspaces.selectedObject != null && c != null ) {
242
239
val workspace = (tableOfWorkspaces.selectedObject as WorkspaceAgentListModel ).workspace
243
240
BrowserUtil .browse(c.url.toURI().resolve(" /templates/${workspace.templateName} " ))
@@ -248,7 +245,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
248
245
private inner class StartWorkspaceAction :
249
246
AnActionButton (CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.start.text" ), CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.start.text" ), CoderIcons .RUN ) {
250
247
override fun actionPerformed (p0 : AnActionEvent ) {
251
- val c = client
248
+ val c = localWizardModel. client
252
249
if (tableOfWorkspaces.selectedObject != null && c != null ) {
253
250
val workspace = (tableOfWorkspaces.selectedObject as WorkspaceAgentListModel ).workspace
254
251
cs.launch {
@@ -268,7 +265,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
268
265
private inner class UpdateWorkspaceTemplateAction :
269
266
AnActionButton (CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.update.text" ), CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.update.text" ), CoderIcons .UPDATE ) {
270
267
override fun actionPerformed (p0 : AnActionEvent ) {
271
- val c = client
268
+ val c = localWizardModel. client
272
269
if (tableOfWorkspaces.selectedObject != null && c != null ) {
273
270
val workspace = (tableOfWorkspaces.selectedObject as WorkspaceAgentListModel ).workspace
274
271
cs.launch {
@@ -290,7 +287,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
290
287
private inner class StopWorkspaceAction :
291
288
AnActionButton (CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.stop.text" ), CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.stop.text" ), CoderIcons .STOP ) {
292
289
override fun actionPerformed (p0 : AnActionEvent ) {
293
- val c = client
290
+ val c = localWizardModel. client
294
291
if (tableOfWorkspaces.selectedObject != null && c != null ) {
295
292
val workspace = (tableOfWorkspaces.selectedObject as WorkspaceAgentListModel ).workspace
296
293
cs.launch {
@@ -310,7 +307,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
310
307
private inner class CreateWorkspaceAction :
311
308
AnActionButton (CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.create.text" ), CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.create.text" ), CoderIcons .CREATE ) {
312
309
override fun actionPerformed (p0 : AnActionEvent ) {
313
- val c = client
310
+ val c = localWizardModel. client
314
311
if (c != null ) {
315
312
BrowserUtil .browse(c.url.toURI().resolve(" /templates" ))
316
313
}
@@ -350,8 +347,8 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
350
347
}
351
348
352
349
private fun updateWorkspaceActions () {
353
- goToDashboardAction.isEnabled = client != null
354
- createWorkspaceAction.isEnabled = client != null
350
+ goToDashboardAction.isEnabled = localWizardModel. client != null
351
+ createWorkspaceAction.isEnabled = localWizardModel. client != null
355
352
goToTemplateAction.isEnabled = tableOfWorkspaces.selectedObject != null
356
353
when (tableOfWorkspaces.selectedObject?.workspace?.latestBuild?.status) {
357
354
WorkspaceStatus .RUNNING -> {
@@ -417,8 +414,8 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
417
414
onAuthFailure : (() -> Unit )? = null,
418
415
): Job {
419
416
// Clear out old deployment details.
420
- cliManager = null
421
- client = null
417
+ localWizardModel. cliManager = null
418
+ localWizardModel. client = null
422
419
poller?.cancel()
423
420
tfUrlComment?.foreground = UIUtil .getContextHelpForeground()
424
421
tfUrlComment?.text = CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text.connecting" , deploymentURL.host)
@@ -430,7 +427,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
430
427
try {
431
428
this .indicator.text = " Authenticating client..."
432
429
val authedClient = authenticate(deploymentURL, token.first)
433
- client = authedClient
430
+ localWizardModel. client = authedClient
434
431
435
432
// Remember these in order to default to them for future attempts.
436
433
appPropertiesService.setValue(CODER_URL_KEY , deploymentURL.toString())
@@ -452,7 +449,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
452
449
updateWorkspaceActions()
453
450
triggerWorkspacePolling(false )
454
451
455
- cliManager = cli
452
+ localWizardModel. cliManager = cli
456
453
tableOfWorkspaces.setEmptyState(CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text.connected" , deploymentURL.host))
457
454
tfUrlComment?.text = CoderGatewayBundle .message(" gateway.connector.view.coder.workspaces.connect.text.connected" , deploymentURL.host)
458
455
} catch (e: Exception ) {
@@ -575,7 +572,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
575
572
private suspend fun loadWorkspaces () {
576
573
val ws = withContext(Dispatchers .IO ) {
577
574
val timeBeforeRequestingWorkspaces = System .currentTimeMillis()
578
- val clientNow = client ? : return @withContext emptySet()
575
+ val clientNow = localWizardModel. client ? : return @withContext emptySet()
579
576
try {
580
577
val ws = clientNow.workspaces()
581
578
val ams = ws.flatMap { it.toAgentList() }
@@ -609,38 +606,35 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
609
606
}
610
607
611
608
override fun onNext (wizardModel : CoderWorkspacesWizardModel ): Boolean {
612
- wizardModel.apply {
613
- coderURL = localWizardModel.coderURL
614
- token = localWizardModel.token
615
- }
616
-
617
609
// These being null would be a developer error.
618
610
val selected = tableOfWorkspaces.selectedObject
619
- val cli = cliManager
620
- val clientNow = client
621
611
if (selected?.agent == null ) {
622
612
logger.error(" No selected agent" )
623
613
return false
624
- } else if (cli == null ) {
625
- logger.error(" No configured CLI" )
626
- return false
627
- } else if (clientNow == null ) {
628
- logger.error(" No configured client" )
629
- return false
630
614
}
631
615
632
- wizardModel.selectedListItem = selected
616
+ // Apply values that will be used in the next step.
617
+ wizardModel.apply {
618
+ coderURL = localWizardModel.coderURL
619
+ token = localWizardModel.token
620
+ selectedListItem = selected
621
+ // The next step will use these to configure the CLI. We could do it
622
+ // here but then we would need to show another progress indicator.
623
+ // The next step already has one so might as well use it.
624
+ cliManager = localWizardModel.cliManager
625
+ client = localWizardModel.client
626
+ // Pass along the latest workspaces so the next step can configure
627
+ // the CLI a bit faster, otherwise it would have to fetch the
628
+ // workspaces again.
629
+ workspaces = tableOfWorkspaces.items.map { it.workspace }
630
+ // The config directory can be used to pull the URL and token in
631
+ // order to query this workspace's status in other flows, for
632
+ // example from the recent connections screen.
633
+ configDirectory = cliManager?.coderConfigPath?.toString() ? : " "
634
+ }
633
635
poller?.cancel()
634
636
635
- logger.info(" Configuring Coder CLI..." )
636
- cli.configSsh(clientNow.agentNames())
637
-
638
- // The config directory can be used to pull the URL and token in
639
- // order to query this workspace's status in other flows, for
640
- // example from the recent connections screen.
641
- wizardModel.configDirectory = cli.coderConfigPath.toString()
642
-
643
- logger.info(" Opening IDE and Project Location window for ${selected.name} " )
637
+ logger.info(" Opening IDE selection window for ${selected.name} " )
644
638
return true
645
639
}
646
640
0 commit comments