-
Notifications
You must be signed in to change notification settings - Fork 1
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
ee07b8d
ba78918
0661a8d
5b7f3e9
3108f7d
0403ee2
86532d4
56ed322
0b49bcb
894bcab
21f012d
00f9ab3
b67585f
9f096cf
2cd3565
d3a483e
20441c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 coderHeaderPager = 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()) | ||
) | ||
|
@@ -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) { | ||
|
@@ -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 = | ||
|
@@ -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 = coderHeaderPager | ||
|
||
/** | ||
* We always show a list of environments. | ||
|
@@ -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 | ||
[email protected] = restClient | ||
coderHeaderPager = NewEnvironmentPage(context, context.i18n.pnotr(restClient.url.toString())) | ||
pollJob = poll(restClient, cli) | ||
} | ||
} | ||
|
||
|
@@ -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 -> | ||
|
@@ -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. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
|
@@ -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...") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is using https://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 | ||
|
@@ -98,7 +97,7 @@ fun ensureCLI( | |
} | ||
|
||
if (settings.enableDownloads) { | ||
indicator?.invoke("Downloading Coder CLI...") | ||
context.logger.info("Downloading Coder CLI...") | ||
dataCLI.download() | ||
return dataCLI | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.