Skip to content

Commit 6aeb88d

Browse files
committed
make the link just start the workspace
1 parent c704fa5 commit 6aeb88d

File tree

1 file changed

+22
-80
lines changed

1 file changed

+22
-80
lines changed

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

Lines changed: 22 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.intellij.openapi.ui.panel.ComponentPanelBuilder
3333
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
3434
import com.intellij.ui.AnimatedIcon
3535
import com.intellij.ui.DocumentAdapter
36+
import com.intellij.ui.JBColor
3637
import com.intellij.ui.SearchTextField
3738
import com.intellij.ui.components.ActionLink
3839
import com.intellij.ui.components.JBScrollPane
@@ -57,6 +58,7 @@ import kotlinx.coroutines.delay
5758
import kotlinx.coroutines.isActive
5859
import kotlinx.coroutines.launch
5960
import kotlinx.coroutines.withContext
61+
import java.awt.Color
6062
import java.awt.Component
6163
import java.awt.Dimension
6264
import java.util.Locale
@@ -194,26 +196,24 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
194196
TopGap.MEDIUM
195197
}
196198
row {
197-
// icon(status.first).applyToComponent {
198-
// foreground = status.second
199-
// }.align(AlignX.LEFT).gap(RightGap.SMALL).applyToComponent {
200-
// size = Dimension(JBUI.scale(16), JBUI.scale(16))
201-
// }
202199
label(workspaceName).applyToComponent {
203200
font = JBFont.h3().asBold()
204201
}.align(AlignX.LEFT).gap(RightGap.SMALL)
205202
label(deploymentURL).applyToComponent {
206203
foreground = UIUtil.getContextHelpForeground()
207204
font = ComponentPanelBuilder.getCommentFont(font)
208205
}
209-
label("").resizableColumn().align(AlignX.FILL)
210-
actionButton(
211-
object : DumbAwareAction(
212-
CoderGatewayBundle.message("gateway.connector.recent-connections.start.button.tooltip"),
213-
"",
214-
CoderIcons.RUN,
215-
) {
216-
override fun actionPerformed(e: AnActionEvent) {
206+
label("").resizableColumn().align(AlignX.FILL) }.topGap(gap)
207+
208+
row { label("Select a project to launch.") }
209+
connections.forEach { workspaceProjectIDE ->
210+
211+
val actionLink = ActionLink(workspaceProjectIDE.projectPathDisplay) {
212+
if (workspaceWithAgent?.workspace?.latestBuild?.status == WorkspaceStatus.RUNNING && workspaceWithAgent.status == WorkspaceAndAgentStatus.READY) {
213+
CoderRemoteConnectionHandle().connect { workspaceProjectIDE }
214+
GatewayUI.getInstance().reset()
215+
} else {
216+
// Start the workspace
217217
withoutNull(workspaceWithAgent?.workspace, deployment?.client) { workspace, client ->
218218
jobs[workspace.id]?.cancel()
219219
jobs[workspace.id] =
@@ -227,78 +227,20 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
227227
}
228228
}
229229
}
230+
cs.launch {
231+
jobs[workspace.id]?.join()
232+
CoderRemoteConnectionHandle().connect { workspaceProjectIDE }
233+
GatewayUI.getInstance().reset()
234+
}
230235
}
236+
231237
}
232-
},
233-
).applyToComponent {
234-
isEnabled =
235-
listOf(
236-
WorkspaceStatus.STOPPED,
237-
WorkspaceStatus.FAILED,
238-
).contains(workspaceWithAgent?.workspace?.latestBuild?.status)
239-
}
240-
.gap(RightGap.SMALL)
241-
actionButton(
242-
object : DumbAwareAction(
243-
CoderGatewayBundle.message("gateway.connector.recent-connections.stop.button.tooltip"),
244-
"",
245-
CoderIcons.STOP,
246-
) {
247-
override fun actionPerformed(e: AnActionEvent) {
248-
withoutNull(workspaceWithAgent?.workspace, deployment?.client) { workspace, client ->
249-
jobs[workspace.id]?.cancel()
250-
jobs[workspace.id] =
251-
cs.launch(ModalityState.current().asContextElement()) {
252-
withContext(Dispatchers.IO) {
253-
try {
254-
client.stopWorkspace(workspace)
255-
fetchWorkspaces()
256-
} catch (e: Exception) {
257-
logger.error("Could not stop workspace ${workspace.name}", e)
258-
}
259-
}
260-
}
261-
}
262-
}
263-
},
264-
).applyToComponent { isEnabled = workspaceWithAgent?.workspace?.latestBuild?.status == WorkspaceStatus.RUNNING }
265-
.gap(RightGap.SMALL)
266-
actionButton(
267-
object : DumbAwareAction(
268-
CoderGatewayBundle.message("gateway.connector.recent-connections.terminal.button.tooltip"),
269-
"",
270-
CoderIcons.OPEN_TERMINAL,
271-
) {
272-
override fun actionPerformed(e: AnActionEvent) {
273-
withoutNull(workspaceWithAgent, deployment?.client) { ws, client ->
274-
val link = client.url.withPath("/me/${ws.name}/terminal")
275-
BrowserUtil.browse(link.toString())
276-
}
277-
}
278-
},
279-
)
280-
}.topGap(gap)
281-
if (deploymentError == null || showError) {
282-
row {
283-
// There must be a way to make this properly wrap?
284-
if (status.first == CoderIcons.PENDING) {
285-
icon(AnimatedIcon.Default())
286238
}
287-
label("<html><body style='width:350px;'>" + status.third + "</html>").applyToComponent {
288-
foreground = status.second
289-
}
290-
}
291-
}
292-
if (workspaceWithAgent?.workspace?.latestBuild?.status == WorkspaceStatus.RUNNING && workspaceWithAgent.status == WorkspaceAndAgentStatus.READY) {
293-
row { label("Select a project to launch.") }
294-
connections.forEach { workspaceProjectIDE ->
239+
295240
row {
296241
icon(workspaceProjectIDE.ideProduct.icon)
297242
cell(
298-
ActionLink(workspaceProjectIDE.projectPathDisplay) {
299-
CoderRemoteConnectionHandle().connect { workspaceProjectIDE }
300-
GatewayUI.getInstance().reset()
301-
},
243+
actionLink,
302244
)
303245
label("").resizableColumn().align(AlignX.FILL)
304246
label(workspaceProjectIDE.ideName).applyToComponent {
@@ -323,7 +265,7 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
323265
)
324266
}
325267
}
326-
}
268+
327269
}
328270
}
329271
}.apply {

0 commit comments

Comments
 (0)