Skip to content

Commit

Permalink
move credential change topic subscription to projectListener (#3916)
Browse files Browse the repository at this point in the history
  • Loading branch information
Will-ShaoHua authored Oct 14, 2023
1 parent ace4af9 commit 007e6c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.explorer

import com.intellij.ide.projectView.PresentationData
import com.intellij.ide.util.treeView.AbstractTreeNode
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import com.intellij.ui.SimpleTextAttributes
import com.intellij.util.text.DateTimeFormatManager
import software.aws.toolkits.core.utils.tryOrNull
import software.aws.toolkits.jetbrains.core.credentials.AwsBearerTokenConnection
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnection
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManagerListener
import software.aws.toolkits.jetbrains.core.credentials.pinning.CodeWhispererConnection
import software.aws.toolkits.jetbrains.core.explorer.devToolsTab.nodes.AbstractActionTreeNode
import software.aws.toolkits.jetbrains.core.explorer.devToolsTab.nodes.ActionGroupOnRightClick
import software.aws.toolkits.jetbrains.core.explorer.devToolsTab.nodes.PinnedConnectionNode
import software.aws.toolkits.jetbrains.core.explorer.refreshDevToolTree
import software.aws.toolkits.jetbrains.services.codewhisperer.credentials.CodeWhispererLoginType
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.nodes.CodeWhispererReconnectNode
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.nodes.FreeTierUsageLimitHitNode
Expand Down Expand Up @@ -60,21 +55,6 @@ class CodeWhispererServiceNode(
}
private val learnCodeWhispererNode by lazy { LearnCodeWhispererNode(nodeProject) }

init {
ApplicationManager.getApplication().messageBus.connect().subscribe(
ToolkitConnectionManagerListener.TOPIC,
object : ToolkitConnectionManagerListener {
override fun activeConnectionChanged(newConnection: ToolkitConnection?) {
// TODO: Move this IF block into nullifyAccountlessCredentialIfNeeded()
if (newConnection is AwsBearerTokenConnection) {
CodeWhispererExplorerActionManager.getInstance().nullifyAccountlessCredentialIfNeeded()
}
project.refreshDevToolTree()
}
}
)
}

override fun onDoubleClick(event: MouseEvent) {}

override fun getChildren(): Collection<AbstractTreeNode<*>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ex.ToolWindowManagerListener
import com.intellij.openapi.wm.impl.status.widget.StatusBarWidgetsManager
import software.aws.toolkits.jetbrains.core.credentials.AwsBearerTokenConnection
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnection
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManagerListener
import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.BearerTokenProviderListener
import software.aws.toolkits.jetbrains.core.explorer.refreshDevToolTree
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.CodeWhispererCodeScanManager
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererActivationChangedListener
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
Expand Down Expand Up @@ -57,6 +59,12 @@ class CodeWhispererProjectStartupSettingsListener(private val project: Project)
} else {
CodeWhispererCodeScanManager.getInstance(project).removeCodeScanUI()
}

// TODO: Move this IF block into nullifyAccountlessCredentialIfNeeded()
if (newConnection is AwsBearerTokenConnection) {
CodeWhispererExplorerActionManager.getInstance().nullifyAccountlessCredentialIfNeeded()
}
project.refreshDevToolTree()
}

override fun onChange(providerId: String) {
Expand Down

0 comments on commit 007e6c1

Please sign in to comment.