Merge pull request #1403 from SiboVG/softwareUpdaterBeta

Add checkbox in preferences for checking for beta updates + fixes
This commit is contained in:
Joe Pfeiffer 2022-06-03 10:22:22 -06:00 committed by GitHub
commit f184940715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 11 deletions

View File

@ -14,5 +14,7 @@ build.source=default
# Whether checking for updates is enabled by default.
build.checkupdates=true
# Whether checking for beta updates is enabled by default.
build.checkbetaupdates=true

View File

@ -297,6 +297,8 @@ pref.dlg.RockSimfiles = RockSim engine files (*.rse)
pref.dlg.ZIParchives = ZIP archives (*.zip)
pref.dlg.checkbox.Checkupdates = Check for software updates at startup
pref.dlg.checkbox.Checkupdates.ttip = Check for software updates every time you start up OpenRocket
pref.dlg.checkbox.CheckBetaupdates = Also check for beta releases
pref.dlg.checkbox.CheckBetaupdates.ttip = If checked, beta release updates are also notified. If unchecked, only official releases are considered.
pref.dlg.ttip.Checkupdatesnow = Check for software updates now
pref.dlg.lbl.Selectprefunits = Select your preferred units:
pref.dlg.lbl.Rocketinfofontsize = Size of text in rocket design panel:

View File

