Skip to content

impl: workspace status reporting (color and icons) #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Changed

- improved workspace status reporting (icon and colors) when it is failed, stopping, deleting, stopped or when we are
establishing the SSH connection.

## 0.2.2 - 2025-05-21

### Added
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ class CoderRemoteEnvironment(

override fun beforeConnection() {
context.logger.info("Connecting to $id...")
context.cs.launch {
state.update {
wsRawStatus.toSshConnectingEnvState(context)
}
}
isConnected.update { true }
pollJob = pollNetworkMetrics()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import com.jetbrains.toolbox.api.remoteDev.states.CustomRemoteEnvironmentState
import com.jetbrains.toolbox.api.remoteDev.states.EnvironmentStateIcons
import com.jetbrains.toolbox.api.remoteDev.states.StandardRemoteEnvironmentState


private val CircularSpinner: EnvironmentStateIcons = EnvironmentStateIcons.Connecting

/**
* WorkspaceAndAgentStatus represents the combined status of a single agent and
* its workspace (or just the workspace if there are no agents).
Expand Down Expand Up @@ -69,23 +72,34 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
}

private fun getStateColor(context: CoderToolboxContext): StateColor {
return if (ready()) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Active)
else if (unhealthy()) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Unhealthy)
else if (canStart()) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Failed)
else if (pending()) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Activating)
return if (this == FAILED) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.FailedToStart)
else if (this == DELETING) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Deleting)
else if (this == DELETED) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Deleted)
else if (ready()) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Active)
else if (unhealthy()) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Unhealthy)
else if (canStart() || this == STOPPING) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Hibernating)
else if (pending()) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Activating)
else context.envStateColorPalette.getColor(StandardRemoteEnvironmentState.Unreachable)
}

private fun getStateIcon(): EnvironmentStateIcons {
return if (ready() || unhealthy()) EnvironmentStateIcons.Active
else if (canStart()) EnvironmentStateIcons.Hibernated
else if (pending()) EnvironmentStateIcons.Connecting
else if (this == DELETING || this == DELETED) EnvironmentStateIcons.Offline
return if (this == FAILED) EnvironmentStateIcons.Error
else if (pending() || this == DELETING || this == DELETED || this == STOPPING) CircularSpinner
else if (ready() || unhealthy()) EnvironmentStateIcons.Active
else if (canStart()) EnvironmentStateIcons.Offline
else EnvironmentStateIcons.NoIcon
}

fun toSshConnectingEnvState(context: CoderToolboxContext): CustomRemoteEnvironmentState {
val existingState = toRemoteEnvironmentState(context)
return CustomRemoteEnvironmentState(
"SSHing",
existingState.color,
existingState.isReachable,
EnvironmentStateIcons.Connecting
)
}

/**
* Return true if the agent is in a connectable state.
*/
Expand Down
Loading