|
@@ -3,10 +3,11 @@ package org.cryptomator.ui.vaultoptions;
|
|
|
import org.cryptomator.common.settings.WhenUnlocked;
|
|
|
import org.cryptomator.common.vaults.Vault;
|
|
|
import org.cryptomator.ui.common.FxController;
|
|
|
-import org.cryptomator.ui.health.HealthCheckComponent;
|
|
|
+import org.cryptomator.ui.controls.NumericTextField;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
import javafx.beans.Observable;
|
|
|
+import javafx.beans.binding.Bindings;
|
|
|
import javafx.fxml.FXML;
|
|
|
import javafx.scene.control.CheckBox;
|
|
|
import javafx.scene.control.ChoiceBox;
|
|
@@ -23,18 +24,18 @@ public class GeneralVaultOptionsController implements FxController {
|
|
|
|
|
|
private final Stage window;
|
|
|
private final Vault vault;
|
|
|
- private final HealthCheckComponent.Builder healthCheckWindow;
|
|
|
private final ResourceBundle resourceBundle;
|
|
|
|
|
|
public TextField vaultName;
|
|
|
public CheckBox unlockOnStartupCheckbox;
|
|
|
public ChoiceBox<WhenUnlocked> actionAfterUnlockChoiceBox;
|
|
|
+ public CheckBox lockAfterTimeCheckbox;
|
|
|
+ public NumericTextField lockTimeInMinutesTextField;
|
|
|
|
|
|
@Inject
|
|
|
- GeneralVaultOptionsController(@VaultOptionsWindow Stage window, @VaultOptionsWindow Vault vault, HealthCheckComponent.Builder healthCheckWindow, ResourceBundle resourceBundle) {
|
|
|
+ GeneralVaultOptionsController(@VaultOptionsWindow Stage window, @VaultOptionsWindow Vault vault, ResourceBundle resourceBundle) {
|
|
|
this.window = window;
|
|
|
this.vault = vault;
|
|
|
- this.healthCheckWindow = healthCheckWindow;
|
|
|
this.resourceBundle = resourceBundle;
|
|
|
}
|
|
|
|
|
@@ -47,6 +48,8 @@ public class GeneralVaultOptionsController implements FxController {
|
|
|
actionAfterUnlockChoiceBox.getItems().addAll(WhenUnlocked.values());
|
|
|
actionAfterUnlockChoiceBox.valueProperty().bindBidirectional(vault.getVaultSettings().actionAfterUnlock());
|
|
|
actionAfterUnlockChoiceBox.setConverter(new WhenUnlockedConverter(resourceBundle));
|
|
|
+ lockAfterTimeCheckbox.selectedProperty().bindBidirectional(vault.getVaultSettings().autoLockWhenIdle());
|
|
|
+ Bindings.bindBidirectional(lockTimeInMinutesTextField.textProperty(), vault.getVaultSettings().autoLockIdleSeconds(), new IdleTimeSecondsConverter());
|
|
|
}
|
|
|
|
|
|
private void trimVaultNameOnFocusLoss(Observable observable, Boolean wasFocussed, Boolean isFocussed) {
|
|
@@ -64,12 +67,6 @@ public class GeneralVaultOptionsController implements FxController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @FXML
|
|
|
- public void showHealthCheck() {
|
|
|
- healthCheckWindow.vault(vault).build().showHealthCheckWindow();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
private static class WhenUnlockedConverter extends StringConverter<WhenUnlocked> {
|
|
|
|
|
|
private final ResourceBundle resourceBundle;
|
|
@@ -89,4 +86,22 @@ public class GeneralVaultOptionsController implements FxController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static class IdleTimeSecondsConverter extends StringConverter<Number> {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString(Number seconds) {
|
|
|
+ int minutes = seconds.intValue() / 60; // int-truncate
|
|
|
+ return Integer.toString(minutes);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Number fromString(String string) {
|
|
|
+ try {
|
|
|
+ int minutes = Integer.valueOf(string);
|
|
|
+ return minutes * 60;
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|