@@ -23,6 +23,7 @@ import kotlinx.coroutines.CoroutineScope
23
23
import kotlinx.coroutines.delay
24
24
import kotlinx.coroutines.flow.MutableStateFlow
25
25
import kotlinx.coroutines.flow.StateFlow
26
+ import kotlinx.coroutines.flow.update
26
27
import kotlinx.coroutines.isActive
27
28
import kotlinx.coroutines.launch
28
29
import kotlinx.coroutines.withTimeout
@@ -41,16 +42,16 @@ class CoderRemoteEnvironment(
41
42
private var agent : WorkspaceAgent ,
42
43
private var cs : CoroutineScope ,
43
44
) : RemoteProviderEnvironment(" ${workspace.name} .${agent.name} " ) {
44
- private var status = WorkspaceAndAgentStatus .from(workspace, agent)
45
+ private var wsRawStatus = WorkspaceAndAgentStatus .from(workspace, agent)
45
46
46
47
private val ui: ToolboxUi = serviceLocator.getService(ToolboxUi ::class .java)
47
48
private val i18n = serviceLocator.getService(LocalizableStringFactory ::class .java)
48
49
49
50
override var name: String = " ${workspace.name} .${agent.name} "
50
- override val state: StateFlow <RemoteEnvironmentState >
51
- get() = TODO ( " Not yet implemented " )
52
- override val description: StateFlow <EnvironmentDescription >
53
- get() = TODO ( " Not yet implemented " )
51
+ override val state: MutableStateFlow <RemoteEnvironmentState > =
52
+ MutableStateFlow (wsRawStatus.toRemoteEnvironmentState(serviceLocator) )
53
+ override val description: MutableStateFlow <EnvironmentDescription > =
54
+ MutableStateFlow ( EnvironmentDescription . General (i18n.pnotr(workspace.templateName)) )
54
55
55
56
override val actionsList: StateFlow <List <ActionDescription >> = MutableStateFlow (
56
57
listOf (
@@ -76,12 +77,12 @@ class CoderRemoteEnvironment(
76
77
}
77
78
}
78
79
},
79
- Action (i18n.ptrl(" Start" ), enabled = { status .canStart() }) {
80
+ Action (i18n.ptrl(" Start" ), enabled = { wsRawStatus .canStart() }) {
80
81
val build = client.startWorkspace(workspace)
81
82
workspace = workspace.copy(latestBuild = build)
82
83
update(workspace, agent)
83
84
},
84
- Action (i18n.ptrl(" Stop" ), enabled = { status .canStop() }) {
85
+ Action (i18n.ptrl(" Stop" ), enabled = { wsRawStatus .canStop() }) {
85
86
val build = client.stopWorkspace(workspace)
86
87
workspace = workspace.copy(latestBuild = build)
87
88
update(workspace, agent)
@@ -99,11 +100,11 @@ class CoderRemoteEnvironment(
99
100
fun update (workspace : Workspace , agent : WorkspaceAgent ) {
100
101
this .workspace = workspace
101
102
this .agent = agent
102
- val newStatus = WorkspaceAndAgentStatus .from(workspace, agent)
103
- if (newStatus != status) {
104
- status = newStatus
105
- val state = status .toRemoteEnvironmentState(serviceLocator)
106
- // listenerSet.forEach { it.consume(state) }
103
+ wsRawStatus = WorkspaceAndAgentStatus .from(workspace, agent)
104
+ cs.launch {
105
+ state.update {
106
+ wsRawStatus .toRemoteEnvironmentState(serviceLocator)
107
+ }
107
108
}
108
109
}
109
110
@@ -139,7 +140,7 @@ class CoderRemoteEnvironment(
139
140
cs.launch {
140
141
// TODO info and cancel pop-ups only appear on the main page where all environments are listed.
141
142
// However, #showSnackbar works on other pages. Until JetBrains fixes this issue we are going to use the snackbar
142
- val shouldDelete = if (status .canStop()) {
143
+ val shouldDelete = if (wsRawStatus .canStop()) {
143
144
ui.showOkCancelPopup(
144
145
i18n.ptrl(" Delete running workspace?" ),
145
146
i18n.ptrl(" Workspace will be closed and all the information in this workspace will be lost, including all files, unsaved changes and historical." ),
@@ -161,7 +162,7 @@ class CoderRemoteEnvironment(
161
162
withTimeout(5 .minutes) {
162
163
var workspaceStillExists = true
163
164
while (cs.isActive && workspaceStillExists) {
164
- if (status == WorkspaceAndAgentStatus .DELETING || status == WorkspaceAndAgentStatus .DELETED ) {
165
+ if (wsRawStatus == WorkspaceAndAgentStatus .DELETING || wsRawStatus == WorkspaceAndAgentStatus .DELETED ) {
165
166
workspaceStillExists = false
166
167
serviceLocator.getService(EnvironmentUiPageManager ::class .java)
167
168
.showPluginEnvironmentsPage()
0 commit comments