@@ -17,7 +17,6 @@ import com.jetbrains.toolbox.api.remoteDev.states.RemoteEnvironmentState
1717import com.jetbrains.toolbox.api.ui.actions.ActionDescription
1818import kotlinx.coroutines.delay
1919import kotlinx.coroutines.flow.MutableStateFlow
20- import kotlinx.coroutines.flow.StateFlow
2120import kotlinx.coroutines.flow.update
2221import kotlinx.coroutines.isActive
2322import kotlinx.coroutines.launch
@@ -44,46 +43,46 @@ class CoderRemoteEnvironment(
4443 override val description: MutableStateFlow <EnvironmentDescription > =
4544 MutableStateFlow (EnvironmentDescription .General (context.i18n.pnotr(workspace.templateDisplayName)))
4645
47- override val actionsList: StateFlow <List <ActionDescription >> = MutableStateFlow (
48- listOf (
49- Action (context.i18n.ptrl( " Open web terminal " )) {
50- context.cs.launch {
51- BrowserUtil .browse(client.url.withPath( " / ${workspace.ownerName} / $name /terminal " ).toString()) {
52- context.ui.showErrorInfoPopup(it)
53- }
46+ override val actionsList: MutableStateFlow <List <ActionDescription >> = MutableStateFlow (getAvailableActions())
47+
48+ private fun getAvailableActions (): List < ActionDescription > = listOf (
49+ Action ( context.i18n.ptrl( " Open web terminal " )) {
50+ context.cs.launch {
51+ BrowserUtil .browse(client.url.withPath( " / ${workspace.ownerName} / $name /terminal " ).toString()) {
52+ context.ui.showErrorInfoPopup(it)
5453 }
55- },
56- Action (context.i18n.ptrl( " Open in dashboard " )) {
57- context.cs.launch {
58- BrowserUtil .browse(client.url.withPath( " /@ ${workspace.ownerName} / ${workspace.name} " ).toString()) {
59- context.ui.showErrorInfoPopup(it)
60- }
54+ }
55+ },
56+ Action ( context.i18n.ptrl( " Open in dashboard " )) {
57+ context.cs.launch {
58+ BrowserUtil .browse(client.url.withPath( " /@ ${workspace.ownerName} / ${workspace.name} " ).toString()) {
59+ context.ui.showErrorInfoPopup(it)
6160 }
62- },
61+ }
62+ },
6363
64- Action (context.i18n.ptrl(" View template" )) {
65- context.cs.launch {
66- BrowserUtil .browse(client.url.withPath(" /templates/${workspace.templateName} " ).toString()) {
67- context.ui.showErrorInfoPopup(it)
68- }
64+ Action (context.i18n.ptrl(" View template" )) {
65+ context.cs.launch {
66+ BrowserUtil .browse(client.url.withPath(" /templates/${workspace.templateName} " ).toString()) {
67+ context.ui.showErrorInfoPopup(it)
6968 }
70- },
71- Action (context.i18n.ptrl( " Start " ), enabled = { wsRawStatus.canStart() }) {
72- val build = client.startWorkspace(workspace)
73- workspace = workspace.copy(latestBuild = build )
74- update( workspace, agent )
75- },
76- Action (context.i18n.ptrl( " Stop " ), enabled = { wsRawStatus.canStop() }) {
77- val build = client.stopWorkspace(workspace)
78- workspace = workspace.copy(latestBuild = build )
79- update( workspace, agent )
80- },
81- Action (context.i18n.ptrl( " Update " ), enabled = { workspace.outdated }) {
82- val build = client.updateWorkspace( workspace)
83- workspace = workspace.copy(latestBuild = build )
84- update( workspace, agent )
85- } )
86- )
69+ }
70+ },
71+ Action (context.i18n.ptrl( " Start " ), enabled = { wsRawStatus.canStart() }) {
72+ val build = client.startWorkspace(workspace )
73+ workspace = workspace.copy(latestBuild = build )
74+ update(workspace, agent)
75+ },
76+ Action (context.i18n.ptrl( " Stop " ), enabled = { wsRawStatus.canStop() }) {
77+ val build = client.stopWorkspace(workspace )
78+ workspace = workspace.copy(latestBuild = build )
79+ update(workspace, agent)
80+ },
81+ Action (context.i18n.ptrl( " Update " ), enabled = { workspace.outdated }) {
82+ val build = client.updateWorkspace(workspace )
83+ workspace = workspace.copy(latestBuild = build )
84+ update(workspace, agent )
85+ } )
8786
8887 /* *
8988 * Update the workspace/agent status to the listeners, if it has changed.
@@ -92,6 +91,11 @@ class CoderRemoteEnvironment(
9291 this .workspace = workspace
9392 this .agent = agent
9493 wsRawStatus = WorkspaceAndAgentStatus .from(workspace, agent)
94+ // we have to regenerate the action list in order to force a redraw
95+ // because the actions don't have a state flow on the enabled property
96+ actionsList.update {
97+ getAvailableActions()
98+ }
9599 context.cs.launch {
96100 state.update {
97101 wsRawStatus.toRemoteEnvironmentState(context)
0 commit comments