-
Notifications
You must be signed in to change notification settings - Fork 274
Notification dismissal state tracking #5129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
8e9325c
ff7debe
f2072e4
5009de3
9b60583
34cbdfa
71e90d3
45bc05d
37b18f9
54799ef
81fa23a
e15c0a4
911b61e
594ecff
3e1725f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||||||
| // Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||
|
|
||||||||||
| package software.aws.toolkits.jetbrains.core.notifications | ||||||||||
|
|
||||||||||
| import com.intellij.openapi.application.ApplicationManager | ||||||||||
| import com.intellij.openapi.components.PersistentStateComponent | ||||||||||
| import com.intellij.openapi.components.State | ||||||||||
| import com.intellij.openapi.components.Storage | ||||||||||
|
|
||||||||||
| @State(name = "notificationDismissals", storages = [Storage("aws.xml")]) | ||||||||||
|
||||||||||
| class NotificationDismissalState : PersistentStateComponent<NotificationDismissalConfiguration> { | ||||||||||
|
Check warning on line 12 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationPersistantState.kt
|
||||||||||
|
||||||||||
| private var state = NotificationDismissalConfiguration() | ||||||||||
|
||||||||||
|
|
||||||||||
| override fun getState(): NotificationDismissalConfiguration = state | ||||||||||
|
|
||||||||||
| override fun loadState(state: NotificationDismissalConfiguration) { | ||||||||||
| this.state = state | ||||||||||
| } | ||||||||||
|
|
||||||||||
| fun isDismissed(notificationId: String): Boolean = | ||||||||||
| state.dismissedNotificationIds.contains(notificationId) | ||||||||||
|
|
||||||||||
| fun dismissNotification(notificationId: String) { | ||||||||||
| state.dismissedNotificationIds.add(notificationId) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| companion object { | ||||||||||
| fun getInstance(): NotificationDismissalState = | ||||||||||
| ApplicationManager.getApplication().getService(NotificationDismissalState::class.java) | ||||||||||
|
||||||||||
| fun getInstance(): NotificationDismissalState = | |
| ApplicationManager.getApplication().getService(NotificationDismissalState::class.java) | |
| fun getInstance(): NotificationDismissalState = | |
| ApplicationManager.getApplication().getService<NotificationDismissalState>() |
Check warning on line 39 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationPersistantState.kt
GitHub Actions / Qodana Community for JVM
Extension class should be final and non-public
Service implementation should not be public. If a service is supposed to be used outside its module, extract an interface from it and specify it as serviceInterface in plugin.xml.
Fixed
Show fixed
Hide fixed
Fixed
Show fixed
Hide fixed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fun getInstance(): NotificationEtagState = | |
| ApplicationManager.getApplication().getService(NotificationEtagState::class.java) | |
| fun getInstance(): NotificationEtagState = | |
| ApplicationManager.getApplication().getService<NotificationEtagState>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting a syntax error when I do this. I think this is for newer versions of Intellij SDK. I don't see any other usages of the bottom code in our repository, but I do see the ::class.java version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you try using getInstance(): NotificationETagState = service()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that works!
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,16 +15,20 @@ | |
| import software.aws.toolkits.core.utils.inputStream | ||
| import software.aws.toolkits.jetbrains.utils.notifyStickyWithData | ||
| import java.nio.file.Paths | ||
| import java.util.concurrent.atomic.AtomicBoolean | ||
|
|
||
| object NotificationMapperUtil { | ||
| val mapper = jacksonObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
|
||
| } | ||
|
|
||
| @Service(Service.Level.PROJECT) | ||
| class ProcessNotificationsBase { | ||
| class ProcessNotificationsBase( | ||
| private val project: Project, | ||
| ) { | ||
| private val notifListener = mutableListOf<NotifListener>() | ||
| private var isStartup: AtomicBoolean = AtomicBoolean(true) | ||
|
||
| init { | ||
| NotificationPollingService.getInstance().addObserver { -> | ||
| NotificationPollingService.getInstance().addObserver { | ||
| retrieveStartupAndEmergencyNotifications() | ||
| } | ||
| } | ||
|
|
@@ -39,11 +43,30 @@ | |
| } | ||
|
|
||
| fun retrieveStartupAndEmergencyNotifications() { | ||
| // TODO: separates notifications into startup and emergency | ||
| // iterates through the 2 lists and processes each notification(if it isn't dismissed) | ||
| val notifications = getNotificationsFromFile() | ||
|
|
||
| notifications?.let { notificationsList -> | ||
| val (startupNotifications, emergencyNotifications) = notificationsList.notifications | ||
| ?.partition { notification -> | ||
| notification.schedule.type.equals("StartUp", ignoreCase = true) | ||
|
||
| } | ||
| ?: Pair(emptyList(), emptyList()) | ||
|
|
||
| val dismissalState = NotificationDismissalState.getInstance() | ||
| val startupList = if (isStartup.compareAndSet(true, false)) { | ||
| startupNotifications | ||
| } else { | ||
| emptyList() | ||
| } | ||
|
|
||
| val combinedNotifications = startupList.plus(emergencyNotifications) | ||
| val activeNotifications = combinedNotifications.filter { !dismissalState.isDismissed(it.id) } | ||
|
|
||
| activeNotifications.forEach { processNotification(project, it) } | ||
| } | ||
| } | ||
|
|
||
| fun processNotification(project: Project, notificationData: NotificationData) { | ||
|
Check notice on line 69 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/ProcessNotificationsBase.kt
|
||
| val shouldShow = RulesEngine.displayNotification(project, notificationData) | ||
| if (shouldShow) { | ||
| val notificationContent = notificationData.content.locale | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import com.intellij.ui.ScrollPaneFactory | |
| import org.slf4j.LoggerFactory | ||
| import software.aws.toolkits.core.utils.warn | ||
| import software.aws.toolkits.jetbrains.core.help.HelpIds | ||
| import software.aws.toolkits.jetbrains.core.notifications.NotificationDismissalState | ||
| import software.aws.toolkits.jetbrains.core.notifications.ProcessNotificationsBase | ||
| import software.aws.toolkits.resources.AwsCoreBundle | ||
| import javax.swing.JLabel | ||
|
|
@@ -67,7 +68,7 @@ fun notifyStickyWithData( | |
| object : AnAction("Dismiss") { | ||
| override fun actionPerformed(e: AnActionEvent) { | ||
| ProcessNotificationsBase.showBannerNotification.remove(id) | ||
|
||
| // TODO: add id to dismissed notification list | ||
| NotificationDismissalState.getInstance().dismissNotification(id) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| <extensions defaultExtensionNs="com.intellij"> | ||
| <!-- each plugin needs its own instance of these --> | ||
| <applicationService serviceImplementation="software.aws.toolkits.jetbrains.core.notifications.NotificationEtagState"/> | ||
| <applicationService serviceImplementation="software.aws.toolkits.jetbrains.core.notifications.NotificationDismissalState"/> | ||
|
||
| <applicationService serviceImplementation="migration.software.aws.toolkits.jetbrains.core.coroutines.PluginCoroutineScopeTracker"/> | ||
| <projectService serviceImplementation="migration.software.aws.toolkits.jetbrains.core.coroutines.PluginCoroutineScopeTracker"/> | ||
| <postStartupActivity implementation = "software.aws.toolkits.jetbrains.core.notifications.NotificationServiceInitializer"/> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.