mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-19 19:21:27 +00:00
simplify app version code
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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); //
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user