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