diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java index 5c915c81d..48f5c2e4a 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java @@ -26,6 +26,7 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.lang3.SystemUtils; +import org.cryptomator.ui.settings.Settings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,9 +35,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import javafx.application.Application; import javafx.application.Platform; +import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.scene.control.CheckBox; import javafx.scene.control.Hyperlink; +import javafx.scene.control.Label; +import javafx.scene.control.ProgressIndicator; import javafx.scene.image.Image; import javafx.scene.image.ImageView; @@ -48,16 +53,27 @@ public class WelcomeController extends AbstractFXMLViewController { @FXML private ImageView botImageView; + @FXML + private CheckBox checkForUpdatesCheckbox; + + @FXML + private Label checkForUpdatesStatus; + + @FXML + private ProgressIndicator checkForUpdatesIndicator; + @FXML private Hyperlink updateLink; private final Application app; + private final Settings settings; private final Comparator semVerComparator; private final ExecutorService executor; @Inject - public WelcomeController(Application app, @Named("SemVer") Comparator semVerComparator, ExecutorService executor) { + public WelcomeController(Application app, Settings settings, @Named("SemVer") Comparator semVerComparator, ExecutorService executor) { this.app = app; + this.settings = settings; this.semVerComparator = semVerComparator; this.executor = executor; } @@ -74,11 +90,32 @@ public class WelcomeController extends AbstractFXMLViewController { @Override public void initialize() { - this.botImageView.setImage(new Image(WelcomeController.class.getResource("/bot_welcome.png").toString())); - executor.execute(this::checkForUpdates); + botImageView.setImage(new Image(getClass().getResource("/bot_welcome.png").toString())); + checkForUpdatesCheckbox.setSelected(settings.isCheckForUpdatesEnabled()); + checkForUpdatesCheckbox.selectedProperty().addListener(this::checkForUpdatesChanged); + if (settings.isCheckForUpdatesEnabled()) { + executor.execute(this::checkForUpdates); + } + } + + // **************************************** + // Check for updates + // **************************************** + + private void checkForUpdatesChanged(ObservableValue observable, Boolean oldValue, Boolean newValue) { + assert newValue != null; + settings.setCheckForUpdatesEnabled(newValue); + if (newValue) { + executor.execute(this::checkForUpdates); + } } private void checkForUpdates() { + Platform.runLater(() -> { + checkForUpdatesCheckbox.setVisible(false); + checkForUpdatesStatus.setText(resourceBundle.getString("welcome.checkForUpdates.label.currentlyChecking")); + checkForUpdatesIndicator.setVisible(true); + }); final HttpClient client = new HttpClient(); final HttpMethod method = new GetMethod("https://cryptomator.org/downloads/latestVersion.json"); client.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); @@ -94,6 +131,12 @@ public class WelcomeController extends AbstractFXMLViewController { } } catch (IOException e) { // no error handling required. Maybe next time the version check is successful. + } finally { + Platform.runLater(() -> { + checkForUpdatesCheckbox.setVisible(true); + checkForUpdatesStatus.setText(resourceBundle.getString("welcome.checkForUpdates.label.checkboxLabel")); + checkForUpdatesIndicator.setVisible(false); + }); } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/settings/Settings.java b/main/ui/src/main/java/org/cryptomator/ui/settings/Settings.java index cb4445b3b..6215e666e 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/settings/Settings.java +++ b/main/ui/src/main/java/org/cryptomator/ui/settings/Settings.java @@ -16,13 +16,15 @@ import org.cryptomator.ui.model.Vault; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -@JsonPropertyOrder(value = {"directories"}) +@JsonPropertyOrder(value = {"directories", "checkForUpdatesEnabled"}) public class Settings implements Serializable { private static final long serialVersionUID = 7609959894417878744L; private List directories; + private Boolean checkForUpdatesEnabled; + /** * Package-private constructor; use {@link SettingsProvider}. */ @@ -43,4 +45,13 @@ public class Settings implements Serializable { this.directories = directories; } + public boolean isCheckForUpdatesEnabled() { + // not false meaning "null or true", so that true is the default value, if not setting exists yet. + return !Boolean.FALSE.equals(checkForUpdatesEnabled); + } + + public void setCheckForUpdatesEnabled(boolean checkForUpdatesEnabled) { + this.checkForUpdatesEnabled = checkForUpdatesEnabled; + } + } diff --git a/main/ui/src/main/resources/css/mac_theme.css b/main/ui/src/main/resources/css/mac_theme.css index 4680a4bb9..7f74cc715 100644 --- a/main/ui/src/main/resources/css/mac_theme.css +++ b/main/ui/src/main/resources/css/mac_theme.css @@ -299,7 +299,7 @@ .check-box { -fx-label-padding: 0 0 0 3px; - -fx-text-fill: -fx-text-background-color; + -fx-text-fill: COLOR_TEXT; } .check-box > .box { -fx-padding: 3px; diff --git a/main/ui/src/main/resources/fxml/welcome.fxml b/main/ui/src/main/resources/fxml/welcome.fxml index 0c8ccd0de..8c939b0f4 100644 --- a/main/ui/src/main/resources/fxml/welcome.fxml +++ b/main/ui/src/main/resources/fxml/welcome.fxml @@ -17,12 +17,24 @@ + + + + -