Skip to content

Commit e3bd944

Browse files
committed
Impl: update the workspace panel every 5 seconds
- poll the workspaces and update the view - re-select the previous workspace and enable the next button if necessary - added logic to cancel the polling when back or next buttons are triggered
1 parent 4de8c50 commit e3bd944

File tree

4 files changed

+76
-38
lines changed

4 files changed

+76
-38
lines changed

CHANGELOG.md

+27-25
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
1-
<!-- Keep a Changelog guide -> https://keepachangelog.com -->
2-
1+
<!-- Keep a Changelog guide -> https://keepachangelog.com -->
2+
33
# coder-gateway Changelog
44

55
## [Unreleased]
6+
### Changed
7+
- workspace panel is now updated every 5 seconds
68

79
## [2.0.2]
8-
### Added
9-
- support for displaying working and non-working workspaces
10-
- better support for Light and Dark themes in the "Status" column
10+
### Added
11+
- support for displaying working and non-working workspaces
12+
- better support for Light and Dark themes in the "Status" column
1113

1214

13-
### Fixed
14-
- left panel is no longer visible when a new connection is triggered from Coder's "Recent Workspaces" panel.
15-
This provides consistency with other plugins compatible with Gateway
16-
- the "Select IDE and Project" button in the "Coder Workspaces" view is now disabled when no workspace is selected
15+
### Fixed
16+
- left panel is no longer visible when a new connection is triggered from Coder's "Recent Workspaces" panel.
17+
This provides consistency with other plugins compatible with Gateway
18+
- the "Select IDE and Project" button in the "Coder Workspaces" view is now disabled when no workspace is selected
1719

1820

19-
### Changed
21+
### Changed
2022
- the authentication view is now merged with the "Coder Workspaces" view allowing users to quickly change the host
2123

2224
## [2.0.1]
2325
### Fixed
24-
- `Recent Coder Workspaces` label overlaps with the search bar in the `Connections` view
25-
- working workspaces are now listed when there are issues with resolving agents
26-
- list only workspaces owned by the logged user
27-
26+
- `Recent Coder Workspaces` label overlaps with the search bar in the `Connections` view
27+
- working workspaces are now listed when there are issues with resolving agents
28+
- list only workspaces owned by the logged user
29+
2830

2931
### Changed
30-
- links to documentation now point to the latest Coder OSS
31-
- simplified main action link text from `Connect to Coder Workspaces` to `Connect to Coder`
32+
- links to documentation now point to the latest Coder OSS
33+
- simplified main action link text from `Connect to Coder Workspaces` to `Connect to Coder`
3234
- minimum supported Gateway build is now 222.3739.24
3335

3436
## [2.0.0]
3537
### Added
36-
- support for Gateway 2022.2
37-
38+
- support for Gateway 2022.2
39+
3840

3941
### Changed
40-
- Java 17 is now required to run the plugin
42+
- Java 17 is now required to run the plugin
4143
- adapted the code to the new SSH API provided by Gateway
4244

4345
## [1.0.0]
4446
### Added
45-
- initial scaffold for Gateway plugin
46-
- browser based authentication on Coder environments
47-
- REST client for Coder V2 public API
48-
- coder-cli orchestration for setting up the SSH configurations for Coder Workspaces
49-
- basic panel to display live Coder Workspaces
50-
- support for multi-agent Workspaces
47+
- initial scaffold for Gateway plugin
48+
- browser based authentication on Coder environments
49+
- REST client for Coder V2 public API
50+
- coder-cli orchestration for setting up the SSH configurations for Coder Workspaces
51+
- basic panel to display live Coder Workspaces
52+
- support for multi-agent Workspaces
5153
- Gateway SSH connection to a Coder Workspace

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

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class CoderGatewayConnectorWizardView : BorderLayoutPanel(), Disposable {
5151
}
5252

5353
private fun previous() {
54+
steps[currentStep].onPrevious()
55+
5456
if (currentStep == 0) {
5557
GatewayUI.getInstance().reset()
5658
} else {

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

+42-13
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ import com.coder.gateway.sdk.OS
1616
import com.coder.gateway.sdk.ex.AuthenticationResponseException
1717
import com.coder.gateway.sdk.getOS
1818
import com.coder.gateway.sdk.toURL
19-
import com.coder.gateway.sdk.v2.models.ProvisionerJobStatus
2019
import com.coder.gateway.sdk.v2.models.Workspace
21-
import com.coder.gateway.sdk.v2.models.WorkspaceBuildTransition
2220
import com.coder.gateway.sdk.withPath
2321
import com.intellij.ide.BrowserUtil
2422
import com.intellij.ide.IdeBundle
@@ -51,11 +49,13 @@ import com.intellij.util.ui.ListTableModel
5149
import com.intellij.util.ui.table.IconTableCellRenderer
5250
import kotlinx.coroutines.CoroutineScope
5351
import kotlinx.coroutines.Dispatchers
52+
import kotlinx.coroutines.Job
5453
import kotlinx.coroutines.cancel
54+
import kotlinx.coroutines.delay
55+
import kotlinx.coroutines.isActive
5556
import kotlinx.coroutines.launch
5657
import kotlinx.coroutines.withContext
5758
import org.zeroturnaround.exec.ProcessExecutor
58-
import java.awt.Color
5959
import java.awt.Component
6060
import java.awt.Dimension
6161
import javax.swing.Icon
@@ -88,6 +88,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
8888
}
8989
}
9090

