Browse Source

simplify app version code

Armin Schrenk 2 years ago
parent
commit
80b5b6af00

+ 6 - 2
src/main/java/org/cryptomator/common/Environment.java

@@ -92,8 +92,12 @@ public class Environment {
 		return getPath(MOUNTPOINT_DIR_PROP_NAME).map(this::replaceHomeDir);
 	}
 
-	public Optional<String> getAppVersion() {
-		return Optional.ofNullable(System.getProperty(APP_VERSION_PROP_NAME));
+	/**
+	 * Returns the app version defined in the {@value APP_VERSION_PROP_NAME} property or returns "SNAPSHOT".
+	 * @return App version or "SNAPSHOT", if undefined
+	 */
+	public String getAppVersion() {
+		return System.getProperty(APP_VERSION_PROP_NAME, "SNAPSHOT");
 	}
 
 	public Optional<String> getBuildNumber() {

+ 1 - 1
src/main/java/org/cryptomator/launcher/Cryptomator.java

@@ -81,7 +81,7 @@ public class Cryptomator {
 	private int run(String[] args) {
 		logConfig.init();
 		LOG.debug("Dagger graph initialized after {}ms", System.currentTimeMillis() - STARTUP_TIME);
-		LOG.info("Starting Cryptomator {} on {} {} ({})", env.getAppVersion().orElse("SNAPSHOT"), SystemUtils.OS_NAME, SystemUtils.OS_VERSION, SystemUtils.OS_ARCH);
+		LOG.info("Starting Cryptomator {} on {} {} ({})", env.getAppVersion(), SystemUtils.OS_NAME, SystemUtils.OS_VERSION, SystemUtils.OS_ARCH);
 		debugMode.initialize();
 		supportedLanguages.applyPreferred();
 

+ 1 - 1
src/main/java/org/cryptomator/ui/common/ErrorController.java

@@ -77,7 +77,7 @@ public class ErrorController implements FxController {
 		var enhancedTemplate = String.format(REPORT_BODY_TEMPLATE, //
 				System.getProperty("os.name"), //
 				System.getProperty("os.version"), //
-				environment.getAppVersion().orElse("undefined"), //
+				environment.getAppVersion(), //
 				environment.getBuildNumber().orElse("undefined"));
 		var body = URLEncoder.encode(enhancedTemplate, StandardCharsets.UTF_8);
 		application.getHostServices().showDocument(REPORT_URL_FORMAT.formatted(title, body));

+ 5 - 10
src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java

@@ -9,14 +9,12 @@ import javax.inject.Inject;
 import javax.inject.Named;
 import javafx.beans.binding.BooleanBinding;
 import javafx.beans.property.ReadOnlyStringProperty;
-import javafx.beans.property.SimpleStringProperty;
 import javafx.beans.property.StringProperty;
 import javafx.concurrent.ScheduledService;
 import javafx.concurrent.Worker;
 import javafx.concurrent.WorkerStateEvent;
 import javafx.util.Duration;
 import java.util.Comparator;
-import java.util.Optional;
 
 @FxApplicationScoped
 public class UpdateChecker {
@@ -25,8 +23,7 @@ public class UpdateChecker {
 	private static final Duration AUTOCHECK_DELAY = Duration.seconds(5);
 
 	private final Settings settings;
-	private final Optional<String> applicationVersion;
-	private final StringProperty currentVersionProperty;
+	private final String currentVersion;
 	private final StringProperty latestVersionProperty;
 	private final Comparator<String> semVerComparator;
 	private final ScheduledService<String> updateCheckerService;
@@ -34,11 +31,10 @@ public class UpdateChecker {
 	@Inject
 	UpdateChecker(Settings settings, Environment env, @Named("latestVersion") StringProperty latestVersionProperty, @Named("SemVer") Comparator<String> semVerComparator, ScheduledService<String> updateCheckerService) {
 		this.settings = settings;
-		this.applicationVersion = env.getAppVersion();
 		this.latestVersionProperty = latestVersionProperty;
 		this.semVerComparator = semVerComparator;
 		this.updateCheckerService = updateCheckerService;
-		this.currentVersionProperty = new SimpleStringProperty(applicationVersion.orElse("SNAPSHOT"));
+		this.currentVersion = env.getAppVersion();
 	}
 
 	public void automaticallyCheckForUpdatesIfEnabled() {
@@ -66,11 +62,10 @@ public class UpdateChecker {
 	}
 
 	private void checkSucceeded(WorkerStateEvent event) {
-		String currentVersion = applicationVersion.orElse(null);
 		String latestVersion = updateCheckerService.getValue();
 		LOG.info("Current version: {}, lastest version: {}", currentVersion, latestVersion);
 
-		if (currentVersion == null || semVerComparator.compare(currentVersion, latestVersion) < 0) {
+		if (semVerComparator.compare(currentVersion, latestVersion) < 0) {
 			// update is available
 			latestVersionProperty.set(latestVersion);
 		} else {
@@ -92,8 +87,8 @@ public class UpdateChecker {
 		return latestVersionProperty;
 	}
 
-	public ReadOnlyStringProperty currentVersionProperty() {
-		return currentVersionProperty;
+	public String getCurrentVersion() {
+		return currentVersion;
 	}
 
 }

+ 1 - 1
src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java

@@ -56,7 +56,7 @@ public abstract class UpdateCheckerModule {
 	@FxApplicationScoped
 	static HttpRequest provideCheckForUpdatesRequest(Environment env) {
 		String userAgent = String.format("Cryptomator VersionChecker/%s %s %s (%s)", //
-				env.getAppVersion().orElse("SNAPSHOT"), //
+				env.getAppVersion(), //
 				SystemUtils.OS_NAME, //
 				SystemUtils.OS_VERSION, //
 				SystemUtils.OS_ARCH); //

+ 5 - 5
src/main/java/org/cryptomator/ui/preferences/AboutController.java

@@ -18,14 +18,14 @@ public class AboutController implements FxController {
 	private static final Logger LOG = LoggerFactory.getLogger(AboutController.class);
 
 	private final String thirdPartyLicenseText;
-	private final String applicationVersion;
+	private final String fullApplicationVersion;
 
 	@Inject
 	AboutController(UpdateChecker updateChecker, Environment environment) {
 		this.thirdPartyLicenseText = loadThirdPartyLicenseFile();
-		StringBuilder sb = new StringBuilder(updateChecker.currentVersionProperty().get());
+		StringBuilder sb = new StringBuilder(environment.getAppVersion());
 		environment.getBuildNumber().ifPresent(s -> sb.append(" (").append(s).append(')'));
-		this.applicationVersion = sb.toString();
+		this.fullApplicationVersion = sb.toString();
 	}
 
 	private static String loadThirdPartyLicenseFile() {
@@ -43,7 +43,7 @@ public class AboutController implements FxController {
 		return thirdPartyLicenseText;
 	}
 
-	public String getApplicationVersion() {
-		return applicationVersion;
+	public String getFullApplicationVersion() {
+		return fullApplicationVersion;
 	}
 }

+ 3 - 7
src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java

@@ -24,7 +24,7 @@ public class UpdatesPreferencesController implements FxController {
 	private final UpdateChecker updateChecker;
 	private final ObjectBinding<ContentDisplay> checkForUpdatesButtonState;
 	private final ReadOnlyStringProperty latestVersion;
-	private final ReadOnlyStringProperty currentVersion;
+	private final String currentVersion;
 	private final BooleanBinding updateAvailable;
 
 	/* FXML */
@@ -38,7 +38,7 @@ public class UpdatesPreferencesController implements FxController {
 		this.checkForUpdatesButtonState = Bindings.when(updateChecker.checkingForUpdatesProperty()).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY);
 		this.latestVersion = updateChecker.latestVersionProperty();
 		this.updateAvailable = latestVersion.isNotNull();
-		this.currentVersion = updateChecker.currentVersionProperty();
+		this.currentVersion = updateChecker.getCurrentVersion();
 	}
 
 	public void initialize() {
@@ -73,12 +73,8 @@ public class UpdatesPreferencesController implements FxController {
 		return latestVersion.get();
 	}
 
-	public ReadOnlyStringProperty currentVersionProperty() {
-		return currentVersion;
-	}
-
 	public String getCurrentVersion() {
-		return currentVersion.get();
+		return currentVersion;
 	}
 
 	public BooleanBinding updateAvailableProperty() {

+ 1 - 1
src/main/resources/fxml/preferences_about.fxml

@@ -21,7 +21,7 @@
 				<Image url="@../img/logo.png"/>
 			</ImageView>
 			<VBox spacing="3" HBox.hgrow="ALWAYS" alignment="CENTER_LEFT">
-				<FormattedLabel styleClass="label-extra-large" format="Cryptomator %s" arg1="${controller.applicationVersion}"/>
+				<FormattedLabel styleClass="label-extra-large" format="Cryptomator %s" arg1="${controller.fullApplicationVersion}"/>
 				<Label text="© 2016 – 2022 Skymatic GmbH"/>
 			</VBox>
 		</HBox>