Skip to content
Merged
Changes from 1 commit
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
Next Next commit
impl: auto-connect to toolbox backend
The auto connect happens only when:
- workspace is running
- the user clicks on one of the environments in the main page
- there isn't already an established connection
  • Loading branch information
fioan89 committed Mar 7, 2025
commit 0ece7ca4fbb1accd51ea66fc79634e89f3be6c2e
13 changes: 12 additions & 1 deletion src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,24 @@ class CoderRemoteEnvironment(
override suspend
fun getContentsView(): EnvironmentContentsView = EnvironmentView(client.url, workspace, agent)

override val connectionRequest: MutableStateFlow<Boolean>? = MutableStateFlow(false)

/**
* Does nothing. In theory, we could do something like start the workspace
* when you click into the workspace, but you would still need to press
* "connect" anyway before the content is populated so there does not seem
* to be much value.
*/
override fun setVisible(visibilityState: EnvironmentVisibilityState) {}
override fun setVisible(visibilityState: EnvironmentVisibilityState) {
if (wsRawStatus.ready() && visibilityState.contentsVisible == true && visibilityState.isBackendConnected == false) {
context.logger.info("Connecting to $id...")
context.cs.launch {
connectionRequest?.update {
true
}
}
}
}

/**
* Immediately send the state to the listener and store for updates.
Expand Down
Loading