From 6c448a5f5a4bc5d6bb7a82ff2568559773427d24 Mon Sep 17 00:00:00 2001 From: hwen Date: Mon, 19 Aug 2024 18:37:24 +0800 Subject: [PATCH] phase active --- .../toolbox/gateway/GitpodRemoteProvider.kt | 7 +--- .../GitpodRemoteProviderEnvironment.kt | 32 ++++--------------- .../toolbox/service/GitpodPublicApiManager.kt | 4 --- 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt index d6ae81f118d85f..49833060ccbb08 100644 --- a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt +++ b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt @@ -40,8 +40,6 @@ class GitpodRemoteProvider( future.complete(null) return@launch } - Utils.toolboxUi.showWindow() - Utils.toolboxUi.showPluginEnvironmentsPage() setEnvironmentVisibility(connectParams) future.complete(null) } @@ -64,7 +62,6 @@ class GitpodRemoteProvider( environmentMap[connectParams.uniqueID] = Pair(workspace, env) consumer.consumeEnvironments(environmentMap.values.map { it.second }) } - env!!.markActive() val joinLinkInfo = workspace!!.fetchJoinLink2Info(publicApi.getWorkspaceOwnerToken(workspaceId)) Utils.clientHelper.setAutoConnectOnEnvironmentReady(workspaceId, joinLinkInfo.ideVersion, joinLinkInfo.projectPath) } @@ -102,12 +99,10 @@ class GitpodRemoteProvider( override fun getOverrideUiPage(): UiPage? { authManger.addLoginListener { - Utils.toolboxUi.showWindow() - Utils.toolboxUi.showPluginEnvironmentsPage() startup() + Utils.toolboxUi.showPluginEnvironmentsPage() } authManger.addLogoutListener { - Utils.toolboxUi.showWindow() Utils.toolboxUi.showPluginEnvironmentsPage() } val account = authManger.getCurrentAccount() diff --git a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProviderEnvironment.kt b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProviderEnvironment.kt index 1b19d7751f1356..809d7384f91e40 100644 --- a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProviderEnvironment.kt +++ b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProviderEnvironment.kt @@ -42,17 +42,6 @@ class GitpodRemoteProviderEnvironment( private val lastWSEnvState = MutableSharedFlow(1, 0, BufferOverflow.DROP_OLDEST) private var lastPhase: WorkspaceInstanceStatus.Phase = WorkspaceInstanceStatus.Phase.PHASE_UNSPECIFIED - private var isMarkActive = false - set(value) { - if (field != value) { - field = value - lastWSEnvState.tryEmit(WorkspaceEnvState(lastPhase, value)) - } - } - - fun markActive() { - isMarkActive = true - } init { Utils.coroutineScope.launch { @@ -66,11 +55,11 @@ class GitpodRemoteProviderEnvironment( } Utils.coroutineScope.launch { - GitpodLogger.info("connectParams.workspaceId $connectParams") + GitpodLogger.debug("watching workspace ${connectParams.workspaceId}") watchWorkspaceJob = publicApi.watchWorkspaceStatus(connectParams.workspaceId) { _, status -> lastPhase = status.phase - GitpodLogger.info("${connectParams.workspaceId} status updated: $lastPhase") - lastWSEnvState.tryEmit(WorkspaceEnvState(status.phase, isMarkActive)) + GitpodLogger.debug("${connectParams.workspaceId} status updated: $lastPhase") + lastWSEnvState.tryEmit(WorkspaceEnvState(status.phase)) } } } @@ -78,7 +67,7 @@ class GitpodRemoteProviderEnvironment( override fun addStateListener(consumer: EnvironmentStateConsumer): Boolean { val ok = super.addStateListener(consumer) Utils.coroutineScope.launch { - lastWSEnvState.tryEmit(WorkspaceEnvState(lastPhase, isMarkActive)) + lastWSEnvState.tryEmit(WorkspaceEnvState(lastPhase)) } return ok } @@ -89,9 +78,6 @@ class GitpodRemoteProviderEnvironment( override fun getContentsView(): CompletableFuture = contentsViewFuture override fun setVisible(visibilityState: EnvironmentVisibilityState) { - if (visibilityState.contentsVisible && lastPhase == WorkspaceInstanceStatus.Phase.PHASE_RUNNING) { - isMarkActive = true - } } override fun getActionList(): ObservableList = actionList @@ -102,14 +88,10 @@ class GitpodRemoteProviderEnvironment( } -private class WorkspaceEnvState(val phase: WorkspaceInstanceStatus.Phase, val isMarkActive: Boolean) { +private class WorkspaceEnvState(val phase: WorkspaceInstanceStatus.Phase) { fun getState() = run { - if (isMarkActive && phase == WorkspaceInstanceStatus.Phase.PHASE_RUNNING) { - StandardRemoteEnvironmentState.Active - } else { - phaseToStateMap[phase] ?: StandardRemoteEnvironmentState.Unreachable - } + phaseToStateMap[phase] ?: StandardRemoteEnvironmentState.Unreachable } companion object { @@ -120,7 +102,7 @@ private class WorkspaceEnvState(val phase: WorkspaceInstanceStatus.Phase, val is WorkspaceInstanceStatus.Phase.PHASE_PENDING to StandardRemoteEnvironmentState.Initializing, WorkspaceInstanceStatus.Phase.PHASE_CREATING to StandardRemoteEnvironmentState.Initializing, WorkspaceInstanceStatus.Phase.PHASE_INITIALIZING to StandardRemoteEnvironmentState.Initializing, - WorkspaceInstanceStatus.Phase.PHASE_RUNNING to StandardRemoteEnvironmentState.Inactive, + WorkspaceInstanceStatus.Phase.PHASE_RUNNING to StandardRemoteEnvironmentState.Active, WorkspaceInstanceStatus.Phase.PHASE_INTERRUPTED to StandardRemoteEnvironmentState.Error, WorkspaceInstanceStatus.Phase.PHASE_STOPPING to StandardRemoteEnvironmentState.Unreachable, WorkspaceInstanceStatus.Phase.PHASE_STOPPED to StandardRemoteEnvironmentState.Hibernated, diff --git a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodPublicApiManager.kt b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodPublicApiManager.kt index 48ba9b1e34ef99..cb44d138147a41 100644 --- a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodPublicApiManager.kt +++ b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/service/GitpodPublicApiManager.kt @@ -25,10 +25,6 @@ class GitpodPublicApiManager(private val authManger: GitpodAuthManager) { private var account: GitpodAccount? = null init { - setup() - authManger.addLoginListener { - setup() - } authManger.addLogoutListener { workspaceApi = null organizationApi = null