Skip to content

Commit 33f7a58

Browse files
authored
Merge pull request #77 from coder/cache-workspace-session
Cache Coder session
2 parents 8b36c6f + 074bf97 commit 33f7a58

File tree

5 files changed

+66
-28
lines changed

5 files changed

+66
-28
lines changed

CHANGELOG.md

+21-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- support for remembering last opened Coder session
10+
11+
### Changed
12+
13+
- minimum supported Gateway build is now 222.3739.54
14+
- some dialog titles
15+
716
## [2.1.0]
8-
### Added
9-
- support for displaying workspace version
10-
- support for managing the lifecycle of a workspace, i.e. start and stop and update workspace to the latest template version
1117

12-
### Changed
13-
- workspace panel is now updated every 5 seconds
14-
- combinations of workspace names and agent names are now listed even when a workspace is down
15-
- minimum supported Gateway build is now 222.3739.40
18+
### Added
19+
20+
- support for displaying workspace version
21+
- support for managing the lifecycle of a workspace, i.e. start and stop and update workspace to the latest template version
22+
23+
### Changed
24+
25+
- workspace panel is now updated every 5 seconds
26+
- combinations of workspace names and agent names are now listed even when a workspace is down
27+
- minimum supported Gateway build is now 222.3739.40
1628

17-
### Fixed
18-
- terminal link for workspaces with a single agent
29+
### Fixed
30+
- terminal link for workspaces with a single agent
1931
- no longer allow users to open a connection to a Windows or macOS workspace. It's not yet supported by Gateway
2032

2133
## [2.0.2]

gradle.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
pluginGroup=com.coder.gateway
44
pluginName=coder-gateway
55
# SemVer format -> https://semver.org
6-
pluginVersion=2.1.0
6+
pluginVersion=2.1.1
77
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
88
# for insight into build numbers and IntelliJ Platform versions.
9-
pluginSinceBuild=222.3739.40
9+
pluginSinceBuild=222.3739.54
1010
pluginUntilBuild=222.*
1111
# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
1212
# Gateway available build versions https://www.jetbrains.com/intellij-repository/snapshots and https://www.jetbrains.com/intellij-repository/releases
1313
platformType=GW
14-
platformVersion=222.3739.40-CUSTOM-SNAPSHOT
15-
instrumentationCompiler=222.3739.40-CUSTOM-SNAPSHOT
14+
platformVersion=222.3739.54-CUSTOM-SNAPSHOT
15+
instrumentationCompiler=222.3739.54-CUSTOM-SNAPSHOT
1616
platformDownloadSources=true
1717
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
1818
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
5555
}
5656

