mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-21 10:06:55 -04:00
refactoring
This commit is contained in:
@@ -5,21 +5,25 @@ import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.ui.changepassword.NewPasswordController;
|
||||
import org.cryptomator.ui.changepassword.PasswordStrengthUtil;
|
||||
import org.cryptomator.ui.common.DefaultSceneFactory;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.common.FxControllerKey;
|
||||
import org.cryptomator.ui.common.FxmlFile;
|
||||
import org.cryptomator.ui.common.FxmlLoaderFactory;
|
||||
import org.cryptomator.ui.common.FxmlScene;
|
||||
import org.cryptomator.ui.changepassword.NewPasswordController;
|
||||
import org.cryptomator.ui.changepassword.PasswordStrengthUtil;
|
||||
import org.cryptomator.ui.common.StageFactory;
|
||||
import org.cryptomator.ui.fxapp.PrimaryStage;
|
||||
import org.cryptomator.ui.recoverykey.RecoveryKeyDisplayController;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
@@ -68,8 +72,14 @@ public abstract class AddVaultModule {
|
||||
@Provides
|
||||
@Named("shorteningThreshold")
|
||||
@AddVaultWizardScoped
|
||||
static StringProperty provideShorteningThreshold() {
|
||||
return new SimpleStringProperty();
|
||||
static IntegerProperty provideShorteningThreshold() {
|
||||
return new SimpleIntegerProperty(CreateNewVaultAdvancedSettingsController.DEFAULT_SHORTENING_THRESHOLD);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@AddVaultWizardScoped
|
||||
static BooleanProperty provideAdvancedSettingsEnabled() {
|
||||
return new SimpleBooleanProperty();
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -11,25 +11,21 @@ import javax.inject.Named;
|
||||
import javafx.application.Application;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.BooleanBinding;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@AddVaultWizardScoped
|
||||
public class CreateNewVaultAdvancedSettingsController implements FxController {
|
||||
|
||||
public static final int DEFAULT_SHORTENING_THRESHOLD = 220;
|
||||
public static final int MIN_SHORTENING_THRESHOLD = 36;
|
||||
private static final String DOCS_MOUNTING_URL = "https://docs.cryptomator.org/en/1.7/security/architecture/#name-shortening";
|
||||
private final Stage window;
|
||||
private final Lazy<Scene> chooseLocationScene;
|
||||
private final Lazy<Scene> choosePasswordScene;
|
||||
private final ObjectProperty<Path> vaultPath;
|
||||
private final StringProperty vaultName;
|
||||
private final ResourceBundle resourceBundle;
|
||||
private final StringProperty shorteningThreshold;
|
||||
private IntegerProperty shorteningThreshold;
|
||||
public NumericTextField shorteningThresholdTextField;
|
||||
private final BooleanBinding validShorteningThreshold;
|
||||
private final Lazy<Application> application;
|
||||
@@ -39,24 +35,25 @@ public class CreateNewVaultAdvancedSettingsController implements FxController {
|
||||
Lazy<Application> application, //
|
||||
@FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy<Scene> chooseLocationScene, //
|
||||
@FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) Lazy<Scene> choosePasswordScene, //
|
||||
ObjectProperty<Path> vaultPath, //
|
||||
@Named("vaultName") StringProperty vaultName, //
|
||||
ResourceBundle resourceBundle, //
|
||||
@Named("shorteningThreshold") StringProperty shorteningThreshold) {
|
||||
@Named("shorteningThreshold") IntegerProperty shorteningThreshold) {
|
||||
this.window = window;
|
||||
this.application = application;
|
||||
this.chooseLocationScene = chooseLocationScene;
|
||||
this.choosePasswordScene = choosePasswordScene;
|
||||
this.vaultPath = vaultPath;
|
||||
this.vaultName = vaultName;
|
||||
this.resourceBundle = resourceBundle;
|
||||
this.shorteningThreshold = shorteningThreshold;
|
||||
this.validShorteningThreshold = Bindings.createBooleanBinding(this::isValidShorteningThreshold, shorteningThreshold);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
shorteningThreshold.bindBidirectional(shorteningThresholdTextField.textProperty());
|
||||
shorteningThresholdTextField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
try {
|
||||
int intValue = Integer.parseInt(newValue);
|
||||
shorteningThreshold.set(intValue);
|
||||
} catch (NumberFormatException e) {
|
||||
shorteningThreshold.set(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -72,20 +69,14 @@ public class CreateNewVaultAdvancedSettingsController implements FxController {
|
||||
}
|
||||
|
||||
public boolean isValidShorteningThreshold() {
|
||||
if(shorteningThresholdTextField != null){
|
||||
try {
|
||||
var value = Integer.parseInt(shorteningThresholdTextField.getText());
|
||||
if (value < 36 || value > 220) {
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
try {
|
||||
var value = shorteningThreshold.get();
|
||||
if (value < MIN_SHORTENING_THRESHOLD || value > DEFAULT_SHORTENING_THRESHOLD) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,11 @@ import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.common.FxmlFile;
|
||||
import org.cryptomator.ui.common.FxmlScene;
|
||||
import org.cryptomator.ui.controls.FontAwesome5IconView;
|
||||
import org.cryptomator.ui.controls.NumericTextField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.BooleanBinding;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
@@ -72,6 +69,7 @@ public class CreateNewVaultLocationController implements FxController {
|
||||
public FontAwesome5IconView goodLocation;
|
||||
public FontAwesome5IconView badLocation;
|
||||
public CheckBox advancedSettingsCheckBox;
|
||||
private final BooleanProperty advancedSettingsEnabled;
|
||||
|
||||
@Inject
|
||||
CreateNewVaultLocationController(@AddVaultWizardWindow Stage window, //
|
||||
@@ -80,7 +78,8 @@ public class CreateNewVaultLocationController implements FxController {
|
||||
@FxmlScene(FxmlFile.ADDVAULT_NEW_ADVANCED_SETTINGS) Lazy<Scene> chooseAdvancedSettingsScene, //
|
||||
ObjectProperty<Path> vaultPath, //
|
||||
@Named("vaultName") StringProperty vaultName, //
|
||||
ResourceBundle resourceBundle) {
|
||||
ResourceBundle resourceBundle, //
|
||||
BooleanProperty advancedSettingsEnabled) {
|
||||
this.window = window;
|
||||
this.chooseNameScene = chooseNameScene;
|
||||
this.choosePasswordScene = choosePasswordScene;
|
||||
@@ -88,6 +87,7 @@ public class CreateNewVaultLocationController implements FxController {
|
||||
this.vaultPath = vaultPath;
|
||||
this.vaultName = vaultName;
|
||||
this.resourceBundle = resourceBundle;
|
||||
this.advancedSettingsEnabled = advancedSettingsEnabled;
|
||||
this.vaultPathStatus = ObservableUtil.mapWithDefault(vaultPath, this::validatePath, new VaultPathStatus(false, "error.message"));
|
||||
this.validVaultPath = ObservableUtil.mapWithDefault(vaultPathStatus, VaultPathStatus::valid, false);
|
||||
this.vaultPathStatus.addListener(this::updateStatusLabel);
|
||||
@@ -149,6 +149,7 @@ public class CreateNewVaultLocationController implements FxController {
|
||||
locationPresetsToggler.getToggles().addAll(locationPresetBtns);
|
||||
locationPresetsToggler.selectedToggleProperty().addListener(this::togglePredefinedLocation);
|
||||
usePresetPath.bind(locationPresetsToggler.selectedToggleProperty().isNotEqualTo(customRadioButton));
|
||||
advancedSettingsEnabled.bind(advancedSettingsCheckBox.selectedProperty());
|
||||
}
|
||||
|
||||
private void togglePredefinedLocation(@SuppressWarnings("unused") ObservableValue<? extends Toggle> observable, @SuppressWarnings("unused") Toggle oldValue, Toggle newValue) {
|
||||
@@ -164,10 +165,9 @@ public class CreateNewVaultLocationController implements FxController {
|
||||
@FXML
|
||||
public void next() {
|
||||
if (validVaultPath.getValue()) {
|
||||
if(advancedSettingsCheckBox.isSelected()){
|
||||
if (advancedSettingsEnabled.get()) {
|
||||
window.setScene(chooseAdvancedSettingsScene.get());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
window.setScene(choosePasswordScene.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import org.cryptomator.cryptolib.api.CryptorProvider;
|
||||
import org.cryptomator.cryptolib.api.Masterkey;
|
||||
import org.cryptomator.cryptolib.api.MasterkeyLoader;
|
||||
import org.cryptomator.cryptolib.common.MasterkeyFileAccess;
|
||||
import org.cryptomator.ui.changepassword.NewPasswordController;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.common.FxmlFile;
|
||||
import org.cryptomator.ui.common.FxmlScene;
|
||||
import org.cryptomator.ui.changepassword.NewPasswordController;
|
||||
import org.cryptomator.ui.common.Tasks;
|
||||
import org.cryptomator.ui.fxapp.FxApplicationWindows;
|
||||
import org.cryptomator.ui.recoverykey.RecoveryKeyFactory;
|
||||
@@ -25,6 +25,7 @@ import javax.inject.Named;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.ObjectBinding;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
@@ -56,6 +57,7 @@ public class CreateNewVaultPasswordController implements FxController {
|
||||
|
||||
private final Stage window;
|
||||
private final Lazy<Scene> chooseLocationScene;
|
||||
private final Lazy<Scene> chooseAdvancedSettingsScene;
|
||||
private final Lazy<Scene> recoveryKeyScene;
|
||||
private final Lazy<Scene> successScene;
|
||||
private final FxApplicationWindows appWindows;
|
||||
@@ -73,6 +75,8 @@ public class CreateNewVaultPasswordController implements FxController {
|
||||
private final BooleanProperty processing;
|
||||
private final BooleanProperty readyToCreateVault;
|
||||
private final ObjectBinding<ContentDisplay> createVaultButtonState;
|
||||
private final IntegerProperty shorteningThreshold;
|
||||
private final BooleanProperty advancedSettingsEnabled;
|
||||
|
||||
/* FXML */
|
||||
public ToggleGroup recoveryKeyChoice;
|
||||
@@ -80,11 +84,10 @@ public class CreateNewVaultPasswordController implements FxController {
|
||||
public Toggle skipRecoveryKey;
|
||||
public NewPasswordController newPasswordSceneController;
|
||||
|
||||
private final StringProperty shorteningThreshold;
|
||||
|
||||
@Inject
|
||||
CreateNewVaultPasswordController(@AddVaultWizardWindow Stage window, //
|
||||
@FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy<Scene> chooseLocationScene, //
|
||||
@FxmlScene(FxmlFile.ADDVAULT_NEW_ADVANCED_SETTINGS) Lazy<Scene> chooseAdvancedSettingsScene, //
|
||||
@FxmlScene(FxmlFile.ADDVAULT_NEW_RECOVERYKEY) Lazy<Scene> recoveryKeyScene, //
|
||||
@FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy<Scene> successScene, //
|
||||
FxApplicationWindows appWindows, //
|
||||
@@ -96,12 +99,14 @@ public class CreateNewVaultPasswordController implements FxController {
|
||||
@Named("recoveryKey") StringProperty recoveryKey, //
|
||||
VaultListManager vaultListManager, //
|
||||
ResourceBundle resourceBundle, //
|
||||
@Named("shorteningThreshold") StringProperty shorteningThreshold, //
|
||||
@Named("shorteningThreshold") IntegerProperty shorteningThreshold, //
|
||||
ReadmeGenerator readmeGenerator, //
|
||||
SecureRandom csprng, //
|
||||
MasterkeyFileAccess masterkeyFileAccess) {
|
||||
MasterkeyFileAccess masterkeyFileAccess, //
|
||||
BooleanProperty advancedSettingsEnabled) {
|
||||
this.window = window;
|
||||
this.chooseLocationScene = chooseLocationScene;
|
||||
this.chooseAdvancedSettingsScene = chooseAdvancedSettingsScene;
|
||||
this.recoveryKeyScene = recoveryKeyScene;
|
||||
this.successScene = successScene;
|
||||
this.appWindows = appWindows;
|
||||
@@ -120,10 +125,7 @@ public class CreateNewVaultPasswordController implements FxController {
|
||||
this.readyToCreateVault = new SimpleBooleanProperty();
|
||||
this.createVaultButtonState = Bindings.when(processing).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY);
|
||||
this.shorteningThreshold = shorteningThreshold;
|
||||
if(this.shorteningThreshold.isNull().get())
|
||||
{
|
||||
this.shorteningThreshold.set("220");
|
||||
}
|
||||
this.advancedSettingsEnabled = advancedSettingsEnabled;
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -137,7 +139,11 @@ public class CreateNewVaultPasswordController implements FxController {
|
||||
|
||||
@FXML
|
||||
public void back() {
|
||||
window.setScene(chooseLocationScene.get());
|
||||
if (advancedSettingsEnabled.getValue()) {
|
||||
window.setScene(chooseAdvancedSettingsScene.get());
|
||||
} else {
|
||||
window.setScene(chooseLocationScene.get());
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -200,7 +206,7 @@ public class CreateNewVaultPasswordController implements FxController {
|
||||
CryptoFileSystemProperties fsProps = CryptoFileSystemProperties.cryptoFileSystemProperties() //
|
||||
.withCipherCombo(CryptorProvider.Scheme.SIV_GCM) //
|
||||
.withKeyLoader(loader) //
|
||||
.withShorteningThreshold(Integer.parseInt(shorteningThreshold.getValue()))
|
||||
.withShorteningThreshold(shorteningThreshold.get()) //
|
||||
.build();
|
||||
CryptoFileSystemProvider.initialize(path, fsProps, DEFAULT_KEY_ID);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<FontAwesome5IconView glyph="QUESTION_CIRCLE" styleClass="glyph-icon-muted"/>
|
||||
</graphic>
|
||||
<tooltip>
|
||||
<Tooltip text="%addvaultwizard.new.shorteningThreshold.tooltip" showDelay="10ms" />
|
||||
<Tooltip text="%addvaultwizard.new.shorteningThreshold.tooltip" showDelay="10ms"/>
|
||||
</tooltip>
|
||||
</Hyperlink>
|
||||
</HBox>
|
||||
@@ -56,12 +56,12 @@
|
||||
</StackPane>
|
||||
</HBox>
|
||||
</VBox>
|
||||
|
||||
<Label text="%addvaultwizard.new.shorteningThreshold.message"/>
|
||||
<Region VBox.vgrow="ALWAYS"/>
|
||||
|
||||
<ButtonBar buttonMinWidth="120" buttonOrder="B+X">
|
||||
<buttons>
|
||||
<Button text="%generic.button.back" ButtonBar.buttonData="BACK_PREVIOUS" onAction="#back"/>
|
||||
<Button text="%generic.button.back" ButtonBar.buttonData="BACK_PREVIOUS" onAction="#back" disable="${!controller.validShorteningThreshold}"/>
|
||||
<Button text="%generic.button.next" ButtonBar.buttonData="NEXT_FORWARD" onAction="#next" defaultButton="true" disable="${!controller.validShorteningThreshold}"/>
|
||||
</buttons>
|
||||
</ButtonBar>
|
||||
|
||||
@@ -67,6 +67,7 @@ addvaultwizard.new.showAdvancedSettings.checkbox=Show advanced settings in next
|
||||
addvaultwizard.new.shorteningThreshold.title=Limit the length of encrypted file names.
|
||||
addvaultwizard.new.shorteningThreshold.tooltip=Open the documentation to learn more.
|
||||
addvaultwizard.new.shorteningThreshold.namePrompt=36-220
|
||||
addvaultwizard.new.shorteningThreshold.message=Enter a value between 36 and 220.
|
||||
addvaultwizard.new.shorteningThreshold.invalid=Invalid
|
||||
addvaultwizard.new.shorteningThreshold.valid=Valid
|
||||
### Password
|
||||
|
||||
Reference in New Issue
Block a user