From 632d39bc9f38750c850fe12a4702b002fddfcfc4 Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Mon, 10 Jul 2023 14:50:06 +0200 Subject: [PATCH] added lastUpdateCheck to settings and integrated check in FXApplication start --- .../java/org/cryptomator/common/settings/Settings.java | 6 ++++++ .../org/cryptomator/common/settings/SettingsJson.java | 3 +++ src/main/java/org/cryptomator/ui/fxapp/FxApplication.java | 4 +++- .../ui/updatereminder/UpdateReminderController.java | 8 +++++++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cryptomator/common/settings/Settings.java b/src/main/java/org/cryptomator/common/settings/Settings.java index cfe30641d..90e6b4408 100644 --- a/src/main/java/org/cryptomator/common/settings/Settings.java +++ b/src/main/java/org/cryptomator/common/settings/Settings.java @@ -26,6 +26,7 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.NodeOrientation; import java.util.function.Consumer; +import java.time.LocalDate; public class Settings { @@ -44,6 +45,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 final ObservableList directories; public final BooleanProperty askedForUpdateCheck; @@ -67,6 +69,7 @@ public class Settings { public final StringProperty displayConfiguration; public final StringProperty language; public final StringProperty mountService; + public final StringProperty lastUpdateCheck; private Consumer saveCmd; @@ -104,6 +107,7 @@ public class Settings { this.displayConfiguration = new SimpleStringProperty(this, "displayConfiguration", json.displayConfiguration); 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.directories.addAll(json.directories.stream().map(VaultSettings::new).toList()); @@ -131,6 +135,7 @@ public class Settings { displayConfiguration.addListener(this::somethingChanged); language.addListener(this::somethingChanged); mountService.addListener(this::somethingChanged); + lastUpdateCheck.addListener(this::somethingChanged); } @SuppressWarnings("deprecation") @@ -185,6 +190,7 @@ public class Settings { json.displayConfiguration = displayConfiguration.get(); json.language = language.get(); json.mountService = mountService.get(); + json.lastUpdateCheck = lastUpdateCheck.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 4bd23bec7..977e1d3cd 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(value = "preferredVolumeImpl", access = JsonProperty.Access.WRITE_ONLY) // WRITE_ONLY means value is "written" into the java object during deserialization. Upvote this: https://github.com/FasterXML/jackson-annotations/issues/233 String preferredVolumeImpl; + @JsonProperty("lastUpdateCheck") + String lastUpdateCheck = Settings.DEFAULT_LAST_UPDATE_CHECK; + } diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java index 47f18d702..93ac96e9b 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java @@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.inject.Named; import javafx.application.Platform; +import java.time.LocalDate; import java.util.concurrent.TimeUnit; @FxApplicationScoped @@ -67,7 +68,8 @@ public class FxApplication { LOG.error("Failed to show main window", error); return null; }); - if(!settings.checkForUpdates.getValue()){ + + if(LocalDate.parse(settings.lastUpdateCheck.get()).isBefore(LocalDate.now().minusDays(14)) && !settings.checkForUpdates.getValue()){ appWindows.showUpdateReminderWindow(); } diff --git a/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderController.java b/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderController.java index 8a5403411..fe852b0fe 100644 --- a/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderController.java +++ b/src/main/java/org/cryptomator/ui/updatereminder/UpdateReminderController.java @@ -8,6 +8,9 @@ import javax.inject.Inject; import javafx.fxml.FXML; import javafx.stage.Stage; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + @UpdateReminderScoped public class UpdateReminderController implements FxController { @@ -25,17 +28,20 @@ public class UpdateReminderController implements FxController { @FXML public void cancel() { + settings.lastUpdateCheck.set(LocalDate.now().format(DateTimeFormatter.ISO_DATE)); window.close(); } @FXML public void once() { + settings.lastUpdateCheck.set(LocalDate.now().format(DateTimeFormatter.ISO_DATE)); updateChecker.checkForUpdatesNow(); window.close(); } @FXML public void automatically() { - settings.checkForUpdates.set(true); + settings.lastUpdateCheck.set(LocalDate.now().format(DateTimeFormatter.ISO_DATE)); updateChecker.checkForUpdatesNow(); + settings.checkForUpdates.set(true); window.close(); }