|
| 1 | +package org.digma.intellij.plugin.activation |
| 2 | + |
| 3 | +import com.intellij.notification.Notification |
| 4 | +import com.intellij.notification.NotificationGroupManager |
| 5 | +import com.intellij.notification.NotificationType |
| 6 | +import com.intellij.openapi.actionSystem.AnAction |
| 7 | +import com.intellij.openapi.actionSystem.AnActionEvent |
| 8 | +import com.intellij.openapi.project.Project |
| 9 | +import org.digma.intellij.plugin.PluginId |
| 10 | +import org.digma.intellij.plugin.common.findActiveProject |
| 11 | +import org.digma.intellij.plugin.errorreporting.ErrorReporter |
| 12 | +import org.digma.intellij.plugin.notifications.NotificationUtil.DIGMA_STICKY_BALLOON_NOTIFICATION_GROUP |
| 13 | +import org.digma.intellij.plugin.posthog.ActivityMonitor |
| 14 | +import org.digma.intellij.plugin.recentactivity.RecentActivityToolWindowShower |
| 15 | +import org.digma.intellij.plugin.ui.ToolWindowShower |
| 16 | + |
| 17 | + |
| 18 | +fun showNewIssueNotification(title: String, uiMessage: String) { |
| 19 | + |
| 20 | + findActiveProject()?.let { project -> |
| 21 | + val notificationName = "NewIssueFoundNotification" |
| 22 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("Show.$notificationName", mapOf()) |
| 23 | + val notification = NotificationGroupManager.getInstance().getNotificationGroup(DIGMA_STICKY_BALLOON_NOTIFICATION_GROUP) |
| 24 | + .createNotification( |
| 25 | + title, |
| 26 | + "Digma has some initial findings! Click the link bellow to view the issues and get more information.", |
| 27 | + NotificationType.INFORMATION |
| 28 | + ) |
| 29 | + notification.addAction(ShowIssuesAction(project, notification, notificationName, uiMessage)) |
| 30 | + notification.whenExpired { |
| 31 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.expired", mapOf()) |
| 32 | + } |
| 33 | + notification.setImportant(true) |
| 34 | + notification.setToolWindowId(PluginId.TOOL_WINDOW_ID) |
| 35 | + notification.notify(project) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +fun showNewInsightNotification(title: String, uiMessage: String) { |
| 40 | + findActiveProject()?.let { project -> |
| 41 | + val notificationName = "NewInsightFoundNotification" |
| 42 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("Show.$notificationName", mapOf()) |
| 43 | + val notification = NotificationGroupManager.getInstance().getNotificationGroup(DIGMA_STICKY_BALLOON_NOTIFICATION_GROUP) |
| 44 | + .createNotification( |
| 45 | + title, |
| 46 | + "Digma has some initial analytics results. Click the link bellow to see the list of assets and drill into any specific one to see more data.", |
| 47 | + NotificationType.INFORMATION |
| 48 | + ) |
| 49 | + notification.addAction(ShowAssetAction(project, notification, notificationName, uiMessage)) |
| 50 | + notification.whenExpired { |
| 51 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.expired", mapOf()) |
| 52 | + } |
| 53 | + notification.setImportant(true) |
| 54 | + notification.setToolWindowId(PluginId.TOOL_WINDOW_ID) |
| 55 | + notification.notify(project) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +fun showNewAssetNotification(title: String, uiMessage: String) { |
| 60 | + findActiveProject()?.let { project -> |
| 61 | + val notificationName = "NewAssetFoundNotification" |
| 62 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("Show.$notificationName", mapOf()) |
| 63 | + val notification = NotificationGroupManager.getInstance().getNotificationGroup(DIGMA_STICKY_BALLOON_NOTIFICATION_GROUP) |
| 64 | + .createNotification( |
| 65 | + title, |
| 66 | + "First assets discovered! Digma has received some data about your code. Click the link bellow to see the assets view.", |
| 67 | + NotificationType.INFORMATION |
| 68 | + ) |
| 69 | + notification.addAction(ShowAssetAction(project, notification, notificationName, uiMessage)) |
| 70 | + notification.whenExpired { |
| 71 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.expired", mapOf()) |
| 72 | + } |
| 73 | + notification.setImportant(true) |
| 74 | + notification.setToolWindowId(PluginId.TOOL_WINDOW_ID) |
| 75 | + notification.notify(project) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +fun showNewRecentActivityNotification(title: String, uiMessage: String) { |
| 80 | + findActiveProject()?.let { project -> |
| 81 | + val notificationName = "NewRecentActivityFoundNotification" |
| 82 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("Show.$notificationName", mapOf()) |
| 83 | + val notification = NotificationGroupManager.getInstance().getNotificationGroup(DIGMA_STICKY_BALLOON_NOTIFICATION_GROUP) |
| 84 | + .createNotification( |
| 85 | + title, |
| 86 | + "Digma has some initial analytics results. Click here to see the list of activities and drill into any specific one to see more data.", |
| 87 | + NotificationType.INFORMATION |
| 88 | + ) |
| 89 | + notification.addAction(ShowRecentActivityAction(project, notification, notificationName, uiMessage)) |
| 90 | + notification.whenExpired { |
| 91 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.expired", mapOf()) |
| 92 | + } |
| 93 | + notification.setImportant(true) |
| 94 | + notification.setToolWindowId(PluginId.TOOL_WINDOW_ID) |
| 95 | + notification.notify(project) |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | + |
| 100 | +private class ShowIssuesAction( |
| 101 | + private val project: Project, |
| 102 | + private val notification: Notification, |
| 103 | + private val notificationName: String, |
| 104 | + private val uiMessage: String, |
| 105 | +) : AnAction("Show Issues") { |
| 106 | + override fun actionPerformed(e: AnActionEvent) { |
| 107 | + |
| 108 | + try { |
| 109 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.clicked", mapOf()) |
| 110 | + ToolWindowShower.getInstance(project).showToolWindow() |
| 111 | + project.messageBus.syncPublisher(UserClickedNotificationEvent.USER_CLICKED_NOTIFICATION_TOPIC).notificationClicked(uiMessage) |
| 112 | + notification.expire() |
| 113 | + } catch (e: Throwable) { |
| 114 | + ErrorReporter.getInstance().reportError(project, "ShowIssuesAction.actionPerformed", e) |
| 115 | + } |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +//we can't show the analytics tab because there is no home for analytics |
| 120 | +private class ShowInsightAction( |
| 121 | + private val project: Project, |
| 122 | + private val notification: Notification, |
| 123 | + private val notificationName: String, |
| 124 | + private val uiMessage: String, |
| 125 | +) : AnAction("Show Insights") { |
| 126 | + override fun actionPerformed(e: AnActionEvent) { |
| 127 | + |
| 128 | + try { |
| 129 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.clicked", mapOf()) |
| 130 | + ToolWindowShower.getInstance(project).showToolWindow() |
| 131 | + project.messageBus.syncPublisher(UserClickedNotificationEvent.USER_CLICKED_NOTIFICATION_TOPIC).notificationClicked(uiMessage) |
| 132 | + notification.expire() |
| 133 | + } catch (e: Throwable) { |
| 134 | + ErrorReporter.getInstance().reportError(project, "ShowInsightAction.actionPerformed", e) |
| 135 | + } |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +private class ShowAssetAction( |
| 140 | + private val project: Project, |
| 141 | + private val notification: Notification, |
| 142 | + private val notificationName: String, |
| 143 | + private val uiMessage: String, |
| 144 | +) : AnAction("Show Assets") { |
| 145 | + override fun actionPerformed(e: AnActionEvent) { |
| 146 | + |
| 147 | + try { |
| 148 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.clicked", mapOf()) |
| 149 | + ToolWindowShower.getInstance(project).showToolWindow() |
| 150 | + project.messageBus.syncPublisher(UserClickedNotificationEvent.USER_CLICKED_NOTIFICATION_TOPIC).notificationClicked(uiMessage) |
| 151 | + notification.expire() |
| 152 | + } catch (e: Throwable) { |
| 153 | + ErrorReporter.getInstance().reportError(project, "ShowAssetAction.actionPerformed", e) |
| 154 | + } |
| 155 | + } |
| 156 | +} |
| 157 | + |
| 158 | +private class ShowRecentActivityAction( |
| 159 | + private val project: Project, |
| 160 | + private val notification: Notification, |
| 161 | + private val notificationName: String, |
| 162 | + private val uiMessage: String, |
| 163 | +) : AnAction("Show Recent Activity") { |
| 164 | + override fun actionPerformed(e: AnActionEvent) { |
| 165 | + |
| 166 | + try { |
| 167 | + ActivityMonitor.getInstance(project).registerNotificationCenterEvent("$notificationName.clicked", mapOf()) |
| 168 | + RecentActivityToolWindowShower.getInstance(project).showToolWindow() |
| 169 | + project.messageBus.syncPublisher(UserClickedNotificationEvent.USER_CLICKED_NOTIFICATION_TOPIC).notificationClicked(uiMessage) |
| 170 | + notification.expire() |
| 171 | + } catch (e: Throwable) { |
| 172 | + ErrorReporter.getInstance().reportError(project, "ShowRecentActivityAction.actionPerformed", e) |
| 173 | + } |
| 174 | + } |
| 175 | +} |
0 commit comments