|
@@ -1,28 +1,36 @@
|
|
|
package org.cryptomator.ui.preferences;
|
|
|
|
|
|
import javafx.beans.binding.Bindings;
|
|
|
+import javafx.beans.binding.BooleanBinding;
|
|
|
import javafx.beans.binding.ObjectBinding;
|
|
|
-import javafx.beans.property.ReadOnlyBooleanProperty;
|
|
|
+import javafx.beans.property.ReadOnlyStringProperty;
|
|
|
import javafx.fxml.FXML;
|
|
|
import javafx.scene.control.CheckBox;
|
|
|
import javafx.scene.control.ContentDisplay;
|
|
|
+import javafx.util.Duration;
|
|
|
import org.cryptomator.common.settings.Settings;
|
|
|
import org.cryptomator.ui.common.FxController;
|
|
|
+import org.cryptomator.ui.fxapp.UpdateChecker;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
-import javax.inject.Named;
|
|
|
|
|
|
@PreferencesScoped
|
|
|
public class UpdatesPreferencesController implements FxController {
|
|
|
|
|
|
private final Settings settings;
|
|
|
+ private final UpdateChecker updateChecker;
|
|
|
private final ObjectBinding<ContentDisplay> checkForUpdatesButtonState;
|
|
|
+ private final ReadOnlyStringProperty latestVersion;
|
|
|
+ private final BooleanBinding updateAvailable;
|
|
|
public CheckBox checkForUpdatesCheckbox;
|
|
|
|
|
|
@Inject
|
|
|
- UpdatesPreferencesController(Settings settings, @Named("checkingForUpdates") ReadOnlyBooleanProperty checkingForUpdates) {
|
|
|
+ UpdatesPreferencesController(Settings settings, UpdateChecker updateChecker) {
|
|
|
this.settings = settings;
|
|
|
- this.checkForUpdatesButtonState = Bindings.when(checkingForUpdates).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY);
|
|
|
+ this.updateChecker = updateChecker;
|
|
|
+ this.checkForUpdatesButtonState = Bindings.when(updateChecker.checkingForUpdatesProperty()).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY);
|
|
|
+ this.latestVersion = updateChecker.latestVersionProperty();
|
|
|
+ this.updateAvailable = latestVersion.isNotNull();
|
|
|
}
|
|
|
|
|
|
public void initialize() {
|
|
@@ -31,9 +39,10 @@ public class UpdatesPreferencesController implements FxController {
|
|
|
|
|
|
@FXML
|
|
|
public void checkNow() {
|
|
|
+ updateChecker.startCheckingForUpdates(Duration.ZERO);
|
|
|
}
|
|
|
|
|
|
- /* Getter/Setter */
|
|
|
+ /* Observable Properties */
|
|
|
|
|
|
public ObjectBinding<ContentDisplay> checkForUpdatesButtonStateProperty() {
|
|
|
return checkForUpdatesButtonState;
|
|
@@ -42,4 +51,20 @@ public class UpdatesPreferencesController implements FxController {
|
|
|
public ContentDisplay getCheckForUpdatesButtonState() {
|
|
|
return checkForUpdatesButtonState.get();
|
|
|
}
|
|
|
+
|
|
|
+ public ReadOnlyStringProperty latestVersionProperty() {
|
|
|
+ return latestVersion;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getLatestVersion() {
|
|
|
+ return latestVersion.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ public BooleanBinding updateAvailableProperty() {
|
|
|
+ return updateAvailable;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isUpdateAvailable() {
|
|
|
+ return updateAvailable.get();
|
|
|
+ }
|
|
|
}
|