@ -117,7 +117,6 @@ public class UpdateInfoRetriever {
private final String preTag = null; // Change e.g. to 'android' for Android release
private final String[] filterTags = null; // Change to e.g. ["beta"] to only retrieve beta releases
private final boolean onlyOfficial = false; // Change to false for beta testing
private volatile UpdateInfo info;
@ -140,7 +139,7 @@ public class UpdateInfoRetriever {
// Get the latest release name from the GitHub release page
JsonArray jsonArr = retrieveAllReleaseObjects();
JsonObject latestObj = getLatestReleaseJSON(jsonArr, preTag, filterTags, onlyOfficial);
JsonObject latestObj = getLatestReleaseJSON(jsonArr, preTag, filterTags, !Application.getPreferences().getCheckBetaUpdates());
ReleaseInfo release = new ReleaseInfo(latestObj);
String latestName = release.getReleaseName();

View File

@ -55,6 +55,8 @@ public abstract class Preferences implements ChangeSource {
public static final String PLOT_SHOW_POINTS = "ShowPlotPoints";
private static final String CHECK_UPDATES = "CheckUpdates";
private static final String CHECK_BETA_UPDATES = "CheckBetaUpdates";
public static final String MOTOR_DIAMETER_FILTER = "MotorDiameterMatch";
public static final String MOTOR_HIDE_SIMILAR = "MotorHideSimilar";
@ -140,6 +142,14 @@ public abstract class Preferences implements ChangeSource {
public final void setCheckUpdates(boolean check) {
this.putBoolean(CHECK_UPDATES, check);
}
public final boolean getCheckBetaUpdates() {
return this.getBoolean(CHECK_BETA_UPDATES, BuildProperties.getDefaultCheckBetaUpdates());
}
public final void setCheckBetaUpdates(boolean check) {
this.putBoolean(CHECK_BETA_UPDATES, check);
}
public final boolean getConfirmSimDeletion() {
return this.getBoolean(CONFIRM_DELETE_SIMULATION, true);

View File

@ -12,6 +12,7 @@ public class BuildProperties {
private static final String BUILD_COPYRIGHT;
private static final String BUILD_SOURCE;
private static final boolean DEFAULT_CHECK_UPDATES;
private static final boolean DEFAULT_CHECK_BETA_UPDATES;
/**
* Return the OpenRocket version number.
@ -30,6 +31,10 @@ public class BuildProperties {
public static boolean getDefaultCheckUpdates() {
return DEFAULT_CHECK_UPDATES;
}
public static boolean getDefaultCheckBetaUpdates() {
return DEFAULT_CHECK_BETA_UPDATES;
}
public static String getCopyrightYear() {
return BUILD_COPYRIGHT;
@ -69,6 +74,12 @@ public class BuildProperties {
DEFAULT_CHECK_UPDATES = Boolean.parseBoolean(value);
else
DEFAULT_CHECK_UPDATES = true;
value = PROPERTIES.getProperty("build.checkbetaupdates");
if (value != null)
DEFAULT_CHECK_BETA_UPDATES = Boolean.parseBoolean(value);
else
DEFAULT_CHECK_BETA_UPDATES = true;
BUILD_COPYRIGHT = PROPERTIES.getProperty("build.copyright", "2021");

View File

@ -14,26 +14,28 @@ import java.util.TreeMap;
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
*/
public class AssetHandler {
private static final Map<String, UpdatePlatform> mapExtensionToPlatform = new HashMap<>(); // Map file extensions to operating platform
private static final Map<String, UpdatePlatform[]> mapExtensionToPlatform = new HashMap<>(); // Map file extensions to operating platform
private static final Map<UpdatePlatform, String> mapPlatformToName = new HashMap<>(); // Map operating platform to a name
public enum UpdatePlatform {
WINDOWS,
MAC_OS,
LINUX,
UNIX,
JAR
}
static {
mapExtensionToPlatform.put(".dmg", UpdatePlatform.MAC_OS);
mapExtensionToPlatform.put(".exe", UpdatePlatform.WINDOWS);
mapExtensionToPlatform.put(".AppImage", UpdatePlatform.LINUX);
mapExtensionToPlatform.put(".sh", UpdatePlatform.LINUX);
mapExtensionToPlatform.put(".jar", UpdatePlatform.JAR);
mapExtensionToPlatform.put(".dmg", new UpdatePlatform[] {UpdatePlatform.MAC_OS});
mapExtensionToPlatform.put(".exe", new UpdatePlatform[] {UpdatePlatform.WINDOWS});
mapExtensionToPlatform.put(".AppImage", new UpdatePlatform[] {UpdatePlatform.LINUX, UpdatePlatform.UNIX});
mapExtensionToPlatform.put(".sh", new UpdatePlatform[] {UpdatePlatform.LINUX, UpdatePlatform.UNIX});
mapExtensionToPlatform.put(".jar", new UpdatePlatform[] {UpdatePlatform.JAR});
mapPlatformToName.put(UpdatePlatform.MAC_OS, "Mac OS");
mapPlatformToName.put(UpdatePlatform.WINDOWS, "Windows");
mapPlatformToName.put(UpdatePlatform.LINUX, "Linux");
mapPlatformToName.put(UpdatePlatform.UNIX, "Linux");
mapPlatformToName.put(UpdatePlatform.JAR, "JAR");
}
@ -45,13 +47,13 @@ public class AssetHandler {
* @return map with as key the operating platform name and as value the corresponding asset URL
*/
public static Map<UpdatePlatform, String> mapURLToPlatform(List<String> urls) {
Map<UpdatePlatform, String> output = new TreeMap<>();
Map<UpdatePlatform, String> output = new HashMap<>();
if (urls == null) return null;
for (String url : urls) {
for (String ext : mapExtensionToPlatform.keySet()) {
if (url.endsWith(ext)) {
output.put(mapExtensionToPlatform.get(ext), url);
output.put(mapExtensionToPlatform.get(ext)[0], url); // First Platform element is enough
}
}
}

View File

@ -3,6 +3,7 @@ package net.sf.openrocket.gui.dialogs;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URI;
@ -61,6 +62,7 @@ public class UpdateInfoDialog extends JDialog {
final JTextPane textPane = new JTextPane();
textPane.setEditable(false);
textPane.setContentType("text/html");
textPane.setMargin(new Insets(10, 10, 40, 10));
textPane.putClientProperty(JTextPane.HONOR_DISPLAY_PROPERTIES, true);
ReleaseInfo release = info.getLatestRelease();
@ -99,6 +101,7 @@ public class UpdateInfoDialog extends JDialog {
});
textPane.setText(sb.toString());
textPane.setCaretPosition(0); // Scroll to the top
panel.add(new JScrollPane(textPane), "left, grow, span, push, gapleft 40px, gapbottom 6px, wrap");

View File

@ -212,6 +212,18 @@ public class GeneralPreferencesPanel extends PreferencesPanel {
}
});
this.add(button, "right, wrap");
//// Check for beta releases
final JCheckBox betaUpdateBox = new JCheckBox(trans.get("pref.dlg.checkbox.CheckBetaupdates"));
betaUpdateBox.setToolTipText(trans.get("pref.dlg.checkbox.CheckBetaupdates.ttip"));
betaUpdateBox.setSelected(preferences.getCheckBetaUpdates());
betaUpdateBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
preferences.setCheckBetaUpdates(betaUpdateBox.isSelected());
}
});
this.add(betaUpdateBox, "gapleft para, wrap");
//// Open most recent file on startup
final JCheckBox openRecentOnStartupBox = new JCheckBox(trans.get("pref.dlg.but.openlast"));