[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:
Sibo Van Gool 2022-01-26 02:03:33 +01:00
parent 6024f6e5f2
commit 448da9d0df

View File

@ -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())) {
JOptionPane.showMessageDialog(this, // Something went wrong, but we know what went wrong
//// You are running the latest version of OpenRocket. if (info.getException() != null) {
trans.get("pref.dlg.lbl.msg3"), JOptionPane.showMessageDialog(this,
//// No updates available info.getException().getMessage(),
trans.get("pref.dlg.lbl.msg4"), JOptionPane.INFORMATION_MESSAGE, null); "Could not check for updates", JOptionPane.WARNING_MESSAGE, null); // TODO: replace by trans
} else { return;
UpdateInfoDialog infoDialog = new UpdateInfoDialog(info); }
infoDialog.setVisible(true);
if (infoDialog.isReminderSelected()) { // Nothing went wrong (yay!)
preferences.putString(SwingPreferences.LAST_UPDATE, ""); ReleaseStatus status = info.getReleaseStatus();
} else { ReleaseInfo release = info.getLatestRelease();
preferences.putString(SwingPreferences.LAST_UPDATE, info.getLatestVersion()); switch (status) {
} case LATEST:
JOptionPane.showMessageDialog(this,
//// You are running the latest version of OpenRocket.
String.format(trans.get("update.dlg.latestVersion"), BuildProperties.getVersion()),
//// No updates available
trans.get("update.dlg.latestVersion.title"), JOptionPane.INFORMATION_MESSAGE, null);
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);
infoDialog.setVisible(true);
} }
} }
} }