@@ -17,7 +17,6 @@ import com.jetbrains.toolbox.api.remoteDev.states.RemoteEnvironmentState
17
17
import com.jetbrains.toolbox.api.ui.actions.ActionDescription
18
18
import kotlinx.coroutines.delay
19
19
import kotlinx.coroutines.flow.MutableStateFlow
20
- import kotlinx.coroutines.flow.StateFlow
21
20
import kotlinx.coroutines.flow.update
22
21
import kotlinx.coroutines.isActive
23
22
import kotlinx.coroutines.launch
@@ -44,46 +43,46 @@ class CoderRemoteEnvironment(
44
43
override val description: MutableStateFlow <EnvironmentDescription > =
45
44
MutableStateFlow (EnvironmentDescription .General (context.i18n.pnotr(workspace.templateDisplayName)))
46
45
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)
54
53
}
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)
61
60
}
62
- },
61
+ }
62
+ },
63
63
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)
69
68
}
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
+ } )
87
86
88
87
/* *
89
88
* Update the workspace/agent status to the listeners, if it has changed.
@@ -92,6 +91,11 @@ class CoderRemoteEnvironment(
92
91
this .workspace = workspace
93
92
this .agent = agent
94
93
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
+ }
95
99
context.cs.launch {
96
100
state.update {
97
101
wsRawStatus.toRemoteEnvironmentState(context)
0 commit comments