This commit is contained in:
Sebastian Stenzel
2015-09-26 16:39:18 +02:00
parent 6b073c1499
commit 485df3aa71
5 changed files with 75 additions and 7 deletions

View File

@@ -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<String> semVerComparator;
private final ExecutorService executor;
@Inject
public WelcomeController(Application app, @Named("SemVer") Comparator<String> semVerComparator, ExecutorService executor) {
public WelcomeController(Application app, Settings settings, @Named("SemVer") Comparator<String> 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<? extends Boolean> 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);
});
}
}

View File

@@ -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<Vault> 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;
}
}

View File

@@ -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;

View File

@@ -17,12 +17,24 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.ProgressIndicator?>
<AnchorPane xmlns:fx="http://javafx.com/fxml">
<children>
<Label AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="20.0" prefWidth="400.0" alignment="CENTER" style="-fx-font-size: 1.5em;" text="%welcome.welcomeLabel"/>
<Hyperlink AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="50.0" prefWidth="400.0" alignment="CENTER" fx:id="updateLink" onAction="#didClickUpdateLink" visible="false"/>
<VBox AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="20.0" prefWidth="400.0" alignment="CENTER" spacing="10.0">
<Label alignment="CENTER" style="-fx-font-size: 1.5em;" text="%welcome.welcomeLabel"/>
<HBox alignment="CENTER" spacing="5.0">
<CheckBox fx:id="checkForUpdatesCheckbox" />
<Label fx:id="checkForUpdatesStatus" text="%welcome.checkForUpdates.label.checkboxLabel"/>
<ProgressIndicator fx:id="checkForUpdatesIndicator" progress="-1" prefWidth="15.0" prefHeight="15.0" visible="false"/>
</HBox>
<Hyperlink alignment="CENTER" fx:id="updateLink" onAction="#didClickUpdateLink" visible="false" />
</VBox>
<ImageView fx:id="botImageView" AnchorPane.leftAnchor="100.0" AnchorPane.topAnchor="200.0" fitHeight="200.0" preserveRatio="true" smooth="false"/>

View File

@@ -18,6 +18,8 @@ main.addDirectory.contextMenu.open=Add existing vault
# welcome.fxml
welcome.welcomeLabel=Welcome to Cryptomator
welcome.addButtonInstructionLabel=Start by adding a new vault
welcome.checkForUpdates.label.checkboxLabel=Check for Updates
welcome.checkForUpdates.label.currentlyChecking=Checking for Updates...
welcome.newVersionMessage=Version %s can be downloaded. This is %s.
# initialize.fxml