Skip to content
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

fix: url refresh after log out and log in #67

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### Fixed

- after log out, user is redirected back to the initial log in screen
- after log out, user is redirected back to the initial log in screen
- url on the main page is now refreshed when switching between multiple deployments (via logout/login or URI handling)

## 0.1.1 - 2025-04-03

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class CoderRemoteEnvironment(
while (context.cs.isActive && workspaceStillExists) {
if (wsRawStatus == WorkspaceAndAgentStatus.DELETING || wsRawStatus == WorkspaceAndAgentStatus.DELETED) {
workspaceStillExists = false
context.envPageManager.showPluginEnvironmentsPage()
context.envPageManager.showMainPageWithUrlVisible()
} else {
delay(1.seconds)
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class CoderRemoteProvider(
// On the first load, automatically log in if we can.
private var firstRun = true
private val isInitialized: MutableStateFlow<Boolean> = MutableStateFlow(false)
private var coderHeaderPage = NewEnvironmentPage(context, context.i18n.pnotr(getDeploymentURL()?.first ?: ""))
private var coderHeaderPage =
NewEnvironmentPage(context, context.i18n.pnotr("Coder"), getDeploymentURL()?.first ?: "")
private val linkHandler = CoderProtocolHandler(context, dialogUi, isInitialized)
override val environments: MutableStateFlow<LoadableState<List<RemoteProviderEnvironment>>> = MutableStateFlow(
LoadableState.Value(emptyList())
Expand Down Expand Up @@ -243,7 +244,7 @@ class CoderRemoteProvider(
* this changes it would be nice to have a new spot to show the
* URL.
*/
override val canCreateNewEnvironments: Boolean = false
override val canCreateNewEnvironments: Boolean = true

/**
* Just displays the deployment URL at the moment, but we could use this as
Expand Down Expand Up @@ -273,7 +274,7 @@ class CoderRemoteProvider(
close()
// start initialization with the new settings
[email protected] = restClient
coderHeaderPage = NewEnvironmentPage(context, context.i18n.pnotr(restClient.url.toString()))
coderHeaderPage.refreshUrl(restClient.url.toString())
pollJob = poll(restClient, cli)
}
}
Expand All @@ -287,7 +288,7 @@ class CoderRemoteProvider(
* than using multiple root pages.
*/
private fun goToEnvironmentsPage() {
context.envPageManager.showPluginEnvironmentsPage()
context.envPageManager.showMainPageWithUrlVisible()
}

/**
Expand Down Expand Up @@ -359,6 +360,7 @@ class CoderRemoteProvider(
pollError = null
pollJob?.cancel()
pollJob = poll(client, cli)
coderHeaderPage.refreshUrl(getDeploymentURL()?.first ?: "")
goToEnvironmentsPage()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.coder.toolbox

import com.jetbrains.toolbox.api.remoteDev.ui.EnvironmentUiPageManager

fun EnvironmentUiPageManager.showMainPageWithUrlVisible() {
showPluginEnvironmentsPage(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.coder.toolbox.sdk.CoderRestClient
import com.coder.toolbox.sdk.v2.models.Workspace
import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
import com.coder.toolbox.showMainPageWithUrlVisible
import com.jetbrains.toolbox.api.localization.LocalizableString
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -322,7 +323,7 @@ private suspend fun CoderToolboxContext.showInfoPopup(

private fun CoderToolboxContext.popupPluginMainPage() {
this.ui.showWindow()
this.envPageManager.showPluginEnvironmentsPage(true)
this.envPageManager.showMainPageWithUrlVisible()
}

/**
Expand Down
16 changes: 12 additions & 4 deletions src/main/kotlin/com/coder/toolbox/views/NewEnvironmentPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.coder.toolbox.views

import com.coder.toolbox.CoderToolboxContext
import com.jetbrains.toolbox.api.localization.LocalizableString
import com.jetbrains.toolbox.api.ui.components.LinkField
import com.jetbrains.toolbox.api.ui.components.UiField
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update


/**
Expand All @@ -14,7 +15,14 @@ import kotlinx.coroutines.flow.StateFlow
* For now we just use this to display the deployment URL since we do not
* support creating environments from the plugin.
*/
class NewEnvironmentPage(context: CoderToolboxContext, deploymentURL: LocalizableString) :
CoderPage(context, deploymentURL) {
override val fields: StateFlow<List<UiField>> = MutableStateFlow(emptyList())
class NewEnvironmentPage(private val context: CoderToolboxContext, title: LocalizableString, initialUrl: String) :
CoderPage(context, title) {
override val fields: MutableStateFlow<List<UiField>> =
MutableStateFlow(listOf(LinkField(context.i18n.pnotr(initialUrl), initialUrl)))

fun refreshUrl(url: String) {
fields.update {
listOf(LinkField(context.i18n.pnotr(url), url))
}
}
}
Loading