Skip to content

Commit 0ece7ca

Browse files
committed
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
1 parent 8f1d3a3 commit 0ece7ca

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,24 @@ class CoderRemoteEnvironment(
106106
override suspend
107107
fun getContentsView(): EnvironmentContentsView = EnvironmentView(client.url, workspace, agent)
108108

109+
override val connectionRequest: MutableStateFlow<Boolean>? = MutableStateFlow(false)
110+
109111
/**
110112
* Does nothing. In theory, we could do something like start the workspace
111113
* when you click into the workspace, but you would still need to press
112114
* "connect" anyway before the content is populated so there does not seem
113115
* to be much value.
114116
*/
115-
override fun setVisible(visibilityState: EnvironmentVisibilityState) {}
117+
override fun setVisible(visibilityState: EnvironmentVisibilityState) {
118+
if (wsRawStatus.ready() && visibilityState.contentsVisible == true && visibilityState.isBackendConnected == false) {
119+
context.logger.info("Connecting to $id...")
120+
context.cs.launch {
121+
connectionRequest?.update {
122+
true
123+
}
124+
}
125+
}
126+
}
116127

117128
/**
118129
* Immediately send the state to the listener and store for updates.

0 commit comments

Comments
 (0)