From 0b6782d44bc8c8efdae20fb9626e770fa9c65bd1 Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Tue, 18 Jul 2023 20:06:50 +0200 Subject: [PATCH 1/2] Refactored error message to use ObservableValues --- .../UnlockInvalidMountPointController.java | 87 ++++++++++++++----- .../cryptomator/ui/unlock/UnlockModule.java | 7 +- .../cryptomator/ui/unlock/UnlockWorkflow.java | 6 +- .../fxml/unlock_invalid_mount_point.fxml | 2 +- 4 files changed, 71 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java index 6e11ed131..14b74e377 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -1,5 +1,6 @@ package org.cryptomator.ui.unlock; +import org.cryptomator.common.ObservableUtil; import org.cryptomator.common.mount.ExistingHideawayException; import org.cryptomator.common.mount.IllegalMountPointException; import org.cryptomator.common.mount.MountPointCleanupFailedException; @@ -16,11 +17,12 @@ import org.cryptomator.ui.vaultoptions.SelectedVaultOptionsTab; import org.jetbrains.annotations.PropertyKey; import javax.inject.Inject; +import javafx.beans.property.ObjectProperty; +import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.stage.Stage; import java.nio.file.Path; import java.util.ResourceBundle; -import java.util.concurrent.atomic.AtomicReference; //At the current point in time only the CustomMountPointChooser may cause this window to be shown. @UnlockScoped @@ -29,34 +31,31 @@ public class UnlockInvalidMountPointController implements FxController { private final Stage window; private final Vault vault; private final FxApplicationWindows appWindows; - private final ResourceBundle resourceBundle; - private final ExceptionType exceptionType; - private final Path exceptionPath; - private final String exceptionMessage; - private final Path hideawayPath; + + private final ObservableValue exceptionType; + private final ObservableValue exceptionPath; + private final ObservableValue exceptionMessage; + private final ObservableValue hideawayPath; + private final ObservableValue format; + private final ObservableValue showPreferences; + private final ObservableValue showVaultOptions; public FormattedLabel dialogDescription; @Inject - UnlockInvalidMountPointController(@UnlockWindow Stage window, @UnlockWindow Vault vault, @UnlockWindow AtomicReference illegalMountPointException, FxApplicationWindows appWindows, ResourceBundle resourceBundle) { + UnlockInvalidMountPointController(@UnlockWindow Stage window, @UnlockWindow Vault vault, @UnlockWindow ObjectProperty illegalMountPointException, FxApplicationWindows appWindows, ResourceBundle resourceBundle) { this.window = window; this.vault = vault; this.appWindows = appWindows; - this.resourceBundle = resourceBundle; - var exc = illegalMountPointException.get(); - this.exceptionType = getExceptionType(exc); - this.exceptionPath = exc.getMountpoint(); - this.exceptionMessage = exc.getMessage(); - this.hideawayPath = exc instanceof ExistingHideawayException haeExc ? haeExc.getHideaway() : null; - } + this.exceptionType = illegalMountPointException.map(this::getExceptionType); + this.exceptionPath = illegalMountPointException.map(IllegalMountPointException::getMountpoint); + this.exceptionMessage = illegalMountPointException.map(IllegalMountPointException::getMessage); + this.hideawayPath = illegalMountPointException.map(e -> e instanceof ExistingHideawayException haeExc ? haeExc.getHideaway() : null); - @FXML - public void initialize() { - dialogDescription.setFormat(resourceBundle.getString(exceptionType.translationKey)); - dialogDescription.setArg1(exceptionPath); - dialogDescription.setArg2(exceptionMessage); - dialogDescription.setArg3(hideawayPath); + this.format = ObservableUtil.mapWithDefault(exceptionType, type -> resourceBundle.getString(type.translationKey), ""); + this.showPreferences = ObservableUtil.mapWithDefault(exceptionType, type -> type.action == ButtonAction.SHOW_PREFERENCES, false); + this.showVaultOptions = ObservableUtil.mapWithDefault(exceptionType, type -> type.action == ButtonAction.SHOW_VAULT_OPTIONS, false); } @FXML @@ -117,11 +116,51 @@ public class UnlockInvalidMountPointController implements FxController { /* Getter */ - public boolean isShowPreferences() { - return exceptionType.action == ButtonAction.SHOW_PREFERENCES; + public Path getExceptionPath() { + return exceptionPath.getValue(); } - public boolean isShowVaultOptions() { - return exceptionType.action == ButtonAction.SHOW_VAULT_OPTIONS; + public ObservableValue exceptionPathProperty() { + return exceptionPath; + } + + public String getFormat() { + return format.getValue(); + } + + public ObservableValue formatProperty() { + return format; + } + + public String getExceptionMessage() { + return exceptionMessage.getValue(); + } + + public ObservableValue exceptionMessageProperty() { + return exceptionMessage; + } + + public Path getHideawayPath() { + return hideawayPath.getValue(); + } + + public ObservableValue hideawayPathProperty() { + return hideawayPath; + } + + public Boolean getShowPreferences() { + return showPreferences.getValue(); + } + + public ObservableValue showPreferencesProperty() { + return showPreferences; + } + + public Boolean getShowVaultOptions() { + return showVaultOptions.getValue(); + } + + public ObservableValue showVaultOptionsProperty() { + return showVaultOptions; } } \ No newline at end of file diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java b/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java index c84c12db1..f93999d21 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java @@ -19,12 +19,13 @@ import org.jetbrains.annotations.Nullable; import javax.inject.Named; import javax.inject.Provider; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; import javafx.scene.Scene; import javafx.stage.Modality; import javafx.stage.Stage; import java.util.Map; import java.util.ResourceBundle; -import java.util.concurrent.atomic.AtomicReference; @Module(subcomponents = {KeyLoadingComponent.class}) abstract class UnlockModule { @@ -62,8 +63,8 @@ abstract class UnlockModule { @Provides @UnlockWindow @UnlockScoped - static AtomicReference illegalMountPointException() { - return new AtomicReference<>(); + static ObjectProperty illegalMountPointException() { + return new SimpleObjectProperty<>(); } @Provides diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index ea91a3651..564d57ab6 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java @@ -17,11 +17,11 @@ import org.slf4j.LoggerFactory; import javax.inject.Inject; import javafx.application.Platform; +import javafx.beans.property.ObjectProperty; import javafx.concurrent.Task; import javafx.scene.Scene; import javafx.stage.Stage; import java.io.IOException; -import java.util.concurrent.atomic.AtomicReference; /** * A multi-step task that consists of background activities as well as user interaction. @@ -40,10 +40,10 @@ public class UnlockWorkflow extends Task { private final Lazy invalidMountPointScene; private final FxApplicationWindows appWindows; private final KeyLoadingStrategy keyLoadingStrategy; - private final AtomicReference illegalMountPointException; + private final ObjectProperty illegalMountPointException; @Inject - UnlockWorkflow(@UnlockWindow Stage window, @UnlockWindow Vault vault, VaultService vaultService, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy invalidMountPointScene, FxApplicationWindows appWindows, @UnlockWindow KeyLoadingStrategy keyLoadingStrategy, @UnlockWindow AtomicReference illegalMountPointException) { + UnlockWorkflow(@UnlockWindow Stage window, @UnlockWindow Vault vault, VaultService vaultService, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy invalidMountPointScene, FxApplicationWindows appWindows, @UnlockWindow KeyLoadingStrategy keyLoadingStrategy, @UnlockWindow ObjectProperty illegalMountPointException) { this.window = window; this.vault = vault; this.vaultService = vaultService; diff --git a/src/main/resources/fxml/unlock_invalid_mount_point.fxml b/src/main/resources/fxml/unlock_invalid_mount_point.fxml index c6f1a31f2..dbf6fad05 100644 --- a/src/main/resources/fxml/unlock_invalid_mount_point.fxml +++ b/src/main/resources/fxml/unlock_invalid_mount_point.fxml @@ -40,7 +40,7 @@ - + From 879e6dcab7182b809a06896deeb0814f7d57a064 Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Wed, 19 Jul 2023 16:04:22 +0200 Subject: [PATCH 2/2] Updated error message See: https://github.com/cryptomator/cryptomator/pull/3001#discussion_r1268035540 --- src/main/resources/i18n/strings.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/i18n/strings.properties b/src/main/resources/i18n/strings.properties index d0d770329..0683c8c16 100644 --- a/src/main/resources/i18n/strings.properties +++ b/src/main/resources/i18n/strings.properties @@ -131,7 +131,7 @@ unlock.error.customPath.message=Unable to mount vault to custom path unlock.error.customPath.description.notSupported=If you wish to keep using the custom path, please go to the preferences and select a volume type that supports it. Otherwise, go to the vault options and choose a supported mount point. unlock.error.customPath.description.notExists=The custom mount path does not exist. Either create it in your local filesystem or change it in the vault options. unlock.error.customPath.description.inUse=Drive letter "%s" is already in use. -unlock.error.customPath.description.hideawayExists=The folder "%3$s", which is used to preserve folder properties set by you, has not been automatically cleaned up since your last mount to "%1$s". Please delete it manually and restore any properties to the original mount path if you set any. +unlock.error.customPath.description.hideawayExists=The temporary, hidden directory "%3$s" used for unlock could not be removed. Please check the directory and remove it manually. unlock.error.customPath.description.couldNotBeCleaned=Your vault could not be mounted to the path "%s". Please try again or choose a different path. unlock.error.customPath.description.notEmptyDir=The custom mount path "%s" is not an empty folder. Please choose an empty folder and try again. unlock.error.customPath.description.generic=You have selected a custom mount path for this vault, but using it failed with the message: %2$s