Skip to content

Commit 594ecff

Browse files
committed
Remove state from companion object
1 parent 911b61e commit 594ecff

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationPanel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class NotificationPanel : BorderLayoutPanel() {
1515
init {
1616
isOpaque = false
1717
addToCenter(wrapper)
18-
ProcessNotificationsBase.showBannerNotification.forEach {
19-
updateNotificationPanel(it.value)
18+
BannerNotificationService.getInstance().getNotifications().forEach { (_, content) ->
19+
updateNotificationPanel(content)
2020
}
2121
}
2222

2323
private fun removeNotificationPanel(notificationId: String) = runInEdt {
24-
ProcessNotificationsBase.showBannerNotification.remove(notificationId)
24+
BannerNotificationService.getInstance().removeNotification(notificationId)
2525
NotificationDismissalState.getInstance().dismissNotification(notificationId)
2626
wrapper.removeAll()
2727
}

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationStateUtils.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ package software.aws.toolkits.jetbrains.core.notifications
55

66
import com.intellij.openapi.components.PersistentStateComponent
77
import com.intellij.openapi.components.RoamingType
8+
import com.intellij.openapi.components.Service
89
import com.intellij.openapi.components.State
910
import com.intellij.openapi.components.Storage
10-
import com.intellij.openapi.components.Service
1111
import com.intellij.openapi.components.service
1212

1313
@Service
@@ -65,3 +65,23 @@ class NotificationEtagState : PersistentStateComponent<NotificationEtagConfigura
6565
data class NotificationEtagConfiguration(
6666
var etag: String? = null,
6767
)
68+
69+
@Service
70+
class BannerNotificationService {
71+
private val notifications = mutableMapOf<String, BannerContent>()
72+
73+
fun addNotification(id: String, content: BannerContent) {
74+
notifications[id] = content
75+
}
76+
77+
fun getNotifications(): Map<String, BannerContent> = notifications
78+
79+
fun removeNotification(id: String) {
80+
notifications.remove(id)
81+
}
82+
83+
companion object {
84+
fun getInstance(): BannerNotificationService =
85+
service()
86+
}
87+
}

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/ProcessNotificationsBase.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ProcessNotificationsBase(
8383
)
8484
if (severity == "Critical") {
8585
val bannerContent = BannerContent(notificationContent.title, notificationContent.description, followupActions, notificationData.id)
86-
showBannerNotification[notificationData.id] = bannerContent
86+
BannerNotificationService.getInstance().addNotification(notificationData.id, bannerContent)
8787
notifyListenerForNotification(bannerContent)
8888
}
8989
}
@@ -107,7 +107,6 @@ class ProcessNotificationsBase(
107107
companion object {
108108
fun getInstance(project: Project): ProcessNotificationsBase = project.service()
109109

110-
val showBannerNotification = mutableMapOf<String, BannerContent>()
111110
private const val NOTIFICATIONS_PATH = "aws-static-resources/notifications.json"
112111
}
113112
}

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/utils/NotificationUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import com.intellij.ui.ScrollPaneFactory
1717
import org.slf4j.LoggerFactory
1818
import software.aws.toolkits.core.utils.warn
1919
import software.aws.toolkits.jetbrains.core.help.HelpIds
20+
import software.aws.toolkits.jetbrains.core.notifications.BannerNotificationService
2021
import software.aws.toolkits.jetbrains.core.notifications.NotificationDismissalState
21-
import software.aws.toolkits.jetbrains.core.notifications.ProcessNotificationsBase
2222
import software.aws.toolkits.resources.AwsCoreBundle
2323
import javax.swing.JLabel
2424
import javax.swing.JTextArea
@@ -67,7 +67,7 @@ fun notifyStickyWithData(
6767
createNotificationExpiringAction(
6868
object : AnAction("Dismiss") {
6969
override fun actionPerformed(e: AnActionEvent) {
70-
ProcessNotificationsBase.showBannerNotification.remove(id)
70+
BannerNotificationService.getInstance().removeNotification(id)
7171
NotificationDismissalState.getInstance().dismissNotification(id)
7272
}
7373
}

0 commit comments

Comments
 (0)