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: store last used URL in Toolbox Settings Store#200

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 6 commits intomainfromstore-last-used-url-in-settings
Sep 27, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
4 changes: 4 additions & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,10 @@

## Unreleased

### Changed

- simplified storage for last used url and token

## 0.6.6 - 2025-09-24

### Changed
Expand Down
2 changes: 1 addition & 1 deletiongradle.properties
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
version=0.6.6
version=0.7.0
group=com.coder.toolbox
name=coder-toolbox
14 changes: 7 additions & 7 deletionssrc/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,6 @@ import com.coder.toolbox.sdk.ex.APIResponseException
import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
import com.coder.toolbox.util.CoderProtocolHandler
import com.coder.toolbox.util.DialogUi
import com.coder.toolbox.util.toURL
import com.coder.toolbox.util.waitForTrue
import com.coder.toolbox.util.withPath
import com.coder.toolbox.views.Action
Expand DownExpand Up@@ -364,8 +363,8 @@ class CoderRemoteProvider(
if (shouldDoAutoSetup()) {
try {
CoderCliSetupContext.apply {
url = context.secrets.lastDeploymentURL.toURL()
token = context.secrets.lastToken
url = context.deploymentUrl
token = context.secrets.tokenFor(context.deploymentUrl)
}
CoderCliSetupWizardState.goToStep(WizardStep.CONNECT)
return CoderCliSetupWizardPage(
Expand DownExpand Up@@ -399,14 +398,15 @@ class CoderRemoteProvider(
* Auto-login only on first the firs run if there is a url & token configured or the auth
* should be done via certificates.
*/
private fun shouldDoAutoSetup(): Boolean = firstRun && (context.secrets.canAutoLogin || !settings.requireTokenAuth)
private fun shouldDoAutoSetup(): Boolean = firstRun && (canAutoLogin() || !settings.requireTokenAuth)

fun canAutoLogin(): Boolean = !context.secrets.tokenFor(context.deploymentUrl).isNullOrBlank()

private fun onConnect(client: CoderRestClient, cli: CoderCLIManager) {
// Store the URL and token for use next time.
context.secrets.lastDeploymentURL =client.url.toString()
context.settingsStore.updateLastUsedUrl(client.url)
if (context.settingsStore.requireTokenAuth) {
context.secrets.lastToken = client.token ?: ""
context.secrets.storeTokenFor(client.url, context.secrets.lastToken)
context.secrets.storeTokenFor(client.url, client.token ?: "")
context.logger.info("Deployment URL and token were stored and will be available for automatic connection")
} else {
context.logger.info("Deployment URL was stored and will be available for automatic connection")
Expand Down
14 changes: 6 additions & 8 deletionssrc/main/kotlin/com/coder/toolbox/CoderToolboxContext.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,17 +36,15 @@ data class CoderToolboxContext(
*
* In order of preference:
*
* 1. Last used URL.
* 2. URL in settings.
* 3. CODER_URL.
* 4. URL in global cli config.
* 1. Last used URL from the settings.
* 2. Last used URL from the secrets store.
* 3. Default URL
*/
val deploymentUrl: URL
get() {
if (this.secrets.lastDeploymentURL.isNotBlank()) {
return this.secrets.lastDeploymentURL.toURL()
}
return this.settingsStore.defaultURL.toURL()
return settingsStore.lastDeploymentURL?.takeIf { it.isNotBlank() }?.toURL()
?: secrets.lastDeploymentURL.takeIf { it.isNotBlank() }?.toURL()
?: settingsStore.defaultURL.toURL()
}

suspend fun logAndShowError(title: String, error: String) {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,12 @@ import java.util.Locale.getDefault
* Read-only interface for accessing Coder settings
*/
interface ReadOnlyCoderSettings {

/**
* The last used deployment URL.
*/
val lastDeploymentURL: String?

/**
* The default URL to show in the connection window.
*/
Expand Down
23 changes: 5 additions & 18 deletionssrc/main/kotlin/com/coder/toolbox/store/CoderSecretsStore.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,24 +8,11 @@ import java.net.URL
* Provides Coder secrets backed by the secrets store service.
*/
class CoderSecretsStore(private val store: PluginSecretStore) {
private fun get(key: String): String = store[key] ?: ""

private fun set(key: String, value: String) {
if (value.isBlank()) {
store.clear(key)
} else {
store[key] = value
}
}

var lastDeploymentURL: String
get() = get("last-deployment-url")
set(value) = set("last-deployment-url", value)
var lastToken: String
get() = get("last-token")
set(value) = set("last-token", value)
val canAutoLogin: Boolean
get() = lastDeploymentURL.isNotBlank() && lastToken.isNotBlank()
@Deprecated(
message = "The URL is now stored the JSON backed settings store. Use CoderSettingsStore#lastDeploymentURL",
replaceWith = ReplaceWith("context.settingsStore.lastDeploymentURL")
)
val lastDeploymentURL: String = store["last-deployment-url"] ?: ""

fun tokenFor(url: URL): String? = store[url.host]

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@ class CoderSettingsStore(
) : ReadOnlyTLSSettings

// Properties implementation
override val lastDeploymentURL: String? get() = store[LAST_USED_URL]
override val defaultURL: String get() = store[DEFAULT_URL] ?: "https://dev.coder.com"
override val binarySource: String? get() = store[BINARY_SOURCE]
override val binaryDirectory: String? get() = store[BINARY_DIRECTORY]
Expand DownExpand Up@@ -155,6 +156,10 @@ class CoderSettingsStore(
fun readOnly(): ReadOnlyCoderSettings = this

// Write operations
fun updateLastUsedUrl(url: URL) {
store[LAST_USED_URL] = url.toString()
}

fun updateBinarySource(source: String) {
store[BINARY_SOURCE] = source
}
Expand Down
2 changes: 1 addition & 1 deletionsrc/main/kotlin/com/coder/toolbox/store/StoreKeys.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@ package com.coder.toolbox.store

internal const val CODER_SSH_CONFIG_OPTIONS = "CODER_SSH_CONFIG_OPTIONS"

internal const valCODER_URL = "CODER_URL"
internal const valLAST_USED_URL = "lastDeploymentURL"

internal const val DEFAULT_URL = "defaultURL"

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,8 +63,8 @@ class DeploymentUrlStep(
errorField.textState.update {
context.i18n.pnotr("")
}
urlField.textState.update {
context.secrets.lastDeploymentURL
urlField.contentState.update {
context.deploymentUrl.toString()
}

signatureFallbackStrategyField.checkedState.update {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp