mirror of
https://github.com/cryptomator/cryptomator.git
synced 2024-11-26 21:40:29 +00:00
added latestVersion and lastUpdateCheck to settings and integrated with update checker
This commit is contained in:
parent
b3789700e1
commit
db224e9e5c
@ -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<VaultSettings> 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<Settings> 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;
|
||||
}
|
||||
|
||||
|
@ -83,4 +83,7 @@ class SettingsJson {
|
||||
@JsonProperty("lastUpdateCheck")
|
||||
String lastUpdateCheck = Settings.DEFAULT_LAST_UPDATE_CHECK;
|
||||
|
||||
@JsonProperty("latestVersion")
|
||||
String latestVersion;
|
||||
|
||||
}
|
||||
|
@ -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<LocalDateTime> updateCheckTimeProperty() {
|
||||
|
@ -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);
|
||||
|
@ -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<Scene> 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();
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user