From e261a1cbfaf181b5ab2519b930329e236b95884d Mon Sep 17 00:00:00 2001 From: Joachim Ansorg Date: Mon, 9 Dec 2024 15:34:34 +0100 Subject: [PATCH] Show notification if the download of an AppMap CLI binary failed --- .../FailedDownloadNotificationListener.java | 20 ++++++++++++ .../notifications/AppMapNotifications.java | 32 +++++++++++++++++++ .../settings/AppMapApplicationSettings.java | 2 ++ .../main/resources/META-INF/appmap-core.xml | 3 ++ .../resources/messages/appland.properties | 6 +++- 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 plugin-core/src/main/java/appland/cli/FailedDownloadNotificationListener.java diff --git a/plugin-core/src/main/java/appland/cli/FailedDownloadNotificationListener.java b/plugin-core/src/main/java/appland/cli/FailedDownloadNotificationListener.java new file mode 100644 index 00000000..0767c9c0 --- /dev/null +++ b/plugin-core/src/main/java/appland/cli/FailedDownloadNotificationListener.java @@ -0,0 +1,20 @@ +package appland.cli; + +import appland.notifications.AppMapNotifications; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +public final class FailedDownloadNotificationListener implements AppLandDownloadListener { + @NotNull private final Project project; + + public FailedDownloadNotificationListener(@NotNull Project project) { + this.project = project; + } + + @Override + public void downloadFinished(@NotNull CliTool type, boolean success) { + if (!success) { + AppMapNotifications.showFailedCliBinaryDownloadNotification(project); + } + } +} diff --git a/plugin-core/src/main/java/appland/notifications/AppMapNotifications.java b/plugin-core/src/main/java/appland/notifications/AppMapNotifications.java index e62e2a6f..43ba8b27 100644 --- a/plugin-core/src/main/java/appland/notifications/AppMapNotifications.java +++ b/plugin-core/src/main/java/appland/notifications/AppMapNotifications.java @@ -314,4 +314,36 @@ public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification noti notification.notify(project); }); } + + /** + * See https://github.com/getappmap/appmap-intellij-plugin/issues/814. + */ + public static void showFailedCliBinaryDownloadNotification(@NotNull Project project) { + if (!AppMapApplicationSettingsService.getInstance().isShowFailedCliDownloadError()) { + return; + } + + // the message should only appear once + AppMapApplicationSettingsService.getInstance().setShowFailedCliDownloadError(false); + + ApplicationManager.getApplication().invokeLater(() -> { + Notification notification = new AppMapFullContentNotification( + GENERIC_NOTIFICATIONS_ID, + null, + AppMapBundle.get("notification.cliDownloadFailed.title"), + null, + AppMapBundle.get("notification.cliDownloadFailed.content"), + NotificationType.ERROR, + null + ); + + var showInstructionsAction = NotificationAction.create(lazy("notification.cliDownloadFailed.browseAction"), (e, n) -> { + n.expire(); + BrowserUtil.browse("https://appmap.io/docs/reference/appmap-airgapped-install.html#download-the-appmap-application-binaries"); + }); + + notification = notification.addAction(showInstructionsAction); + notification.notify(project); + }); + } } diff --git a/plugin-core/src/main/java/appland/settings/AppMapApplicationSettings.java b/plugin-core/src/main/java/appland/settings/AppMapApplicationSettings.java index bcfa76d1..22c3a128 100644 --- a/plugin-core/src/main/java/appland/settings/AppMapApplicationSettings.java +++ b/plugin-core/src/main/java/appland/settings/AppMapApplicationSettings.java @@ -54,6 +54,8 @@ public class AppMapApplicationSettings { */ private volatile int maxPinnedFileSizeKB = 20; + private volatile boolean showFailedCliDownloadError = true; + public AppMapApplicationSettings() { } diff --git a/plugin-core/src/main/resources/META-INF/appmap-core.xml b/plugin-core/src/main/resources/META-INF/appmap-core.xml index 0f21b0f0..cd188750 100644 --- a/plugin-core/src/main/resources/META-INF/appmap-core.xml +++ b/plugin-core/src/main/resources/META-INF/appmap-core.xml @@ -24,6 +24,9 @@ + + diff --git a/plugin-core/src/main/resources/messages/appland.properties b/plugin-core/src/main/resources/messages/appland.properties index 858807f3..b35007a6 100644 --- a/plugin-core/src/main/resources/messages/appland.properties +++ b/plugin-core/src/main/resources/messages/appland.properties @@ -122,6 +122,7 @@ dirPathValidation.notDir=Please enter the location of a directory, not a file. nameValidation.empty=Please enter a valid name. +notification.dontShowAgainOption=Don't show again notification.closeButton=Close notification.stopButton=Stop notification.recordingHelpButton=Show Help @@ -162,6 +163,10 @@ notification.exportAppMapJson.content=An error occurred while exporting AppMap J notification.reloadProject.content=Please reload your project because the AppMap settings changed. +notification.cliDownloadFailed.title=AppMap Binary Download Failed +notification.cliDownloadFailed.content=Failed to download a required AppMap binary. Please refer to the instructions to manually install it. +notification.cliDownloadFailed.browseAction=Show instructions + statusBar.recording.displayName=AppMap Recording statusBar.recording.recordingStatus=Recording... @@ -268,4 +273,3 @@ findingsOverview.openFindingsByHashError.message=Unable to locate AppMap with ha toolwindow.appmap.navie.intro=Ask Navie a question about your application to get started. toolwindow.appmap.navie.newNavieChat=New Navie Chat toolwindow.appmap.navie.details=Navie uses AppMap data to improve the accuracy of Generative AI models. Navie searches through your locally stored AppMap data to identify the application behavior related to your question. -notification.dontShowAgainOption=Don't show again