From d55363674e62649b06b1eb7717b83ad345db486c Mon Sep 17 00:00:00 2001 From: Faur Ioan-Aurel Date: Sat, 8 Mar 2025 00:14:36 +0200 Subject: [PATCH] fix: env. action buttons state - the action buttons like (start/stop/update) did not change visibility or enabled property when the workspace changed its running status - this fix regenerates the list of available actions in order to force a re-draw in UI when workspace status changes - resolves #12 --- .../coder/toolbox/CoderRemoteEnvironment.kt | 78 ++++++++++--------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt b/src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt index 5aa09aa..4421094 100644 --- a/src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt +++ b/src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt @@ -17,7 +17,6 @@ import com.jetbrains.toolbox.api.remoteDev.states.RemoteEnvironmentState import com.jetbrains.toolbox.api.ui.actions.ActionDescription import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.isActive import kotlinx.coroutines.launch @@ -44,46 +43,46 @@ class CoderRemoteEnvironment( override val description: MutableStateFlow = MutableStateFlow(EnvironmentDescription.General(context.i18n.pnotr(workspace.templateDisplayName))) - override val actionsList: StateFlow> = MutableStateFlow( - listOf( - Action(context.i18n.ptrl("Open web terminal")) { - context.cs.launch { - BrowserUtil.browse(client.url.withPath("/${workspace.ownerName}/$name/terminal").toString()) { - context.ui.showErrorInfoPopup(it) - } + override val actionsList: MutableStateFlow> = MutableStateFlow(getAvailableActions()) + + private fun getAvailableActions(): List = listOf( + Action(context.i18n.ptrl("Open web terminal")) { + context.cs.launch { + BrowserUtil.browse(client.url.withPath("/${workspace.ownerName}/$name/terminal").toString()) { + context.ui.showErrorInfoPopup(it) } - }, - Action(context.i18n.ptrl("Open in dashboard")) { - context.cs.launch { - BrowserUtil.browse(client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString()) { - context.ui.showErrorInfoPopup(it) - } + } + }, + Action(context.i18n.ptrl("Open in dashboard")) { + context.cs.launch { + BrowserUtil.browse(client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString()) { + context.ui.showErrorInfoPopup(it) } - }, + } + }, - Action(context.i18n.ptrl("View template")) { - context.cs.launch { - BrowserUtil.browse(client.url.withPath("/templates/${workspace.templateName}").toString()) { - context.ui.showErrorInfoPopup(it) - } + Action(context.i18n.ptrl("View template")) { + context.cs.launch { + BrowserUtil.browse(client.url.withPath("/templates/${workspace.templateName}").toString()) { + context.ui.showErrorInfoPopup(it) } - }, - Action(context.i18n.ptrl("Start"), enabled = { wsRawStatus.canStart() }) { - val build = client.startWorkspace(workspace) - workspace = workspace.copy(latestBuild = build) - update(workspace, agent) - }, - Action(context.i18n.ptrl("Stop"), enabled = { wsRawStatus.canStop() }) { - val build = client.stopWorkspace(workspace) - workspace = workspace.copy(latestBuild = build) - update(workspace, agent) - }, - Action(context.i18n.ptrl("Update"), enabled = { workspace.outdated }) { - val build = client.updateWorkspace(workspace) - workspace = workspace.copy(latestBuild = build) - update(workspace, agent) - }) - ) + } + }, + Action(context.i18n.ptrl("Start"), enabled = { wsRawStatus.canStart() }) { + val build = client.startWorkspace(workspace) + workspace = workspace.copy(latestBuild = build) + update(workspace, agent) + }, + Action(context.i18n.ptrl("Stop"), enabled = { wsRawStatus.canStop() }) { + val build = client.stopWorkspace(workspace) + workspace = workspace.copy(latestBuild = build) + update(workspace, agent) + }, + Action(context.i18n.ptrl("Update"), enabled = { workspace.outdated }) { + val build = client.updateWorkspace(workspace) + workspace = workspace.copy(latestBuild = build) + update(workspace, agent) + }) /** * Update the workspace/agent status to the listeners, if it has changed. @@ -92,6 +91,11 @@ class CoderRemoteEnvironment( this.workspace = workspace this.agent = agent wsRawStatus = WorkspaceAndAgentStatus.from(workspace, agent) + // we have to regenerate the action list in order to force a redraw + // because the actions don't have a state flow on the enabled property + actionsList.update { + getAvailableActions() + } context.cs.launch { state.update { wsRawStatus.toRemoteEnvironmentState(context) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy