@@ -25,11 +25,19 @@ class CoderRemoteEnvironment(
25
25
) : AbstractRemoteProviderEnvironment(observablePropertiesFactory) {
26
26
override fun getId (): String = " ${workspace.name} .${agent.name} "
27
27
override fun getName (): String = " ${workspace.name} .${agent.name} "
28
- private val status = WorkspaceAndAgentStatus .from(workspace, agent)
28
+ private var status = WorkspaceAndAgentStatus .from(workspace, agent)
29
29
30
-
31
- // Map each state to whether a connection can be attempted.
32
- private var state = status.toRemoteEnvironmentState()
30
+ /* *
31
+ * Update the workspace/agent status to the listeners, if it has changed.
32
+ */
33
+ fun update (workspace : Workspace , agent : WorkspaceAgent ) {
34
+ val newStatus = WorkspaceAndAgentStatus .from(workspace, agent)
35
+ if (newStatus != status) {
36
+ status = newStatus
37
+ val state = status.toRemoteEnvironmentState()
38
+ listenerSet.forEach { it.consume(state) }
39
+ }
40
+ }
33
41
34
42
/* *
35
43
* The contents are provided by the SSH view provided by Toolbox, all we
@@ -47,14 +55,26 @@ class CoderRemoteEnvironment(
47
55
override fun setVisible (visibilityState : EnvironmentVisibilityState ) {}
48
56
49
57
/* *
50
- * Immediately send the state to the listener.
51
- *
52
- * Currently we consume the entire workspace list and are not updating
53
- * individual workspaces, so the state here is static and the listener is
54
- * only used once.
58
+ * Immediately send the state to the listener and store for updates.
55
59
*/
56
60
override fun addStateListener (consumer : EnvironmentStateConsumer ): Boolean {
57
- consumer.consume(state )
61
+ consumer.consume(status.toRemoteEnvironmentState() )
58
62
return super .addStateListener(consumer)
59
63
}
64
+
65
+ /* *
66
+ * An environment is equal if it has the same ID.
67
+ */
68
+ override fun equals (other : Any? ): Boolean {
69
+ if (other == null ) return false
70
+ if (this == = other) return true // Note the triple ===
71
+ if (other !is CoderRemoteEnvironment ) return false
72
+ if (getId() != other.getId()) return false
73
+ return true
74
+ }
75
+
76
+ /* *
77
+ * Companion to equals, for sets.
78
+ */
79
+ override fun hashCode (): Int = getId().hashCode()
60
80
}
0 commit comments