Prepared "check for updates" button

This commit is contained in:
Sebastian Stenzel
2019-07-31 17:32:34 +02:00
parent e7f7321393
commit fc9565e13c
3 changed files with 42 additions and 3 deletions

View File

@@ -2,6 +2,10 @@ package org.cryptomator.ui.fxapp;
import dagger.Module;
import dagger.Provides;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.concurrent.ScheduledService;
@@ -22,6 +26,13 @@ public abstract class UpdateCheckerModule {
private static final URI LATEST_VERSION_URI = URI.create("https://api.cryptomator.org/updates/latestVersion.json");
private static final Duration UPDATE_CHECK_INTERVAL = Duration.hours(3);
@Provides
@Named("checkingForUpdates")
@FxApplicationScoped
static ReadOnlyBooleanProperty provideCheckingForUpdates(ScheduledService<String> updateCheckerService) {
return updateCheckerService.runningProperty();
}
@Provides
@Named("latestVersion")
@FxApplicationScoped
@@ -41,8 +52,7 @@ public abstract class UpdateCheckerModule {
String userAgent = String.format("Cryptomator VersionChecker/%s %s %s (%s)", applicationVersion.orElse("SNAPSHOT"), SystemUtils.OS_NAME, SystemUtils.OS_VERSION, SystemUtils.OS_ARCH);
return HttpRequest.newBuilder() //
.uri(LATEST_VERSION_URI) //
.header("User-Agent", userAgent)
.build();
.header("User-Agent", userAgent).build();
}
@Provides

View File

@@ -1,24 +1,45 @@
package org.cryptomator.ui.preferences;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ContentDisplay;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.ui.common.FxController;
import javax.inject.Inject;
import javax.inject.Named;
@PreferencesScoped
public class UpdatesPreferencesController implements FxController {
private final Settings settings;
private final ObjectBinding<ContentDisplay> checkForUpdatesButtonState;
public CheckBox checkForUpdatesCheckbox;
@Inject
UpdatesPreferencesController(Settings settings) {
UpdatesPreferencesController(Settings settings, @Named("checkingForUpdates") ReadOnlyBooleanProperty checkingForUpdates) {
this.settings = settings;
this.checkForUpdatesButtonState = Bindings.when(checkingForUpdates).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY);
}
public void initialize() {
checkForUpdatesCheckbox.selectedProperty().bindBidirectional(settings.checkForUpdates());
}
@FXML
public void checkNow() {
}
/* Getter/Setter */
public ObjectBinding<ContentDisplay> checkForUpdatesButtonStateProperty() {
return checkForUpdatesButtonState;
}
public ContentDisplay getCheckForUpdatesButtonState() {
return checkForUpdatesButtonState.get();
}
}

View File

@@ -3,6 +3,8 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.ProgressIndicator?>
<?import javafx.scene.control.Button?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.cryptomator.ui.preferences.UpdatesPreferencesController"
@@ -12,5 +14,11 @@
</padding>
<children>
<CheckBox fx:id="checkForUpdatesCheckbox" text="%preferences.autoUpdateCheck"/>
<Button text="TODO check now!" defaultButton="true" onAction="#checkNow" contentDisplay="${controller.checkForUpdatesButtonState}">
<graphic>
<ProgressIndicator progress="-1" prefWidth="12" prefHeight="12"/>
</graphic>
</Button>
</children>
</VBox>