@@ -16,12 +16,12 @@ import io.gitpod.toolbox.auth.GitpodLoginPage
16
16
import io.gitpod.toolbox.auth.GitpodOrganizationPage
17
17
import io.gitpod.toolbox.components.GitpodIcon
18
18
import io.gitpod.toolbox.components.SimpleButton
19
+ import io.gitpod.toolbox.service.ConnectParams
19
20
import io.gitpod.toolbox.service.GitpodPublicApiManager
20
21
import io.gitpod.toolbox.service.Utils
21
22
import kotlinx.coroutines.launch
22
23
import org.slf4j.LoggerFactory
23
24
import java.net.URI
24
- import java.net.URLEncoder
25
25
26
26
class GitpodRemoteProvider (
27
27
private val consumer : RemoteEnvironmentConsumer ,
@@ -36,20 +36,25 @@ class GitpodRemoteProvider(
36
36
private val environmentMap = mutableMapOf<String , GitpodRemoteProviderEnvironment >()
37
37
38
38
private val openInToolboxUriHandler = GitpodOpenInToolboxUriHandler { connectParams ->
39
+ if (! authManger.loginWithHost(connectParams.gitpodHost)) {
40
+ // TODO: store connectParams locally so that user doesn't need another dashboard click?
41
+ return @GitpodOpenInToolboxUriHandler
42
+ }
39
43
Utils .toolboxUi.showPluginEnvironmentsPage()
40
- setEnvironmentVisibility(connectParams.workspaceId )
44
+ setEnvironmentVisibility(connectParams)
41
45
}
42
46
43
47
// TODO: multiple host support
44
- private fun setEnvironmentVisibility (workspaceId : String ) {
48
+ private fun setEnvironmentVisibility (connectParams : ConnectParams ) {
49
+ val workspaceId = connectParams.workspaceId
45
50
logger.info(" setEnvironmentVisibility $workspaceId " )
46
51
Utils .toolboxUi.showWindow()
47
52
val env = environmentMap[workspaceId]
48
53
if (env != null ) {
49
54
env.markActive()
50
- Utils .clientHelper.setAutoConnectOnEnvironmentReady(workspaceId , " GO-233.15026.17" , " /workspace/empty" )
55
+ Utils .clientHelper.setAutoConnectOnEnvironmentReady(connectParams.uniqueID , " GO-233.15026.17" , " /workspace/empty" )
51
56
} else {
52
- GitpodRemoteProviderEnvironment (authManger, workspaceId , publicApi).apply {
57
+ GitpodRemoteProviderEnvironment (authManger, connectParams , publicApi).apply {
53
58
environmentMap[workspaceId] = this
54
59
this .markActive()
55
60
consumer.consumeEnvironments(listOf (this ))
@@ -76,14 +81,6 @@ class GitpodRemoteProvider(
76
81
if (workspaces.isEmpty()) {
77
82
return @collect
78
83
}
79
- // TODO: Remove me
80
- workspaces.forEach{
81
- val host = URLEncoder .encode(" https://exp-migration.preview.gitpod-dev.com" , " UTF-8" )
82
- val workspaceId = URLEncoder .encode(it.id, " UTF-8" )
83
- val debugWorkspace = " false"
84
- val newUri = " jetbrains://gateway/io.gitpod.toolbox.gateway/open-in-toolbox?host=${host} &workspaceId=${workspaceId} &debugWorkspace=${debugWorkspace} "
85
- logger.info(" workspace ${it.id} $newUri " )
86
- }
87
84
consumer.consumeEnvironments(workspaces.map {
88
85
val env = environmentMap[it.id]
89
86
if (env != null ) {
@@ -99,9 +96,9 @@ class GitpodRemoteProvider(
99
96
}
100
97
101
98
private fun startup () {
102
- val account = authManger.getCurrentAccount() ? : return
99
+ authManger.getCurrentAccount() ? : return
103
100
publicApi.setup()
104
- val orgId = account .organizationId
101
+ val orgId = Utils .gitpodSettings .organizationId
105
102
logger.info(" user logged in, current selected org: $orgId " )
106
103
if (orgId != null ) {
107
104
Utils .dataManager.startWatchWorkspaces(publicApi)
@@ -111,14 +108,19 @@ class GitpodRemoteProvider(
111
108
Utils .toolboxUi.showUiPage(organizationPage)
112
109
}
113
110
}
114
- authManger.getCurrentAccount()?.onOrgSelected {
115
- Utils .dataManager.startWatchWorkspaces(publicApi)
111
+ Utils .gitpodSettings.onSettingsChanged { key, _ ->
112
+ when (key) {
113
+ GitpodSettings .SettingKey .ORGANIZATION_ID .name -> {
114
+ Utils .dataManager.startWatchWorkspaces(publicApi)
115
+ }
116
+ }
116
117
}
117
118
}
118
119
119
120
override fun getOverrideUiPage (): UiPage ? {
120
- logger.info(" getOverrideUiPage" )
121
- authManger.getCurrentAccount() ? : return loginPage
121
+ val account = authManger.getCurrentAccount()
122
+ logger.info(" get override ui page for ${account?.getHost()} " )
123
+ account ? : return loginPage
122
124
return null
123
125
}
124
126
0 commit comments