From 362b225d665abed8059e47c7a9045b464f5d77e6 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Wed, 27 Nov 2019 16:39:40 +0100 Subject: [PATCH] Fixes #939 --- .../org/cryptomator/ui/common/FxmlFile.java | 1 + .../ui/unlock/UnlockController.java | 10 ++--- .../UnlockInvalidMountPointController.java | 39 ++++++++++++++++ .../cryptomator/ui/unlock/UnlockModule.java | 13 ++++++ .../fxml/unlock_invalid_mount_point.fxml | 45 +++++++++++++++++++ .../main/resources/i18n/strings.properties | 2 + 6 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java create mode 100644 main/ui/src/main/resources/fxml/unlock_invalid_mount_point.fxml diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java index c25562bdc..e6f449ccb 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -22,6 +22,7 @@ public enum FxmlFile { REMOVE_VAULT("/fxml/remove_vault.fxml"), // UNLOCK("/fxml/unlock.fxml"), UNLOCK_GENERIC_ERROR("/fxml/unlock_generic_error.fxml"), // + UNLOCK_INVALID_MOUNT_POINT("/fxml/unlock_invalid_mount_point.fxml"), // UNLOCK_SUCCESS("/fxml/unlock_success.fxml"), // VAULT_OPTIONS("/fxml/vault_options.fxml"), // WRONGFILEALERT("/fxml/wrongfilealert.fxml"); diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockController.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockController.java index 76b1c591a..837dc827f 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockController.java @@ -51,6 +51,7 @@ public class UnlockController implements FxController { private final ObjectBinding unlockButtonState; private final Optional keychainAccess; private final Lazy successScene; + private final Lazy invalidMountPointScene; private final Lazy genericErrorScene; private final ObjectProperty genericErrorCause; private final ForgetPasswordComponent.Builder forgetPassword; @@ -59,13 +60,14 @@ public class UnlockController implements FxController { public CheckBox savePassword; @Inject - public UnlockController(@UnlockWindow Stage window, @UnlockWindow Vault vault, ExecutorService executor, Optional keychainAccess, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.UNLOCK_GENERIC_ERROR) Lazy genericErrorScene, @Named("genericErrorCause") ObjectProperty genericErrorCause, ForgetPasswordComponent.Builder forgetPassword) { + public UnlockController(@UnlockWindow Stage window, @UnlockWindow Vault vault, ExecutorService executor, Optional keychainAccess, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy invalidMountPointScene, @FxmlScene(FxmlFile.UNLOCK_GENERIC_ERROR) Lazy genericErrorScene, @Named("genericErrorCause") ObjectProperty genericErrorCause, ForgetPasswordComponent.Builder forgetPassword) { this.window = window; this.vault = vault; this.executor = executor; this.unlockButtonState = Bindings.createObjectBinding(this::getUnlockButtonState, vault.stateProperty()); this.keychainAccess = keychainAccess; this.successScene = successScene; + this.invalidMountPointScene = invalidMountPointScene; this.genericErrorScene = genericErrorScene; this.genericErrorCause = genericErrorCause; this.forgetPassword = forgetPassword; @@ -106,14 +108,12 @@ public class UnlockController implements FxController { shakeWindow(); passwordField.selectAll(); passwordField.requestFocus(); - }).onError(UnsupportedVaultFormatException.class, e -> { - // TODO }).onError(NotDirectoryException.class, e -> { LOG.error("Unlock failed. Mount point not a directory: {}", e.getMessage()); - // TODO + window.setScene(invalidMountPointScene.get()); }).onError(DirectoryNotEmptyException.class, e -> { LOG.error("Unlock failed. Mount point not empty: {}", e.getMessage()); - // TODO + window.setScene(invalidMountPointScene.get()); }).onError(Exception.class, e -> { // including RuntimeExceptions LOG.error("Unlock failed for technical reasons.", e); genericErrorCause.set(e); diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java new file mode 100644 index 000000000..d73c96c07 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -0,0 +1,39 @@ +package org.cryptomator.ui.unlock; + +import dagger.Lazy; +import javafx.fxml.FXML; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.cryptomator.common.vaults.Vault; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; + +import javax.inject.Inject; + +@UnlockScoped +public class UnlockInvalidMountPointController implements FxController { + + private final Stage window; + private final Lazy unlockScene; + private final Vault vault; + + @Inject + UnlockInvalidMountPointController(@UnlockWindow Stage window, @FxmlScene(FxmlFile.UNLOCK) Lazy unlockScene, @UnlockWindow Vault vault) { + this.window = window; + this.unlockScene = unlockScene; + this.vault = vault; + } + + @FXML + public void back() { + window.setScene(unlockScene.get()); + } + + /* Getter/Setter */ + + public String getMountPoint() { + return vault.getVaultSettings().getIndividualMountPath().orElse("AUTO"); + } + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java index 6ab89f658..69488010f 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java @@ -68,6 +68,14 @@ abstract class UnlockModule { return fxmlLoaders.createScene("/fxml/unlock_success.fxml"); } + @Provides + @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) + @UnlockScoped + static Scene provideInvalidMountPointScene(@UnlockWindow FXMLLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene("/fxml/unlock_invalid_mount_point.fxml"); + } + + @Provides @FxmlScene(FxmlFile.UNLOCK_GENERIC_ERROR) @UnlockScoped @@ -88,6 +96,11 @@ abstract class UnlockModule { @FxControllerKey(UnlockSuccessController.class) abstract FxController bindUnlockSuccessController(UnlockSuccessController controller); + @Binds + @IntoMap + @FxControllerKey(UnlockInvalidMountPointController.class) + abstract FxController bindUnlockInvalidMountPointController(UnlockInvalidMountPointController controller); + @Binds @IntoMap @FxControllerKey(UnlockGenericErrorController.class) diff --git a/main/ui/src/main/resources/fxml/unlock_invalid_mount_point.fxml b/main/ui/src/main/resources/fxml/unlock_invalid_mount_point.fxml new file mode 100644 index 000000000..fd643223d --- /dev/null +++ b/main/ui/src/main/resources/fxml/unlock_invalid_mount_point.fxml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +