Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

impl: support uri handling#35

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fioan89 merged 17 commits intomainfromimpl-support-for-uri
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
ee07b8d
impl: support uri handling (1)
fioan89Mar 13, 2025
ba78918
chore: update comment
fioan89Mar 14, 2025
0661a8d
refactor: text progress indicator can be replaced by an actual logger
fioan89Mar 14, 2025
5b7f3e9
impl: support for uri handling (2)
fioan89Mar 14, 2025
3108f7d
impl: resilience when `url` query parameter is missing
fioan89Mar 14, 2025
0403ee2
impl: rework the handling of missing token code
fioan89Mar 17, 2025
86532d4
impl: show error dialog when workspace name was not provided
fioan89Mar 17, 2025
56ed322
impl: wait for workspace to be running
fioan89Mar 17, 2025
0b49bcb
impl: support for ClientHelper
fioan89Mar 18, 2025
894bcab
fix: URI handling race condition when creating polling jobs
fioan89Mar 18, 2025
21f012d
impl: install ide to the workspace if product code and build number w…
fioan89Mar 18, 2025
00f9ab3
fix: wait for IDE to be installed and then connect
fioan89Mar 19, 2025
b67585f
fix: use launch/join instead of runBlocking
fioan89Mar 20, 2025
9f096cf
impl: uri support for specifying a project to open
fioan89Mar 20, 2025
2cd3565
fix: handle the uri when we don't do autologin
fioan89Mar 20, 2025
d3a483e
refactor: proper constant name to reflect the value
fioan89Mar 21, 2025
20441c8
chore: fix typo in property name
fioan89Mar 21, 2025
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
39 changes: 24 additions & 15 deletionssrc/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,9 +7,8 @@ import com.coder.toolbox.services.CoderSecretsService
import com.coder.toolbox.services.CoderSettingsService
import com.coder.toolbox.settings.CoderSettings
import com.coder.toolbox.settings.Source
import com.coder.toolbox.util.CoderProtocolHandler
import com.coder.toolbox.util.DialogUi
import com.coder.toolbox.util.LinkHandler
import com.coder.toolbox.util.toQueryParameters
import com.coder.toolbox.views.Action
import com.coder.toolbox.views.CoderSettingsPage
import com.coder.toolbox.views.ConnectPage
Expand DownExpand Up@@ -53,7 +52,6 @@ class CoderRemoteProvider(
private val secrets: CoderSecretsService = CoderSecretsService(context.secretsStore)
private val settingsPage: CoderSettingsPage = CoderSettingsPage(context, settingsService)
private val dialogUi = DialogUi(context, settings)
private val linkHandler = LinkHandler(context, settings, httpClient, dialogUi)

// The REST client, if we are signed in
private var client: CoderRestClient? = null
Expand All@@ -65,7 +63,9 @@ 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 val linkHandler = CoderProtocolHandler(context, settings, httpClient, dialogUi, isInitialized)
override val environments: MutableStateFlow<LoadableState<List<RemoteProviderEnvironment>>> = MutableStateFlow(
LoadableState.Value(emptyList())
)
Expand DownExpand Up@@ -122,6 +122,12 @@ class CoderRemoteProvider(
environments.update {
LoadableState.Value(resolvedEnvironments.toList())
}
if (isInitialized.value == false) {
context.logger.info("Environments for ${client.url} are now initialized")
isInitialized.update {
true
}
}

lastEnvironments = resolvedEnvironments
} catch (_: CancellationException) {
Expand DownExpand Up@@ -171,14 +177,14 @@ class CoderRemoteProvider(
/**
* Cancel polling and clear the client and environments.
*
* Called as part of our own logout but it is unclear where it is called by
* Toolbox. Maybe on uninstall?
* Also called as part of our own logout.
*/
override fun close() {
pollJob?.cancel()
client = null
client?.close()
lastEnvironments = null
environments.value = LoadableState.Value(emptyList())
isInitialized.update { false }
}

override val svgIcon: SvgIcon =
Expand DownExpand Up@@ -213,8 +219,7 @@ class CoderRemoteProvider(
* Just displays the deployment URL at the moment, but we could use this as
* a form for creating new environments.
*/
override fun getNewEnvironmentUiPage(): UiPage =
NewEnvironmentPage(context, context.i18n.pnotr(getDeploymentURL()?.first ?: ""))
override fun getNewEnvironmentUiPage(): UiPage = coderHeaderPage

/**
* We always show a list of environments.
Expand All@@ -233,11 +238,13 @@ class CoderRemoteProvider(
* Handle incoming links (like from the dashboard).
*/
override suspend fun handleUri(uri: URI) {
val params = uri.toQueryParameters()
context.cs.launch {
val name = linkHandler.handle(params)
// TODO@JB: Now what? How do we actually connect this workspace?
context.logger.debug("External request for $name: $uri")
linkHandler.handle(uri, shouldDoAutoLogin()) { restClient, cli ->
// stop polling and de-initialize resources
close()
// start initialization with the new settings
this@CoderRemoteProvider.client = restClient
coderHeaderPage = NewEnvironmentPage(context, context.i18n.pnotr(restClient.url.toString()))
pollJob = poll(restClient, cli)
}
}

Expand All@@ -263,7 +270,7 @@ class CoderRemoteProvider(
// Show sign in page if we have not configured the client yet.
if (client == null) {
// When coming back to the application, authenticate immediately.
val autologin =firstRun && secrets.rememberMe == "true"
val autologin =shouldDoAutoLogin()
var autologinEx: Exception? = null
secrets.lastToken.let { lastToken ->
secrets.lastDeploymentURL.let { lastDeploymentURL ->
Expand DownExpand Up@@ -302,6 +309,8 @@ class CoderRemoteProvider(
return null
}

private fun shouldDoAutoLogin(): Boolean = firstRun && secrets.rememberMe == "true"

/**
* Create a connect page that starts polling and resets the UI on success.
*/
Expand Down
2 changes: 2 additions & 0 deletionssrc/main/kotlin/com/coder/toolbox/CoderToolboxContext.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import com.jetbrains.toolbox.api.core.PluginSecretStore
import com.jetbrains.toolbox.api.core.PluginSettingsStore
import com.jetbrains.toolbox.api.core.diagnostics.Logger
import com.jetbrains.toolbox.api.localization.LocalizableStringFactory
import com.jetbrains.toolbox.api.remoteDev.connection.ClientHelper
import com.jetbrains.toolbox.api.remoteDev.states.EnvironmentStateColorPalette
import com.jetbrains.toolbox.api.remoteDev.ui.EnvironmentUiPageManager
import com.jetbrains.toolbox.api.ui.ToolboxUi
Expand All@@ -13,6 +14,7 @@ data class CoderToolboxContext(
val ui: ToolboxUi,
val envPageManager: EnvironmentUiPageManager,
val envStateColorPalette: EnvironmentStateColorPalette,
val ideOrchestrator: ClientHelper,
val cs: CoroutineScope,
val logger: Logger,
val i18n: LocalizableStringFactory,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,7 @@ import com.jetbrains.toolbox.api.core.diagnostics.Logger
import com.jetbrains.toolbox.api.localization.LocalizableStringFactory
import com.jetbrains.toolbox.api.remoteDev.RemoteDevExtension
import com.jetbrains.toolbox.api.remoteDev.RemoteProvider
import com.jetbrains.toolbox.api.remoteDev.connection.ClientHelper
import com.jetbrains.toolbox.api.remoteDev.states.EnvironmentStateColorPalette
import com.jetbrains.toolbox.api.remoteDev.ui.EnvironmentUiPageManager
import com.jetbrains.toolbox.api.ui.ToolboxUi
Expand All@@ -24,6 +25,7 @@ class CoderToolboxExtension : RemoteDevExtension {
serviceLocator.getService(ToolboxUi::class.java),
serviceLocator.getService(EnvironmentUiPageManager::class.java),
serviceLocator.getService(EnvironmentStateColorPalette::class.java),
serviceLocator.getService(ClientHelper::class.java),
serviceLocator.getService(CoroutineScope::class.java),
serviceLocator.getService(Logger::class.java),
serviceLocator.getService(LocalizableStringFactory::class.java),
Expand Down
5 changes: 2 additions & 3 deletionssrc/main/kotlin/com/coder/toolbox/cli/CoderCLIManager.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,7 +60,6 @@ fun ensureCLI(
deploymentURL: URL,
buildVersion: String,
settings: CoderSettings,
indicator: ((t: String) -> Unit)? = null,
): CoderCLIManager {
val cli = CoderCLIManager(deploymentURL, context.logger, settings)

Expand All@@ -76,7 +75,7 @@ fun ensureCLI(

// If downloads are enabled download the new version.
if (settings.enableDownloads) {
indicator?.invoke("Downloading Coder CLI...")
context.logger.info("Downloading Coder CLI...")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

should we also log what version of CLI is being downloaded and the source URL?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is usinghttps://dev.coder.com/bin/ to download the binary, and it doesn't contain the version. I think the version can be resolved only after running the cli, which means much later than this log.

try {
cli.download()
return cli
Expand All@@ -98,7 +97,7 @@ fun ensureCLI(
}

if (settings.enableDownloads) {
indicator?.invoke("Downloading Coder CLI...")
context.logger.info("Downloading Coder CLI...")
dataCLI.download()
return dataCLI
}
Expand Down
21 changes: 21 additions & 0 deletionssrc/main/kotlin/com/coder/toolbox/sdk/CoderRestClient.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -169,6 +169,19 @@ open class CoderRestClient(
return workspacesResponse.body()!!.workspaces
}

/**
* Retrieves a workspace with the provided id.
* @throws [APIResponseException].
*/
fun workspace(workspaceID: UUID): Workspace {
val workspacesResponse = retroRestClient.workspace(workspaceID).execute()
if (!workspacesResponse.isSuccessful) {
throw APIResponseException("retrieve workspace", url, workspacesResponse)
}

return workspacesResponse.body()!!
}

/**
* Retrieves all the agent names for all workspaces, including those that
* are off. Meant to be used when configuring SSH.
Expand DownExpand Up@@ -272,4 +285,12 @@ open class CoderRestClient(
}
return buildResponse.body()!!
}

fun close() {
httpClient.apply {
dispatcher.executorService.shutdown()
connectionPool.evictAll()
cache?.close()
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import com.coder.toolbox.sdk.v2.models.BuildInfo
import com.coder.toolbox.sdk.v2.models.CreateWorkspaceBuildRequest
import com.coder.toolbox.sdk.v2.models.Template
import com.coder.toolbox.sdk.v2.models.User
import com.coder.toolbox.sdk.v2.models.Workspace
import com.coder.toolbox.sdk.v2.models.WorkspaceBuild
import com.coder.toolbox.sdk.v2.models.WorkspaceResource
import com.coder.toolbox.sdk.v2.models.WorkspacesResponse
Expand All@@ -30,6 +31,14 @@ interface CoderV2RestFacade {
@Query("q") searchParams: String,
): Call<WorkspacesResponse>

/**
* Retrieves a workspace with the provided id.
*/
@GET("api/v2/workspaces/{workspaceID}")
fun workspace(
@Path("workspaceID") workspaceID: UUID
): Call<Workspace>

@GET("api/v2/buildinfo")
fun buildInfo(): Call<BuildInfo>

Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp