update checker: show balloon notification when automatic updates, dialog when explicitly invoked check-action (IDEA-98256, IDEA-88905)

This commit is contained in:
Anna Kozlova
2013-05-31 18:42:25 +04:00
parent f344e24502
commit 0aea27c45e
@@ -27,7 +27,6 @@ import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
@@ -40,8 +39,7 @@ import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.*;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.ex.WindowManagerEx;
import com.intellij.util.Function;
import com.intellij.util.PlatformUtils;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.io.UrlConnectionUtil;
@@ -55,7 +53,6 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.io.*;
import java.net.*;
@@ -470,10 +467,10 @@ public final class UpdateChecker {
private static boolean ourUpdateInfoDialogShown = false;
public static void showUpdateResult(CheckForUpdateResult checkForUpdateResult,
List<PluginDownloader> updatedPlugins,
boolean showConfirmation,
boolean enableLink,
public static void showUpdateResult(final CheckForUpdateResult checkForUpdateResult,
final List<PluginDownloader> updatedPlugins,
final boolean showConfirmation,
final boolean enableLink,
final boolean alwaysShowResults) {
UpdateChannel channelToPropose = checkForUpdateResult.getChannelToPropose();
if (channelToPropose != null && channelToPropose.getLatestBuild() != null) {
@@ -481,46 +478,76 @@ public final class UpdateChecker {
dialog.setModal(alwaysShowResults);
dialog.show();
}
else if (checkForUpdateResult.hasNewBuildInSelectedChannel() && !ourUpdateInfoDialogShown) {
UpdateInfoDialog dialog = new UpdateInfoDialog(true, checkForUpdateResult.getUpdatedChannel(), updatedPlugins, enableLink) {
@Override
protected void dispose() {
ourUpdateInfoDialogShown = false;
super.dispose();
}
};
dialog.setModal(alwaysShowResults);
ourUpdateInfoDialogShown = true;
dialog.show();
}
else if ((updatedPlugins != null || alwaysShowResults && ProjectManager.getInstance().getOpenProjects().length == 0) && !ourUpdateInfoDialogShown) {
NoUpdatesDialog dialog = new NoUpdatesDialog(true, updatedPlugins, enableLink) {
@Override
protected void dispose() {
ourUpdateInfoDialogShown = false;
super.dispose();
}
};
dialog.setShowConfirmation(showConfirmation);
ourUpdateInfoDialogShown = true;
dialog.show();
} else if (alwaysShowResults) {
final String title = IdeBundle.message("updates.info.dialog.title");
final String message = "You already have the latest version of " + ApplicationInfo.getInstance().getVersionName() + " installed.<br> " +
"To configure automatic update settings, see the <a href=\"updates\">Updates</a> dialog of your IDE settings";
new NotificationGroup(IdeBundle.message("update.available.group"), NotificationDisplayType.STICKY_BALLOON, true)
.createNotification(title, message, NotificationType.INFORMATION, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
notification.expire();
final UpdateSettingsConfigurable configurable = new UpdateSettingsConfigurable();
IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null);
ShowSettingsUtil.getInstance().editConfigurable((JFrame)ideFrame, configurable);
else {
final boolean showBalloonNotification = !alwaysShowResults && ProjectManager.getInstance().getOpenProjects().length > 0;
if (checkForUpdateResult.hasNewBuildInSelectedChannel() && !ourUpdateInfoDialogShown) {
final Runnable showUpdatesDialogRunnable = new Runnable() {
public void run() {
UpdateInfoDialog dialog = new UpdateInfoDialog(true, checkForUpdateResult.getUpdatedChannel(), updatedPlugins, enableLink) {
@Override
protected void dispose() {
ourUpdateInfoDialogShown = false;
super.dispose();
}
};
dialog.setModal(alwaysShowResults);
ourUpdateInfoDialogShown = true;
dialog.show();
}
}).notify(null);
};
if (showBalloonNotification) {
final String message = ApplicationInfo.getInstance().getVersionName() + " is ready to <a href=\"update\">update</a>";
showBalloonNotification(showUpdatesDialogRunnable, message);
}
else {
showUpdatesDialogRunnable.run();
}
}
else {
final Runnable showPluginsUpdateDialogRunnable = new Runnable() {
public void run() {
final NoUpdatesDialog dialog = new NoUpdatesDialog(true, updatedPlugins, enableLink) {
@Override
protected void dispose() {
ourUpdateInfoDialogShown = false;
super.dispose();
}
};
dialog.setShowConfirmation(showConfirmation);
ourUpdateInfoDialogShown = true;
dialog.show();
}
};
if (showBalloonNotification && updatedPlugins != null) {
final String updatedPluginsList = StringUtil.join(updatedPlugins, new Function<PluginDownloader, String>() {
@Override
public String fun(PluginDownloader downloader) {
return downloader.getPluginName();
}
}, ", ");
final String message = "You already have the latest version of " + ApplicationInfo.getInstance().getVersionName() + " installed.<br> " +
"The following plugins are ready to <a href=\"update\">update</a>: " + updatedPluginsList;
showBalloonNotification(showPluginsUpdateDialogRunnable, message);
}
else if ((updatedPlugins != null || alwaysShowResults) && !ourUpdateInfoDialogShown) {
showPluginsUpdateDialogRunnable.run();
}
}
}
}
private static void showBalloonNotification(final Runnable showUpdatesDialogRunnable, String message) {
new NotificationGroup(IdeBundle.message("update.available.group"), NotificationDisplayType.STICKY_BALLOON, true)
.createNotification(IdeBundle.message("updates.info.dialog.title"), message, NotificationType.INFORMATION,
new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
notification.expire();
showUpdatesDialogRunnable.run();
}
}).notify(null);
}
public static String prepareUpdateCheckArgs() {
addUpdateRequestParameter("build", ApplicationInfo.getInstance().getBuild().asString());
addUpdateRequestParameter("uid", getInstallationUID(PropertiesComponent.getInstance()));