Skip to content

impl: auto-connect to toolbox backend #24

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
Mar 9, 2025
Merged
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
28 changes: 12 additions & 16 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,27 @@ 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) {}

/**
* Immediately send the state to the listener and store for updates.
*/
// override fun addStateListener(consumer: EnvironmentStateConsumer): Boolean {
// // TODO@JB: It would be ideal if we could have the workspace state and
// // the connected state listed separately, since right now the
// // connected state can mask the workspace state.
// // TODO@JB: You can still press connect if the environment is
// // unreachable. Is that expected?
// consumer.consume(status.toRemoteEnvironmentState(serviceLocator))
// return super.addStateListener(consumer)
// }
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
}
}
}
}

override fun onDelete() {
context.cs.launch {
// TODO info and cancel pop-ups only appear on the main page where all environments are listed.
// However, #showSnackbar works on other pages. Until JetBrains fixes this issue we are going to use the snackbar
val shouldDelete = if (wsRawStatus.canStop()) {
context.ui.showOkCancelPopup(
context.i18n.ptrl("Delete running workspace?"),
Expand Down
Loading