use of com.mucommander.job.impl.SelfUpdateJob in project mucommander by mucommander.
the class CheckVersionDialog method run.
/**
* Checks for updates and notifies the user of the outcome.
*/
public void run() {
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
String message;
String title;
VersionChecker version;
URL downloadURL = null;
boolean downloadOption = false;
String jarURL = null;
try {
LOGGER.debug("Checking for new version...");
version = VersionChecker.getInstance();
// A newer version is available
if (version.isNewVersionAvailable()) {
LOGGER.info("A new version is available!");
title = Translator.get("version_dialog.new_version_title");
// Checks if the current platform can open a new browser window
downloadURL = new URL(version.getDownloadURL());
downloadOption = DesktopManager.isOperationSupported(DesktopManager.BROWSE, new Object[] { downloadURL });
// display the download URL.
if (downloadOption) {
message = Translator.get("version_dialog.new_version");
} else {
message = Translator.get("version_dialog.new_version_url", downloadURL.toString());
}
jarURL = version.getJarURL();
} else // We're already running latest version
{
LOGGER.debug("No new version.");
// we do not need to inform the user that he already has the latest version
if (!userInitiated) {
dispose();
return;
}
title = Translator.get("version_dialog.no_new_version_title");
message = Translator.get("version_dialog.no_new_version");
}
}// Check failed
catch (Exception e) {
// we do not need to inform the user that the check failed
if (!userInitiated) {
dispose();
return;
}
title = Translator.get("version_dialog.not_available_title");
message = Translator.get("version_dialog.not_available");
}
// Set title
setTitle(title);
List<DialogAction> actions = new ArrayList<>();
actions.add(CheckVersionAction.OK);
// 'Go to website' choice (if available)
if (downloadOption) {
actions.add(CheckVersionAction.GO_TO_WEBSITE);
}
// // 'Install and restart' choice (if available)
// if(jarURL!=null) {
// actionsV.add(new Integer(INSTALL_AND_RESTART_ACTION));
// labelsV.add(Translator.get("version_dialog.install_and_restart"));
// }
init(new InformationPane(message, null, Font.PLAIN, InformationPane.INFORMATION_ICON), actions, 0);
JCheckBox showNextTimeCheckBox = new JCheckBox(Translator.get("prefs_dialog.check_for_updates_on_startup"), MuConfigurations.getPreferences().getVariable(MuPreference.CHECK_FOR_UPDATE, MuPreferences.DEFAULT_CHECK_FOR_UPDATE));
addComponent(showNextTimeCheckBox);
setMinimumSize(MINIMUM_DIALOG_DIMENSION);
// Show dialog and get user action
DialogAction action = getActionValue();
if (action == CheckVersionAction.GO_TO_WEBSITE) {
try {
DesktopManager.executeOperation(DesktopManager.BROWSE, new Object[] { downloadURL });
} catch (Exception e) {
InformationDialog.showErrorDialog(this);
}
} else if (action == CheckVersionAction.INSTALL_AND_RESTART) {
ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("Installing new version"));
SelfUpdateJob job = new SelfUpdateJob(progressDialog, mainFrame, FileFactory.getFile(jarURL));
progressDialog.start(job);
}
// Remember user preference
MuConfigurations.getPreferences().setVariable(MuPreference.CHECK_FOR_UPDATE, showNextTimeCheckBox.isSelected());
}
Aggregations