From db224e9e5c3c1d943c45e78b66dd1f9e2143b31c Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Fri, 8 Mar 2024 09:58:59 +0100 Subject: [PATCH] added latestVersion and lastUpdateCheck to settings and integrated with update checker --- .../cryptomator/common/settings/Settings.java | 6 +++++- .../common/settings/SettingsJson.java | 3 +++ .../cryptomator/ui/fxapp/UpdateChecker.java | 21 ++++++++++++++++++- .../UpdatesPreferencesController.java | 2 +- .../UpdateReminderComponent.java | 6 ++++-- .../UpdateReminderController.java | 5 ++--- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/cryptomator/common/settings/Settings.java b/src/main/java/org/cryptomator/common/settings/Settings.java index 4e0e0df97..6c46654c1 100644 --- a/src/main/java/org/cryptomator/common/settings/Settings.java +++ b/src/main/java/org/cryptomator/common/settings/Settings.java @@ -44,7 +44,7 @@ public class Settings { static final String DEFAULT_KEYCHAIN_PROVIDER = SystemUtils.IS_OS_WINDOWS ? "org.cryptomator.windows.keychain.WindowsProtectedKeychainAccess" : SystemUtils.IS_OS_MAC ? "org.cryptomator.macos.keychain.MacSystemKeychainAccess" : "org.cryptomator.linux.keychain.SecretServiceKeychainAccess"; static final String DEFAULT_USER_INTERFACE_ORIENTATION = NodeOrientation.LEFT_TO_RIGHT.name(); static final boolean DEFAULT_SHOW_MINIMIZE_BUTTON = false; - static final String DEFAULT_LAST_UPDATE_CHECK = "2000-01-01"; + public static final String DEFAULT_LAST_UPDATE_CHECK = "2000-01-01T10:00:00"; public final ObservableList directories; public final BooleanProperty askedForUpdateCheck; @@ -68,6 +68,7 @@ public class Settings { public final StringProperty language; public final StringProperty mountService; public final StringProperty lastUpdateCheck; + public final StringProperty latestVersion; private Consumer saveCmd; @@ -105,6 +106,7 @@ public class Settings { this.language = new SimpleStringProperty(this, "language", json.language); this.mountService = new SimpleStringProperty(this, "mountService", json.mountService); this.lastUpdateCheck = new SimpleStringProperty(this, "lastUpdateCheck", json.lastUpdateCheck); + this.latestVersion = new SimpleStringProperty(this, "latestVersion", json.latestVersion); this.directories.addAll(json.directories.stream().map(VaultSettings::new).toList()); @@ -132,6 +134,7 @@ public class Settings { language.addListener(this::somethingChanged); mountService.addListener(this::somethingChanged); lastUpdateCheck.addListener(this::somethingChanged); + latestVersion.addListener(this::somethingChanged); } @SuppressWarnings("deprecation") @@ -186,6 +189,7 @@ public class Settings { json.language = language.get(); json.mountService = mountService.get(); json.lastUpdateCheck = lastUpdateCheck.get(); + json.latestVersion = latestVersion.get(); return json; } diff --git a/src/main/java/org/cryptomator/common/settings/SettingsJson.java b/src/main/java/org/cryptomator/common/settings/SettingsJson.java index 2c7c963da..2dbb514c0 100644 --- a/src/main/java/org/cryptomator/common/settings/SettingsJson.java +++ b/src/main/java/org/cryptomator/common/settings/SettingsJson.java @@ -83,4 +83,7 @@ class SettingsJson { @JsonProperty("lastUpdateCheck") String lastUpdateCheck = Settings.DEFAULT_LAST_UPDATE_CHECK; + @JsonProperty("latestVersion") + String latestVersion; + } diff --git a/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java b/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java index e2e423f84..369ab168a 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java +++ b/src/main/java/org/cryptomator/ui/fxapp/UpdateChecker.java @@ -16,7 +16,10 @@ import javafx.concurrent.ScheduledService; import javafx.concurrent.Worker; import javafx.concurrent.WorkerStateEvent; import javafx.util.Duration; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; @FxApplicationScoped public class UpdateChecker { @@ -38,6 +41,21 @@ public class UpdateChecker { this.env = env; this.settings = settings; this.updateCheckerService = updateCheckerService; + this.latestVersionProperty.set(settings.latestVersion.get()); + var dateTimeString = !settings.lastUpdateCheck.get().isEmpty() ? settings.lastUpdateCheck.get() : Settings.DEFAULT_LAST_UPDATE_CHECK; + try { + LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, DateTimeFormatter.ISO_DATE_TIME); + this.updateCheckTimeProperty.set(dateTime); + } catch (DateTimeParseException e) { + try { + LocalDate date = LocalDate.parse(dateTimeString, DateTimeFormatter.ISO_DATE); + this.updateCheckTimeProperty.set(LocalDateTime.of(date, LocalDate.MIN.atStartOfDay().toLocalTime())); + } catch (DateTimeParseException ex) { + LOG.error("The date/time format is invalid:" + dateTimeString, ex); + } + } + this.latestVersionProperty().addListener((_, _, newValue) -> settings.latestVersion.set(newValue)); + this.updateCheckTimeProperty().addListener((_,_,newValue) -> settings.lastUpdateCheck.set(newValue.toString())); } public void automaticallyCheckForUpdatesIfEnabled() { @@ -69,6 +87,7 @@ public class UpdateChecker { String latestVersion = updateCheckerService.getValue(); LOG.info("Current version: {}, latest version: {}", getCurrentVersion(), latestVersion); updateCheckTimeProperty.set(LocalDateTime.now()); + //settings.lastUpdateCheck.set(updateCheckTimeProperty.get().toString()); latestVersionProperty.set(latestVersion); state.set(UpdateCheckState.CHECK_SUCCESSFUL); } @@ -95,7 +114,7 @@ public class UpdateChecker { } public String getCurrentVersion() { - return env.getAppVersion(); + return "1.12.3";//env.getAppVersion(); } public ObjectProperty updateCheckTimeProperty() { diff --git a/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java b/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java index 57ebc9706..f168b0a5c 100644 --- a/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java +++ b/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java @@ -77,7 +77,7 @@ public class UpdatesPreferencesController implements FxController { checkForUpdatesCheckbox.selectedProperty().bindBidirectional(settings.checkForUpdates); DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.getDefault()); - updateCheckDateFormattedLabel.arg1Property().bind(Bindings.createStringBinding(() -> (updateCheckDateProperty.get() != null) ? updateCheckDateProperty.get().format(formatter) : "-", updateCheckDateProperty)); + updateCheckDateFormattedLabel.arg1Property().bind(Bindings.createStringBinding(() -> (!updateCheckDateProperty.get().equals(LocalDateTime.parse(Settings.DEFAULT_LAST_UPDATE_CHECK)) && latestVersionProperty().isNotNull().get() ) ? updateCheckDateProperty.get().format(formatter) : "-", updateCheckDateProperty, latestVersionProperty())); BooleanBinding isUpdateCheckFailed = updateCheckStateProperty.isEqualTo(UpdateChecker.UpdateCheckState.CHECK_FAILED); checkFailedHBox.managedProperty().bind(isUpdateCheckFailed); diff --git a/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderComponent.java b/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderComponent.java index aa13f30da..d51d8df82 100644 --- a/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderComponent.java +++ b/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderComponent.java @@ -5,10 +5,11 @@ import dagger.Subcomponent; import org.cryptomator.common.settings.Settings; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; +import org.cryptomator.ui.fxapp.UpdateChecker; import javafx.scene.Scene; import javafx.stage.Stage; -import java.time.LocalDate; +import java.time.LocalDateTime; @UpdateReminderScoped @Subcomponent(modules = {UpdateReminderModule.class}) @@ -21,9 +22,10 @@ public interface UpdateReminderComponent { Lazy updateReminderScene(); Settings settings(); + UpdateChecker updateChecker(); default void checkAndShowUpdateReminderWindow() { - if (LocalDate.parse(settings().lastUpdateCheck.get()).isBefore(LocalDate.now().minusDays(14)) && !settings().checkForUpdates.getValue()) { + if (updateChecker().updateCheckTimeProperty().get().isBefore(LocalDateTime.now().minusDays(14)) && !settings().checkForUpdates.getValue()) { Stage stage = window(); stage.setScene(updateReminderScene().get()); stage.sizeToScene(); diff --git a/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderController.java b/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderController.java index 28ae0b5c6..bd70115e3 100644 --- a/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderController.java +++ b/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderController.java @@ -8,6 +8,7 @@ import javax.inject.Inject; import javafx.fxml.FXML; import javafx.stage.Stage; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @UpdateReminderScoped @@ -27,20 +28,18 @@ public class UpdateReminderController implements FxController { @FXML public void cancel() { - settings.lastUpdateCheck.set(LocalDate.now().format(DateTimeFormatter.ISO_DATE)); + updateChecker.updateCheckTimeProperty().set(LocalDateTime.now()); window.close(); } @FXML public void once() { - settings.lastUpdateCheck.set(LocalDate.now().format(DateTimeFormatter.ISO_DATE)); updateChecker.checkForUpdatesNow(); window.close(); } @FXML public void automatically() { - settings.lastUpdateCheck.set(LocalDate.now().format(DateTimeFormatter.ISO_DATE)); updateChecker.checkForUpdatesNow(); settings.checkForUpdates.set(true); window.close();