-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ee07b8d
impl: support uri handling (1)
fioan89 ba78918
chore: update comment
fioan89 0661a8d
refactor: text progress indicator can be replaced by an actual logger
fioan89 5b7f3e9
impl: support for uri handling (2)
fioan89 3108f7d
impl: resilience when `url` query parameter is missing
fioan89 0403ee2
impl: rework the handling of missing token code
fioan89 86532d4
impl: show error dialog when workspace name was not provided
fioan89 56ed322
impl: wait for workspace to be running
fioan89 0b49bcb
impl: support for ClientHelper
fioan89 894bcab
fix: URI handling race condition when creating polling jobs
fioan89 21f012d
impl: install ide to the workspace if product code and build number w…
fioan89 00f9ab3
fix: wait for IDE to be installed and then connect
fioan89 b67585f
fix: use launch/join instead of runBlocking
fioan89 9f096cf
impl: uri support for specifying a project to open
fioan89 2cd3565
fix: handle the uri when we don't do autologin
fioan89 d3a483e
refactor: proper constant name to reflect the value
fioan89 20441c8
chore: fix typo in property name
fioan89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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()) | ||
) | ||
|
@@ -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 = coderHeaderPage | ||
|
||
/** | ||
* 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 | ||
coderHeaderPage = 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. | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.