From 7b78dd567f9e7becd102c2dee4b0c40f40a3906f Mon Sep 17 00:00:00 2001 From: Sergey Dubov Date: Wed, 11 Dec 2019 15:56:13 +0300 Subject: [PATCH] Notify a user about open browser failure and show notification after a timeout - Currently, we open browser after unsuccessfull attempts to get response from a running application and open a browser with provided host and port. This might be confusing for cases when user debug their application. The commit show a notification instead to notify a user about unreachable app. - Related issues: RIDER-23354, UX-1077 GitOrigin-RevId: cbe08957e1244ebd0be97820759e4ead5230dd3c --- .../intellij/ide/browsers/BrowserStarter.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/xml/impl/src/com/intellij/ide/browsers/BrowserStarter.java b/xml/impl/src/com/intellij/ide/browsers/BrowserStarter.java index c487abbab095..eaf5818c13e0 100644 --- a/xml/impl/src/com/intellij/ide/browsers/BrowserStarter.java +++ b/xml/impl/src/com/intellij/ide/browsers/BrowserStarter.java @@ -5,6 +5,10 @@ import com.google.common.net.HostAndPort; import com.intellij.concurrency.JobScheduler; import com.intellij.execution.configurations.RunConfiguration; import com.intellij.execution.process.ProcessHandler; +import com.intellij.ide.BrowserUtil; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationGroup; +import com.intellij.notification.NotificationType; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Urls; @@ -12,7 +16,9 @@ import com.intellij.util.net.NetUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.event.HyperlinkEvent; import java.net.URI; +import java.util.Objects; import java.util.concurrent.TimeUnit; import java.util.function.BooleanSupplier; @@ -83,8 +89,8 @@ public class BrowserStarter { checkAndOpenPageLater(hostAndPort, attemptNumber + 1, delayMillis); } else { - LOG.info("#" + attemptNumber + " check " + hostAndPort + " failed. Too many failed checks, opening " + hostAndPort); - openPageNow(); + LOG.info("#" + attemptNumber + " check " + hostAndPort + " failed. Too many failed checks. Failed to open " + hostAndPort); + showBrowserOpenTimeoutNotification(); } } @@ -114,4 +120,28 @@ public class BrowserStarter { private boolean isOutdated() { return myOutdated.getAsBoolean(); } + + private void showBrowserOpenTimeoutNotification() { + NotificationGroup group = NotificationGroup.balloonGroup("URL does not respond notification"); + NotificationType type = NotificationType.ERROR; + + String title = "URL does not respond"; + String url = Objects.requireNonNull(mySettings.getUrl()); + String openUrlDescription = "open_url"; + String content = String.format( + "Unable to open %s in the browser because the URL does not respond.", + openUrlDescription, + url + ); + + Notification openBrowserNotification = group.createNotification(title, content, type, (notification, event) -> { + if (event.getEventType() != HyperlinkEvent.EventType.ACTIVATED) return; + if (event.getDescription().equals(openUrlDescription)) { + BrowserUtil.open(url); + notification.expire(); + } + }); + + openBrowserNotification.notify(myRunConfiguration.getProject()); + } }