Skip to content

Commit

Permalink
phase active
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Aug 19, 2024
1 parent 3426801 commit 6c448a5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class GitpodRemoteProvider(
future.complete(null)
return@launch
}
Utils.toolboxUi.showWindow()
Utils.toolboxUi.showPluginEnvironmentsPage()
setEnvironmentVisibility(connectParams)
future.complete(null)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ class GitpodRemoteProviderEnvironment(

private val lastWSEnvState = MutableSharedFlow<WorkspaceEnvState>(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 {
Expand All @@ -66,19 +55,19 @@ 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))
}
}
}

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
}
Expand All @@ -89,9 +78,6 @@ class GitpodRemoteProviderEnvironment(
override fun getContentsView(): CompletableFuture<EnvironmentContentsView> = contentsViewFuture

override fun setVisible(visibilityState: EnvironmentVisibilityState) {
if (visibilityState.contentsVisible && lastPhase == WorkspaceInstanceStatus.Phase.PHASE_RUNNING) {
isMarkActive = true
}
}

override fun getActionList(): ObservableList<ActionDescription> = actionList
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c448a5

Please sign in to comment.