5757
val clientLifetime = LifetimeDefinition()
58-
clientLifetime.launchUnderBackgroundProgress("Coder Gateway Deploy", canBeCancelled = true, isIndeterminate = true, project = null) {
58+
clientLifetime.launchUnderBackgroundProgress(CoderGatewayBundle.message("gateway.connector.coder.connection.provider.title"), canBeCancelled = true, isIndeterminate = true, project = null) {
5959
val context = SshMultistagePanelContext(
6060
HostDeployInputs.FullySpecified(
6161
remoteProjectPath = projectPath,

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

+38-13
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import com.intellij.icons.AllIcons
2828
import com.intellij.ide.ActivityTracker
2929
import com.intellij.ide.BrowserUtil
3030
import com.intellij.ide.IdeBundle
31+
import com.intellij.ide.util.PropertiesComponent
3132
import com.intellij.openapi.Disposable
3233
import com.intellij.openapi.actionSystem.AnActionEvent
33-
import com.intellij.openapi.application.ApplicationManager
3434
import com.intellij.openapi.application.ModalityState
3535
import com.intellij.openapi.application.invokeAndWaitIfNeeded
36+
import com.intellij.openapi.components.service
3637
import com.intellij.openapi.diagnostic.Logger
3738
import com.intellij.openapi.progress.ProgressIndicator
3839
import com.intellij.openapi.progress.ProgressManager
@@ -72,16 +73,23 @@ import java.awt.Dimension
7273
import javax.swing.Icon
7374
import javax.swing.JLabel
7475
import javax.swing.JTable
76+
import javax.swing.JTextField
7577
import javax.swing.ListSelectionModel
7678
import javax.swing.table.DefaultTableCellRenderer
7779
import javax.swing.table.TableCellRenderer
7880

7981

82+
private const val CODER_URL_KEY = "coder-url"
83+
84+
private const val SESSION_TOKEN = "session-token"
85+
8086
class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) : CoderWorkspacesWizardStep, Disposable {
8187
private val cs = CoroutineScope(Dispatchers.Main)
8288
private var localWizardModel = CoderWorkspacesWizardModel()
83-
private val coderClient: CoderRestClientService = ApplicationManager.getApplication().getService(CoderRestClientService::class.java)
89+
private val coderClient: CoderRestClientService = service()
90+
private val appPropertiesService: PropertiesComponent = service()
8491

92+
private var tfUrl: JTextField? = null
8593
private var listTableModelOfWorkspaces = ListTableModel<WorkspaceAgentModel>(
8694
WorkspaceIconColumnInfo(""),
8795
WorkspaceNameColumnInfo("Name"),
@@ -148,15 +156,15 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
148156
browserLink(CoderGatewayBundle.message("gateway.connector.view.login.documentation.action"), "https://coder.com/docs/coder-oss/latest/workspaces")
149157
}.bottomGap(BottomGap.MEDIUM)
150158
row(CoderGatewayBundle.message("gateway.connector.view.login.url.label")) {
151-
textField().resizableColumn().horizontalAlign(HorizontalAlign.FILL).gap(RightGap.SMALL).bindText(localWizardModel::coderURL).applyToComponent {
159+
tfUrl = textField().resizableColumn().horizontalAlign(HorizontalAlign.FILL).gap(RightGap.SMALL).bindText(localWizardModel::coderURL).applyToComponent {
152160
addActionListener {
153161
poller?.cancel()
154-
loginAndLoadWorkspace()
162+
askTokenAndOpenSession()
155163
}
156-
}
164+
}.component
157165
button(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.connect.text")) {
158166
poller?.cancel()
159-
loginAndLoadWorkspace()
167+
askTokenAndOpenSession()
160168
}.applyToComponent {
161169
background = WelcomeScreenUIManager.getMainAssociatedComponentBackground()
162170
}
@@ -238,6 +246,17 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
238246
enableNextButtonCallback(false)
239247
if (localWizardModel.coderURL.isNotBlank() && localWizardModel.token.isNotBlank()) {
240248
triggerWorkspacePolling()
249+
} else {
250+
val url = appPropertiesService.getValue(CODER_URL_KEY)
251+
val token = appPropertiesService.getValue(SESSION_TOKEN)
252+
if (!url.isNullOrBlank() && !token.isNullOrBlank()) {
253+
localWizardModel.coderURL = url
254+
localWizardModel.token = token
255+
tfUrl?.text = url
256+
257+
poller?.cancel()
258+
loginAndLoadWorkspace(token)
259+
}
241260
}
242261
updateWorkspaceActions()
243262
}
@@ -272,28 +291,31 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
272291
ActivityTracker.getInstance().inc()
273292
}
274293

275-
private fun loginAndLoadWorkspace() {
294+
private fun askTokenAndOpenSession() {
276295
// force bindings to be filled
277296
component.apply()
278297

279-
BrowserUtil.browse(localWizardModel.coderURL.toURL().withPath("/login?redirect=%2Fcli-auth"))
280298
val pastedToken = askToken()
281-
282299
if (pastedToken.isNullOrBlank()) {
283300
return
284301
}
302+
loginAndLoadWorkspace(pastedToken)
303+
}
304+
305+
private fun loginAndLoadWorkspace(token: String) {
285306
try {
286-
coderClient.initClientSession(localWizardModel.coderURL.toURL(), pastedToken)
307+
coderClient.initClientSession(localWizardModel.coderURL.toURL(), token)
287308
} catch (e: AuthenticationResponseException) {
288309
logger.error("Could not authenticate on ${localWizardModel.coderURL}. Reason $e")
289310
return
290311
}
291-
312+
appPropertiesService.setValue(CODER_URL_KEY, localWizardModel.coderURL)
313+
appPropertiesService.setValue(SESSION_TOKEN, token)
292314
val cliManager = CoderCLIManager(localWizardModel.coderURL.toURL(), coderClient.buildVersion)
293315

294316

295317
localWizardModel.apply {
296-
token = pastedToken
318+
this.token = token
297319
buildVersion = coderClient.buildVersion
298320
localCliPath = cliManager.localCliPath.toAbsolutePath().toString()
299321
}
@@ -327,11 +349,14 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
327349
}
328350
}
329351

330-
ProgressManager.getInstance().run(authTask)
352+
cs.launch {
353+
ProgressManager.getInstance().run(authTask)
354+
}
331355
triggerWorkspacePolling()
332356
}
333357

334358
private fun askToken(): String? {
359+
BrowserUtil.browse(localWizardModel.coderURL.toURL().withPath("/login?redirect=%2Fcli-auth"))
335360
return invokeAndWaitIfNeeded(ModalityState.any()) {
336361
lateinit var sessionTokenTextField: JBTextField
337362

src/main/resources/messages/CoderGatewayBundle.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ gateway.connector.view.coder.remoteproject.choose.text=Choose IDE and project fo
2222
gateway.connector.recentconnections.title=Recent Coder Workspaces
2323
gateway.connector.recentconnections.new.wizard.button.tooltip=Open a new Coder Workspace
2424
gateway.connector.recentconnections.remove.button.tooltip=Remove from Recent Connections
25-
gateway.connector.recentconnections.terminal.button.tooltip=Open SSH Web Terminal
25+
gateway.connector.recentconnections.terminal.button.tooltip=Open SSH Web Terminal
26+
gateway.connector.coder.connection.provider.title=Connecting to Coder workspace...

0 commit comments

Comments
 (0)