[fixes #825] Tie new update checker in preferences
Ties the new update checker logic to the 'Check for updates' button in the preferences
This commit is contained in:
parent
6024f6e5f2
commit
448da9d0df
@ -24,8 +24,10 @@ import javax.swing.event.DocumentEvent;
|
|||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
import net.sf.openrocket.communication.ReleaseInfo;
|
||||||
import net.sf.openrocket.communication.UpdateInfo;
|
import net.sf.openrocket.communication.UpdateInfo;
|
||||||
import net.sf.openrocket.communication.UpdateInfoRetriever;
|
import net.sf.openrocket.communication.UpdateInfoRetriever;
|
||||||
|
import net.sf.openrocket.communication.UpdateInfoRetriever.ReleaseStatus;
|
||||||
import net.sf.openrocket.gui.components.DescriptionArea;
|
import net.sf.openrocket.gui.components.DescriptionArea;
|
||||||
import net.sf.openrocket.gui.components.StyledLabel;
|
import net.sf.openrocket.gui.components.StyledLabel;
|
||||||
import net.sf.openrocket.gui.components.StyledLabel.Style;
|
import net.sf.openrocket.gui.components.StyledLabel.Style;
|
||||||
@ -239,7 +241,7 @@ public class GeneralPreferencesPanel extends PreferencesPanel {
|
|||||||
|
|
||||||
private void checkForUpdates() {
|
private void checkForUpdates() {
|
||||||
final UpdateInfoRetriever retriever = new UpdateInfoRetriever();
|
final UpdateInfoRetriever retriever = new UpdateInfoRetriever();
|
||||||
retriever.start();
|
retriever.startFetchUpdateInfo();
|
||||||
|
|
||||||
|
|
||||||
// Progress dialog
|
// Progress dialog
|
||||||
@ -290,30 +292,47 @@ public class GeneralPreferencesPanel extends PreferencesPanel {
|
|||||||
|
|
||||||
// Check result
|
// Check result
|
||||||
UpdateInfo info = retriever.getUpdateInfo();
|
UpdateInfo info = retriever.getUpdateInfo();
|
||||||
|
|
||||||
|
// Something went wrong
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
JOptionPane.showMessageDialog(this,
|
JOptionPane.showMessageDialog(this,
|
||||||
//// An error occurred while communicating with the server.
|
//// An error occurred while communicating with the server.
|
||||||
trans.get("pref.dlg.lbl.msg1"),
|
trans.get("pref.dlg.lbl.msg1"),
|
||||||
//// Unable to retrieve update information
|
//// Unable to retrieve update information
|
||||||
trans.get("pref.dlg.lbl.msg2"), JOptionPane.WARNING_MESSAGE, null);
|
trans.get("pref.dlg.lbl.msg2"), JOptionPane.WARNING_MESSAGE, null);
|
||||||
} else if (info.getLatestVersion() == null ||
|
return;
|
||||||
info.getLatestVersion().equals("") ||
|
}
|
||||||
BuildProperties.getVersion().equalsIgnoreCase(info.getLatestVersion())) {
|
|
||||||
|
// Something went wrong, but we know what went wrong
|
||||||
|
if (info.getException() != null) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
info.getException().getMessage(),
|
||||||
|
"Could not check for updates", JOptionPane.WARNING_MESSAGE, null); // TODO: replace by trans
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing went wrong (yay!)
|
||||||
|
ReleaseStatus status = info.getReleaseStatus();
|
||||||
|
ReleaseInfo release = info.getLatestRelease();
|
||||||
|
switch (status) {
|
||||||
|
case LATEST:
|
||||||
JOptionPane.showMessageDialog(this,
|
JOptionPane.showMessageDialog(this,
|
||||||
//// You are running the latest version of OpenRocket.
|
//// You are running the latest version of OpenRocket.
|
||||||
trans.get("pref.dlg.lbl.msg3"),
|
String.format(trans.get("update.dlg.latestVersion"), BuildProperties.getVersion()),
|
||||||
//// No updates available
|
//// No updates available
|
||||||
trans.get("pref.dlg.lbl.msg4"), JOptionPane.INFORMATION_MESSAGE, null);
|
trans.get("update.dlg.latestVersion.title"), JOptionPane.INFORMATION_MESSAGE, null);
|
||||||
} else {
|
break;
|
||||||
|
case NEWER:
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
//// You are running the latest version of OpenRocket.
|
||||||
|
String.format("<html><body><p style='width: %dpx'>%s", 400, String.format("You are either running a test/unofficial release of OpenRocket, or you have a time machine and are running an official release from the future.\n\nYour version: %s\nLatest official release: %s",
|
||||||
|
BuildProperties.getVersion(), release.getReleaseName())), // TODO: trans
|
||||||
|
//// No updates available
|
||||||
|
"Newer version", JOptionPane.INFORMATION_MESSAGE, null); // TODO: trans
|
||||||
|
break;
|
||||||
|
case OLDER:
|
||||||
UpdateInfoDialog infoDialog = new UpdateInfoDialog(info);
|
UpdateInfoDialog infoDialog = new UpdateInfoDialog(info);
|
||||||
infoDialog.setVisible(true);
|
infoDialog.setVisible(true);
|
||||||
if (infoDialog.isReminderSelected()) {
|
|
||||||
preferences.putString(SwingPreferences.LAST_UPDATE, "");
|
|
||||||
} else {
|
|
||||||
preferences.putString(SwingPreferences.LAST_UPDATE, info.getLatestVersion());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user