Skip to content

Commit b031c65

Browse files
committed
fix: connection status rendering
- the connection status was unreadable due to the background and foreground colors used. The latest Toolbox version comes with standard color palettes that change based on the theme and environment state. - plus some small extra refactorings that reduce the number of constructor parameters and rely on the service locator
1 parent 5973b0d commit b031c65

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
88
import com.coder.toolbox.util.withPath
99
import com.coder.toolbox.views.Action
1010
import com.coder.toolbox.views.EnvironmentView
11+
import com.jetbrains.toolbox.api.core.ServiceLocator
1112
import com.jetbrains.toolbox.api.remoteDev.AbstractRemoteProviderEnvironment
1213
import com.jetbrains.toolbox.api.remoteDev.EnvironmentVisibilityState
1314
import com.jetbrains.toolbox.api.remoteDev.environments.EnvironmentContentsView
@@ -23,12 +24,13 @@ import java.util.concurrent.CompletableFuture
2324
* Used in the environment list view.
2425
*/
2526
class CoderRemoteEnvironment(
27+
private val serviceLocator: ServiceLocator,
2628
private val client: CoderRestClient,
2729
private var workspace: Workspace,
2830
private var agent: WorkspaceAgent,
2931
private var cs: CoroutineScope,
30-
private val ui: ToolboxUi,
3132
) : AbstractRemoteProviderEnvironment() {
33+
private val ui: ToolboxUi = serviceLocator.getService(ToolboxUi::class.java)
3234
override fun getId(): String = "${workspace.name}.${agent.name}"
3335
override fun getName(): String = "${workspace.name}.${agent.name}"
3436
private var status = WorkspaceAndAgentStatus.from(workspace, agent)
@@ -93,7 +95,7 @@ class CoderRemoteEnvironment(
9395
val newStatus = WorkspaceAndAgentStatus.from(workspace, agent)
9496
if (newStatus != status) {
9597
status = newStatus
96-
val state = status.toRemoteEnvironmentState()
98+
val state = status.toRemoteEnvironmentState(serviceLocator)
9799
listenerSet.forEach { it.consume(state) }
98100
}
99101
}
@@ -122,7 +124,7 @@ class CoderRemoteEnvironment(
122124
// connected state can mask the workspace state.
123125
// TODO@JB: You can still press connect if the environment is
124126
// unreachable. Is that expected?
125-
consumer.consume(status.toRemoteEnvironmentState())
127+
consumer.consume(status.toRemoteEnvironmentState(serviceLocator))
126128
return super.addStateListener(consumer)
127129
}
128130

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class CoderRemoteProvider(
100100
it.name
101101
}?.map { agent ->
102102
// If we have an environment already, update that.
103-
val env = CoderRemoteEnvironment(client, ws, agent, coroutineScope, ui)
103+
val env = CoderRemoteEnvironment(serviceLocator, client, ws, agent, coroutineScope)
104104
lastEnvironments?.firstOrNull { it == env }?.let {
105105
it.update(ws, agent)
106106
it

src/main/kotlin/com/coder/toolbox/models/WorkspaceAndAgentStatus.kt

+16-15
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
55
import com.coder.toolbox.sdk.v2.models.WorkspaceAgentLifecycleState
66
import com.coder.toolbox.sdk.v2.models.WorkspaceAgentStatus
77
import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
8-
import com.jetbrains.toolbox.api.core.ui.color.Color
8+
import com.jetbrains.toolbox.api.core.ServiceLocator
99
import com.jetbrains.toolbox.api.core.ui.color.StateColor
10-
import com.jetbrains.toolbox.api.core.ui.color.ThemeColor
1110
import com.jetbrains.toolbox.api.remoteDev.states.CustomRemoteEnvironmentState
11+
import com.jetbrains.toolbox.api.remoteDev.states.EnvironmentStateColorPalette
12+
import com.jetbrains.toolbox.api.remoteDev.states.StandardRemoteEnvironmentState
1213

1314
/**
1415
* WorkspaceAndAgentStatus represents the combined status of a single agent and
@@ -57,27 +58,27 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
5758
* Note that a reachable environment will always display "connected" or
5859
* "disconnected" regardless of the label we give that status.
5960
*/
60-
fun toRemoteEnvironmentState(): CustomRemoteEnvironmentState {
61-
// Use comments; no named arguments for non-Kotlin functions.
62-
// TODO@JB: Is there a set of default colors we could use?
61+
fun toRemoteEnvironmentState(serviceLocator: ServiceLocator): CustomRemoteEnvironmentState {
62+
val stateColor = getStateColor(serviceLocator)
6363
return CustomRemoteEnvironmentState(
6464
label,
65-
StateColor(
66-
ThemeColor(
67-
Color(0.407f, 0.439f, 0.502f, 1.0f), // lightThemeColor
68-
Color(0.784f, 0.784f, 0.784f, 0.784f), // darkThemeColor
69-
),
70-
ThemeColor(
71-
Color(0.878f, 0.878f, 0.941f, 0.102f), // darkThemeBackgroundColor
72-
Color(0.878f, 0.878f, 0.961f, 0.980f), // lightThemeBackgroundColor
73-
)
74-
),
65+
stateColor,
7566
ready(), // reachable
7667
// TODO@JB: How does this work? Would like a spinner for pending states.
7768
null, // iconId
7869
)
7970
}
8071

72+
private fun getStateColor(serviceLocator: ServiceLocator): StateColor {
73+
val colorPalette = serviceLocator.getService(EnvironmentStateColorPalette::class.java)
74+
75+
76+
return if (ready()) colorPalette.getColor(StandardRemoteEnvironmentState.Active)
77+
else if (canStart()) colorPalette.getColor(StandardRemoteEnvironmentState.Failed)
78+
else if (pending()) colorPalette.getColor(StandardRemoteEnvironmentState.Activating)
79+
else colorPalette.getColor(StandardRemoteEnvironmentState.Unreachable)
80+
}
81+
8182
/**
8283
* Return true if the agent is in a connectable state.
8384
*/

0 commit comments

Comments
 (0)