@@ -23,6 +23,7 @@ import kotlinx.coroutines.CoroutineScope
2323import kotlinx.coroutines.delay
2424import kotlinx.coroutines.flow.MutableStateFlow
2525import kotlinx.coroutines.flow.StateFlow
26+ import kotlinx.coroutines.flow.update
2627import kotlinx.coroutines.isActive
2728import kotlinx.coroutines.launch
2829import kotlinx.coroutines.withTimeout
@@ -41,16 +42,16 @@ class CoderRemoteEnvironment(
4142 private var agent : WorkspaceAgent ,
4243 private var cs : CoroutineScope ,
4344) : RemoteProviderEnvironment(" ${workspace.name} .${agent.name} " ) {
44- private var status = WorkspaceAndAgentStatus .from(workspace, agent)
45+ private var wsRawStatus = WorkspaceAndAgentStatus .from(workspace, agent)
4546
4647 private val ui: ToolboxUi = serviceLocator.getService(ToolboxUi ::class .java)
4748 private val i18n = serviceLocator.getService(LocalizableStringFactory ::class .java)
4849
4950 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)) )
5455
5556 override val actionsList: StateFlow <List <ActionDescription >> = MutableStateFlow (
5657 listOf (
@@ -76,12 +77,12 @@ class CoderRemoteEnvironment(
7677 }
7778 }
7879 },
79- Action (i18n.ptrl(" Start" ), enabled = { status .canStart() }) {
80+ Action (i18n.ptrl(" Start" ), enabled = { wsRawStatus .canStart() }) {
8081 val build = client.startWorkspace(workspace)
8182 workspace = workspace.copy(latestBuild = build)
8283 update(workspace, agent)
8384 },
84- Action (i18n.ptrl(" Stop" ), enabled = { status .canStop() }) {
85+ Action (i18n.ptrl(" Stop" ), enabled = { wsRawStatus .canStop() }) {
8586 val build = client.stopWorkspace(workspace)
8687 workspace = workspace.copy(latestBuild = build)
8788 update(workspace, agent)
@@ -99,11 +100,11 @@ class CoderRemoteEnvironment(
99100 fun update (workspace : Workspace , agent : WorkspaceAgent ) {
100101 this .workspace = workspace
101102 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+ }
107108 }
108109 }
109110
@@ -139,7 +140,7 @@ class CoderRemoteEnvironment(
139140 cs.launch {
140141 // TODO info and cancel pop-ups only appear on the main page where all environments are listed.
141142 // 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()) {
143144 ui.showOkCancelPopup(
144145 i18n.ptrl(" Delete running workspace?" ),
145146 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(
161162 withTimeout(5 .minutes) {
162163 var workspaceStillExists = true
163164 while (cs.isActive && workspaceStillExists) {
164- if (status == WorkspaceAndAgentStatus .DELETING || status == WorkspaceAndAgentStatus .DELETED ) {
165+ if (wsRawStatus == WorkspaceAndAgentStatus .DELETING || wsRawStatus == WorkspaceAndAgentStatus .DELETED ) {
165166 workspaceStillExists = false
166167 serviceLocator.getService(EnvironmentUiPageManager ::class .java)
167168 .showPluginEnvironmentsPage()
0 commit comments