91+
private var poller: Job? = null
92+
9193
override val component = panel {
9294
indent {
9395
row {
@@ -105,10 +107,12 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
105107
row(CoderGatewayBundle.message("gateway.connector.view.login.url.label")) {
106108
textField().resizableColumn().horizontalAlign(HorizontalAlign.FILL).gap(RightGap.SMALL).bindText(wizardModel::coderURL).applyToComponent {
107109
addActionListener {
110+
poller?.cancel()
108111
loginAndLoadWorkspace()
109112
}
110113
}
111114
button(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.connect.text")) {
115+
poller?.cancel()
112116
loginAndLoadWorkspace()
113117
}.applyToComponent {
114118
background = WelcomeScreenUIManager.getMainAssociatedComponentBackground()
@@ -211,18 +215,30 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
211215
}
212216

213217
private fun loadWorkspaces() {
214-
cs.launch {
215-
val workspaceList = withContext(Dispatchers.IO) {
216-
try {
217-
return@withContext coderClient.workspaces().collectAgents()
218-
} catch (e: Exception) {
219-
logger.error("Could not retrieve workspaces for ${coderClient.me.username} on ${coderClient.coderURL}. Reason: $e")
220-
emptyList()
218+
poller = cs.launch {
219+
while (isActive) {
220+
val workspaceList = withContext(Dispatchers.IO) {
221+
try {
222+
return@withContext coderClient.workspaces().collectAgents()
223+
} catch (e: Exception) {
224+
logger.error("Could not retrieve workspaces for ${coderClient.me.username} on ${coderClient.coderURL}. Reason: $e")
225+
emptyList()
226+
}
221227
}
222-
}
223228

224-
// if we just run the update on the main dispatcher, the code will block because it cant get some AWT locks
225-
ApplicationManager.getApplication().invokeLater { listTableModelOfWorkspaces.updateItems(workspaceList) }
229+
val selectedWorkspace = withContext(Dispatchers.Main) {
230+
tableOfWorkspaces.selectedObject
231+
}
232+
233+
// if we just run the update on the main dispatcher, the code will block because it cant get some AWT locks
234+
ApplicationManager.getApplication().invokeLater {
235+
listTableModelOfWorkspaces.updateItems(workspaceList)
236+
if (selectedWorkspace != null) {
237+
tableOfWorkspaces.selectItem(selectedWorkspace)
238+
}
239+
}
240+
}
241+
delay(5000)
226242
}
227243
}
228244

@@ -279,10 +295,16 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
279295
}
280296
}
281297

298+
override fun onPrevious() {
299+
super.onPrevious()
300+
poller?.cancel()
301+
}
302+
282303
override fun onNext(wizardModel: CoderWorkspacesWizardModel): Boolean {
283304
val workspace = tableOfWorkspaces.selectedObject
284305
if (workspace != null) {
285306
wizardModel.selectedWorkspace = workspace
307+
poller?.cancel()
286308
return true
287309
}
288310
return false
@@ -387,6 +409,13 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
387409
this.addRows(workspaces)
388410
}
389411

412+
private fun TableView<WorkspaceAgentModel>.selectItem(workspace: WorkspaceAgentModel) {
413+
this.items.forEachIndexed { index, workspaceAgentModel ->
414+
if (workspaceAgentModel.name == workspace.name)
415+
this.setRowSelectionInterval(index, index)
416+
}
417+
}
418+
390419
companion object {
391420
val logger = Logger.getInstance(CoderWorkspacesStepView::class.java.simpleName)
392421
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ sealed interface CoderWorkspacesWizardStep {
1010
val previousActionText: String
1111

1212
fun onInit(wizardModel: CoderWorkspacesWizardModel)
13+
14+
fun onPrevious() {
15+
16+
}
17+
1318
fun onNext(wizardModel: CoderWorkspacesWizardModel): Boolean
1419
}

0 commit comments

Comments
 (0)