@@ -16,12 +16,13 @@ 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
22
+ import io.gitpod.toolbox.service.getConnectParams
21
23
import kotlinx.coroutines.launch
22
24
import org.slf4j.LoggerFactory
23
25
import java.net.URI
24
- import java.net.URLEncoder
25
26
26
27
class GitpodRemoteProvider (
27
28
private val consumer : RemoteEnvironmentConsumer ,
@@ -36,24 +37,29 @@ class GitpodRemoteProvider(
36
37
private val environmentMap = mutableMapOf<String , GitpodRemoteProviderEnvironment >()
37
38
38
39
private val openInToolboxUriHandler = GitpodOpenInToolboxUriHandler { connectParams ->
40
+ if (! authManger.loginWithHost(connectParams.gitpodHost)) {
41
+ // TODO: store connectParams locally so that user doesn't need another dashboard click?
42
+ return @GitpodOpenInToolboxUriHandler
43
+ }
39
44
Utils .toolboxUi.showPluginEnvironmentsPage()
40
- setEnvironmentVisibility(connectParams.workspaceId )
45
+ setEnvironmentVisibility(connectParams)
41
46
}
42
47
43
48
// TODO: multiple host support
44
- private fun setEnvironmentVisibility (workspaceId : String ) {
49
+ private fun setEnvironmentVisibility (connectParams : ConnectParams ) {
50
+ val workspaceId = connectParams.workspaceId
45
51
logger.info(" setEnvironmentVisibility $workspaceId " )
46
52
Utils .toolboxUi.showWindow()
47
53
val env = environmentMap[workspaceId]
48
54
if (env != null ) {
49
55
env.markActive()
50
- Utils .clientHelper.setAutoConnectOnEnvironmentReady(workspaceId , " GO-233.15026.17 " , " /workspace/empty " )
56
+ Utils .clientHelper.setAutoConnectOnEnvironmentReady(connectParams.uniqueID , " GO-241.18034.61 " , " /workspace/template-golang-cli " )
51
57
} else {
52
- GitpodRemoteProviderEnvironment (authManger, workspaceId , publicApi).apply {
58
+ GitpodRemoteProviderEnvironment (authManger, connectParams , publicApi).apply {
53
59
environmentMap[workspaceId] = this
54
60
this .markActive()
55
61
consumer.consumeEnvironments(listOf (this ))
56
- Utils .clientHelper.setAutoConnectOnEnvironmentReady(workspaceId, " GO-233.15026.17 " , " /workspace/empty " )
62
+ Utils .clientHelper.setAutoConnectOnEnvironmentReady(workspaceId, " GO-241.18034.61 " , " /workspace/template-golang-cli " )
57
63
}
58
64
}
59
65
}
@@ -76,21 +82,14 @@ class GitpodRemoteProvider(
76
82
if (workspaces.isEmpty()) {
77
83
return @collect
78
84
}
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
85
consumer.consumeEnvironments(workspaces.map {
88
- val env = environmentMap[it.id]
86
+ val connectParams = it.getConnectParams()
87
+ val env = environmentMap[connectParams.uniqueID]
89
88
if (env != null ) {
90
89
env
91
90
} else {
92
- val newEnv = GitpodRemoteProviderEnvironment (authManger, it.id , publicApi)
93
- environmentMap[it.id ] = newEnv
91
+ val newEnv = GitpodRemoteProviderEnvironment (authManger, connectParams , publicApi)
92
+ environmentMap[connectParams.uniqueID ] = newEnv
94
93
newEnv
95
94
}
96
95
})
@@ -99,9 +98,9 @@ class GitpodRemoteProvider(
99
98
}
100
99
101
100
private fun startup () {
102
- val account = authManger.getCurrentAccount() ? : return
101
+ authManger.getCurrentAccount() ? : return
103
102
publicApi.setup()
104
- val orgId = account .organizationId
103
+ val orgId = Utils .gitpodSettings .organizationId
105
104
logger.info(" user logged in, current selected org: $orgId " )
106
105
if (orgId != null ) {
107
106
Utils .dataManager.startWatchWorkspaces(publicApi)
@@ -111,14 +110,19 @@ class GitpodRemoteProvider(
111
110
Utils .toolboxUi.showUiPage(organizationPage)
112
111
}
113
112
}
114
- authManger.getCurrentAccount()?.onOrgSelected {
115
- Utils .dataManager.startWatchWorkspaces(publicApi)
113
+ Utils .gitpodSettings.onSettingsChanged { key, _ ->
114
+ when (key) {
115
+ GitpodSettings .SettingKey .ORGANIZATION_ID .name -> {
116
+ Utils .dataManager.startWatchWorkspaces(publicApi)
117
+ }
118
+ }
116
119
}
117
120
}
118
121
119
122
override fun getOverrideUiPage (): UiPage ? {
120
- logger.info(" getOverrideUiPage" )
121
- authManger.getCurrentAccount() ? : return loginPage
123
+ val account = authManger.getCurrentAccount()
124
+ logger.info(" get override ui page for ${account?.getHost()} " )
125
+ account ? : return loginPage
122
126
return null
123
127
}
124
128
0 commit comments