check for updates always in a background thread

This commit is contained in:
Dmitry Jemerov
2011-03-04 19:33:56 +01:00
parent e0ddde1485
commit be9a87e25c
3 changed files with 60 additions and 36 deletions
@@ -204,16 +204,27 @@ public class IdeaApplication {
}, ModalityState.NON_MODAL);
}
private void updatePlugins(boolean showConfirmation) {
final CheckForUpdateResult checkForUpdateResult = UpdateChecker.checkForUpdates();
private void updatePlugins(final boolean showConfirmation) {
final Application app = ApplicationManager.getApplication();
app.executeOnPooledThread(new Runnable() {
@Override
public void run() {
final CheckForUpdateResult checkForUpdateResult = UpdateChecker.checkForUpdates();
final List<PluginDownloader> updatedPlugins = UpdateChecker.updatePlugins(false, null);
if (checkForUpdateResult.hasNewBuildInSelectedChannel()) {
UpdateChecker.showUpdateInfoDialog(true, checkForUpdateResult.getUpdatedChannel(), updatedPlugins);
}
else if (updatedPlugins != null) {
UpdateChecker.showNoUpdatesDialog(true, updatedPlugins, showConfirmation);
}
final List<PluginDownloader> updatedPlugins = UpdateChecker.updatePlugins(false, null);
app.invokeLater(new Runnable() {
@Override
public void run() {
if (checkForUpdateResult.hasNewBuildInSelectedChannel()) {
UpdateChecker.showUpdateInfoDialog(true, checkForUpdateResult.getUpdatedChannel(), updatedPlugins);
}
else if (updatedPlugins != null) {
UpdateChecker.showNoUpdatesDialog(true, updatedPlugins, showConfirmation);
}
}
});
}
});
}
}
@@ -17,8 +17,15 @@ package com.intellij.openapi.updateSettings.impl;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SystemInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -30,34 +37,37 @@ public class CheckForUpdateAction extends AnAction implements DumbAware {
}
public void actionPerformed(AnActionEvent e) {
actionPerformed(true, null);
Project project = e.getData(PlatformDataKeys.PROJECT);
actionPerformed(project, true, null);
}
public static void actionPerformed(final boolean enableLink, final @Nullable UpdateSettingsConfigurable settingsConfigurable) {
final CheckForUpdateResult result = UpdateChecker.checkForUpdates();
final List<PluginDownloader> updatedPlugins = UpdateChecker.updatePlugins(true, settingsConfigurable);
if (result.getState() == UpdateStrategy.State.CONNECTION_ERROR) {
UpdateChecker.showConnectionErrorDialog();
return;
}
if (result.getState() != UpdateStrategy.State.LOADED) {
//not a connection error... something happened but user has nothing to do with it
return;
}
if (result.hasNewBuildInSelectedChannel()) {
//information about new channel could be there
UpdateSettings.getInstance().LAST_TIME_CHECKED = System.currentTimeMillis();
UpdateChecker.showUpdateInfoDialog(enableLink, result.getUpdatedChannel(), updatedPlugins);
}else{
//information about new channel could be there
UpdateChecker.showNoUpdatesDialog(enableLink, updatedPlugins, true);
}
public static void actionPerformed(Project project, final boolean enableLink, final @Nullable UpdateSettingsConfigurable settingsConfigurable) {
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Checking for updates", false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final CheckForUpdateResult result = UpdateChecker.checkForUpdates();
final List<PluginDownloader> updatedPlugins = UpdateChecker.updatePlugins(true, settingsConfigurable);
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (result.getState() == UpdateStrategy.State.CONNECTION_ERROR) {
UpdateChecker.showConnectionErrorDialog();
return;
}
if (result.hasNewBuildInSelectedChannel()) {
//information about new channel could be there
UpdateSettings.getInstance().LAST_TIME_CHECKED = System.currentTimeMillis();
UpdateChecker.showUpdateInfoDialog(enableLink, result.getUpdatedChannel(), updatedPlugins);
}
else {
//information about new channel could be there
UpdateChecker.showNoUpdatesDialog(enableLink, updatedPlugins, true);
}
}
});
}
});
}
}
@@ -15,17 +15,19 @@
*/
package com.intellij.openapi.updateSettings.impl;
import com.intellij.ide.DataManager;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.options.BaseConfigurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.InputValidator;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.NonEmptyInputValidator;
import com.intellij.openapi.util.IconLoader;
import com.intellij.ui.CollectionComboBoxModel;
import com.intellij.ui.EnumComboBoxModel;
import com.intellij.ui.ListUtil;
import com.intellij.ui.components.JBList;
import com.intellij.util.ArrayUtil;
@@ -138,7 +140,8 @@ public class UpdateSettingsConfigurable extends BaseConfigurable implements Sear
myBtnCheckNow.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CheckForUpdateAction.actionPerformed(false, UpdateSettingsConfigurable.this);
Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myBtnCheckNow));
CheckForUpdateAction.actionPerformed(project, false, UpdateSettingsConfigurable.this);
updateLastCheckedLabel();
}
});