@@ -10,14 +10,12 @@ import com.jetbrains.toolbox.gateway.RemoteProvider
10
10
import com.jetbrains.toolbox.gateway.ui.AccountDropdownField
11
11
import com.jetbrains.toolbox.gateway.ui.ActionDescription
12
12
import com.jetbrains.toolbox.gateway.ui.UiPage
13
+ import io.gitpod.publicapi.experimental.v1.Workspaces
13
14
import io.gitpod.toolbox.auth.GitpodAuthManager
14
15
import io.gitpod.toolbox.auth.GitpodLoginPage
15
16
import io.gitpod.toolbox.components.GitpodIcon
16
17
import io.gitpod.toolbox.components.SimpleButton
17
- import io.gitpod.toolbox.service.ConnectParams
18
- import io.gitpod.toolbox.service.GitpodPublicApiManager
19
- import io.gitpod.toolbox.service.Utils
20
- import io.gitpod.toolbox.service.getConnectParams
18
+ import io.gitpod.toolbox.service.*
21
19
import io.gitpod.toolbox.utils.GitpodLogger
22
20
import kotlinx.coroutines.launch
23
21
import java.net.URI
@@ -31,7 +29,7 @@ class GitpodRemoteProvider(
31
29
private val loginPage = GitpodLoginPage (authManger)
32
30
33
31
// cache consumed environments map locally
34
- private val environmentMap = mutableMapOf<String , GitpodRemoteProviderEnvironment >()
32
+ private val environmentMap = mutableMapOf<String , Pair < Workspaces . Workspace , GitpodRemoteProviderEnvironment > >()
35
33
36
34
private var pendingConnectParams: Pair <String , ConnectParams >? = null
37
35
private val openInToolboxUriHandler = GitpodOpenInToolboxUriHandler { (gitpodHost, connectParams) ->
@@ -50,30 +48,25 @@ class GitpodRemoteProvider(
50
48
return @GitpodOpenInToolboxUriHandler future
51
49
}
52
50
53
- private fun setEnvironmentVisibility (connectParams : ConnectParams ) {
51
+ private suspend fun setEnvironmentVisibility (connectParams : ConnectParams ) {
54
52
val workspaceId = connectParams.workspaceId
55
53
GitpodLogger .debug(" setEnvironmentVisibility $workspaceId , $connectParams " )
56
- val env = environmentMap[connectParams.uniqueID]
57
- if (env != null ) {
58
- env.markActive()
59
- Utils .clientHelper.setAutoConnectOnEnvironmentReady(
60
- connectParams.uniqueID,
61
- " GO-242.20224.39" ,
62
- " /workspace/empty"
63
- )
64
- } else {
65
- GitpodRemoteProviderEnvironment (
54
+ val obj = environmentMap[connectParams.uniqueID]
55
+ var (workspace, env) = obj ? : Pair (null , null )
56
+ if (obj == null ) {
57
+ workspace = publicApi.getWorkspace(workspaceId)
58
+ env = GitpodRemoteProviderEnvironment (
66
59
authManger,
67
60
connectParams,
68
61
publicApi,
69
62
Utils .observablePropertiesFactory
70
- ).apply {
71
- environmentMap[connectParams.uniqueID] = this
72
- this .markActive()
73
- consumer.consumeEnvironments(listOf (this ))
74
- Utils .clientHelper.setAutoConnectOnEnvironmentReady(workspaceId, " GO-242.20224.39" , " /workspace/empty" )
75
- }
63
+ )
64
+ environmentMap[connectParams.uniqueID] = Pair (workspace, env)
65
+ consumer.consumeEnvironments(environmentMap.values.map { it.second })
76
66
}
67
+ env!! .markActive()
68
+ val joinLinkInfo = workspace!! .fetchJoinLink2Info(publicApi.getWorkspaceOwnerToken(workspaceId))
69
+ Utils .clientHelper.setAutoConnectOnEnvironmentReady(workspaceId, joinLinkInfo.ideVersion, joinLinkInfo.projectPath)
77
70
}
78
71
79
72
private fun showWorkspacesList () {
@@ -84,13 +77,13 @@ class GitpodRemoteProvider(
84
77
}
85
78
consumer.consumeEnvironments(workspaces.map {
86
79
val connectParams = it.getConnectParams()
87
- val env = environmentMap[connectParams.uniqueID] ? : GitpodRemoteProviderEnvironment (
80
+ val env = environmentMap[connectParams.uniqueID]?.second ? : GitpodRemoteProviderEnvironment (
88
81
authManger,
89
82
connectParams,
90
83
publicApi,
91
84
Utils .observablePropertiesFactory
92
85
)
93
- environmentMap[connectParams.uniqueID] = env
86
+ environmentMap[connectParams.uniqueID] = Pair (it, env)
94
87
if (connectParams.uniqueID == pendingConnectParams?.second?.uniqueID) {
95
88
setEnvironmentVisibility(connectParams)
96
89
pendingConnectParams = null
@@ -108,9 +101,6 @@ class GitpodRemoteProvider(
108
101
}
109
102
110
103
override fun getOverrideUiPage (): UiPage ? {
111
- val account = authManger.getCurrentAccount()
112
- account ? : return loginPage
113
- startup()
114
104
authManger.addLoginListener {
115
105
Utils .toolboxUi.showWindow()
116
106
Utils .toolboxUi.showPluginEnvironmentsPage()
@@ -120,6 +110,16 @@ class GitpodRemoteProvider(
120
110
Utils .toolboxUi.showWindow()
121
111
Utils .toolboxUi.showPluginEnvironmentsPage()
122
112
}
113
+ val account = authManger.getCurrentAccount()
114
+ account ? : return loginPage
115
+ startup()
116
+ Utils .coroutineScope.launch {
117
+ if (account.isValidate()) {
118
+ return @launch
119
+ }
120
+ authManger.logout()
121
+ Utils .toolboxUi.showPluginEnvironmentsPage()
122
+ }
123
123
return null
124
124
}
125
125
0 commit comments