Sfoglia il codice sorgente

adding error screen for adding existing vault

Armin Schrenk 5 anni fa
parent
commit
54d2591391

+ 51 - 0
main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultFailureExisitingController.java

@@ -0,0 +1,51 @@
+package org.cryptomator.ui.addvaultwizard;
+
+import dagger.Lazy;
+import javafx.beans.binding.Bindings;
+import javafx.beans.binding.StringBinding;
+import javafx.beans.property.ObjectProperty;
+import javafx.fxml.FXML;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.common.FxmlFile;
+import org.cryptomator.ui.common.FxmlScene;
+
+import javax.inject.Inject;
+import java.nio.file.Path;
+
+@AddVaultWizardScoped
+public class AddVaultFailureExisitingController implements FxController {
+
+	private final Stage window;
+	private final Lazy<Scene> previousScene;
+	private final StringBinding vaultName;
+
+	@Inject
+	AddVaultFailureExisitingController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_EXISTING) Lazy<Scene> previousScene, ObjectProperty<Path> pathOfFailedVault){
+		this.window = window;
+		this.previousScene = previousScene;
+		this.vaultName = Bindings.createStringBinding(() -> pathOfFailedVault.get().getFileName().toString(),pathOfFailedVault);
+	}
+
+	@FXML
+	public void close(){
+		window.close();
+	}
+
+	@FXML
+	public void back(){
+		window.setScene(previousScene.get());
+	}
+
+	// Getter & Setter
+
+	public StringBinding vaultNameProperty(){
+		return vaultName;
+	}
+
+	public String getVaultName(){
+		return vaultName.get();
+	}
+
+}

+ 12 - 0
main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java

@@ -94,6 +94,13 @@ public abstract class AddVaultModule {
 		return fxmlLoaders.createScene(FxmlFile.ADDVAULT_EXISTING.getRessourcePathString());
 	}
 
+	@Provides
+	@FxmlScene(FxmlFile.ADDVAULT_EXISTING_ERROR)
+	@AddVaultWizardScoped
+	static Scene provideChooseExistingVaultErrorScene(@AddVaultWizardWindow FXMLLoaderFactory fxmlLoaders) {
+		return fxmlLoaders.createScene(FxmlFile.ADDVAULT_EXISTING_ERROR.getRessourcePathString());
+	}
+
 	@Provides
 	@FxmlScene(FxmlFile.ADDVAULT_NEW_NAME)
 	@AddVaultWizardScoped
@@ -141,6 +148,11 @@ public abstract class AddVaultModule {
 	@FxControllerKey(ChooseExistingVaultController.class)
 	abstract FxController bindChooseExistingVaultController(ChooseExistingVaultController controller);
 
+	@Binds
+	@IntoMap
+	@FxControllerKey(AddVaultFailureExisitingController.class)
+	abstract FxController bindAddVaultFailureExistingController(AddVaultFailureExisitingController controller);
+
 	@Binds
 	@IntoMap
 	@FxControllerKey(CreateNewVaultNameController.class)

+ 8 - 7
main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java

@@ -28,16 +28,18 @@ public class ChooseExistingVaultController implements FxController {
 	private final Stage window;
 	private final Lazy<Scene> welcomeScene;
 	private final Lazy<Scene> successScene;
+	private final Lazy<Scene> errorScene;
 	private final ObjectProperty<Path> vaultPath;
 	private final ObjectProperty<Vault> vault;
 	private final VaultListManager vaultListManager;
 	private final ResourceBundle resourceBundle;
 
 	@Inject
-	ChooseExistingVaultController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy<Scene> welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy<Scene> successScene, ObjectProperty<Path> vaultPath, @AddVaultWizardWindow ObjectProperty<Vault> vault, VaultListManager vaultListManager, ResourceBundle resourceBundle) {
+	ChooseExistingVaultController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy<Scene> welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy<Scene> successScene, @FxmlScene(FxmlFile.ADDVAULT_EXISTING_ERROR) Lazy<Scene> errorScene, ObjectProperty<Path> vaultPath, @AddVaultWizardWindow ObjectProperty<Vault> vault, VaultListManager vaultListManager, ResourceBundle resourceBundle) {
 		this.window = window;
 		this.welcomeScene = welcomeScene;
 		this.successScene = successScene;
+		this.errorScene = errorScene;
 		this.vaultPath = vaultPath;
 		this.vault = vault;
 		this.vaultListManager = vaultListManager;
@@ -51,20 +53,19 @@ public class ChooseExistingVaultController implements FxController {
 
 	@FXML
 	public void chooseFileAndNext() {
-		//TODO: error handling & cannot unlock added vault
 		FileChooser fileChooser = new FileChooser();
 		fileChooser.setTitle(resourceBundle.getString("addvaultwizard.existing.filePickerTitle"));
 		fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Cryptomator Masterkey", "*.cryptomator"));
-		File file = fileChooser.showOpenDialog(window);
-		if (file != null) {
-			vaultPath.setValue(file.toPath().toAbsolutePath().getParent());
+		File masterkeyFile = fileChooser.showOpenDialog(window);
+		if (masterkeyFile != null) {
+			vaultPath.setValue(masterkeyFile.toPath().toAbsolutePath().getParent());
 			try {
 				Vault newVault = vaultListManager.add(vaultPath.get());
 				vault.set(newVault);
 				window.setScene(successScene.get());
 			} catch (NoSuchFileException e) {
-				LOG.error("Nope", e);
-				// TODO
+				LOG.error("Failed to open existing vault.", e);
+				window.setScene(errorScene.get());
 			}
 		}
 	}

+ 1 - 0
main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java

@@ -3,6 +3,7 @@ package org.cryptomator.ui.common;
 public enum FxmlFile {
 	ADDVAULT_WELCOME("/fxml/addvault_welcome.fxml"), //
 	ADDVAULT_EXISTING("/fxml/addvault_existing.fxml"), //
+	ADDVAULT_EXISTING_ERROR("/fxml/addvault_existing_error.fxml"),
 	ADDVAULT_NEW_NAME("/fxml/addvault_new_name.fxml"), //
 	ADDVAULT_NEW_LOCATION("/fxml/addvault_new_location.fxml"), //
 	ADDVAULT_NEW_PASSWORD("/fxml/addvault_new_password.fxml"), //

+ 1 - 0
main/ui/src/main/java/org/cryptomator/ui/controls/FontAwesome5Icon.java

@@ -9,6 +9,7 @@ public enum FontAwesome5Icon {
 	CHECK("\uF00C"), //
 	COG("\uF013"), //
 	COGS("\uF085"), //
+	EXCLAMATION("\uF12A"),
 	EXCLAMATION_TRIANGLE("\uF071"), //
 	EYE("\uF06E"), //
 	EYE_SLASH("\uF070"), //

+ 41 - 0
main/ui/src/main/resources/fxml/addvault_existing_error.fxml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import javafx.geometry.Insets?>
+<?import javafx.scene.control.Button?>
+<?import javafx.scene.control.ButtonBar?>
+<?import javafx.scene.layout.HBox?>
+<?import javafx.scene.layout.StackPane?>
+<?import javafx.scene.layout.VBox?>
+<?import javafx.scene.shape.Circle?>
+<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
+<?import org.cryptomator.ui.controls.FormattedLabel?>
+<VBox xmlns="http://javafx.com/javafx"
+	  xmlns:fx="http://javafx.com/fxml"
+	  fx:controller="org.cryptomator.ui.addvaultwizard.AddVaultFailureExisitingController"
+	  minWidth="400"
+	  maxWidth="400"
+	  minHeight="145"
+	  spacing="12">
+	<padding>
+		<Insets topRightBottomLeft="12"/>
+	</padding>
+	<children>
+		<HBox spacing="12" alignment="CENTER_LEFT" VBox.vgrow="ALWAYS">
+			<StackPane alignment="CENTER" HBox.hgrow="NEVER">
+				<Circle styleClass="glyph-icon-primary" radius="24"/>
+				<FontAwesome5IconView styleClass="glyph-icon-white" glyph="EXCLAMATION" glyphSize="24"/>
+			</StackPane>
+			<FormattedLabel format="%addvaultwizard.existing.error" arg1="${controller.vaultName}" wrapText="true"/>
+		</HBox>
+
+		<VBox alignment="BOTTOM_CENTER" VBox.vgrow="ALWAYS">
+			<ButtonBar buttonMinWidth="120" buttonOrder="B+C">
+				<buttons>
+					<Button text="%generic.button.back" ButtonBar.buttonData="BACK_PREVIOUS" onAction="#back"/>
+					<Button text="%generic.button.cancel" ButtonBar.buttonData="CANCEL_CLOSE" defaultButton="true" cancelButton="true" onAction="#close"/>
+				</buttons>
+			</ButtonBar>
+		</VBox>
+	</children>
+</VBox>
+

+ 5 - 0
main/ui/src/main/resources/i18n/strings.properties

@@ -24,8 +24,10 @@ addvaultwizard.title=Add Vault
 addvaultwizard.welcome.newButton=Create New Vault
 addvaultwizard.welcome.existingButton=Open Existing Vault
 ## New
+### Name
 addvaultwizard.new.nameInstruction=Choose a name for the vault
 addvaultwizard.new.namePrompt=Vault Name
+### Location
 addvaultwizard.new.locationInstruction=Where should Cryptomator store the encrypted files of your vault?
 addvaultwizard.new.locationLabel=Storage location
 addvaultwizard.new.locationPrompt=…
@@ -35,12 +37,14 @@ addvaultwizard.new.directoryPickerTitle=Select Directory
 addvaultwizard.new.enterPassword=Enter a password for the vault
 addvaultwizard.new.fileAlreadyExists=Vault can not be created at this path because some object already exists.
 addvaultwizard.new.invalidName=Invalid vault name. Please consider a regular directory name.
+### Password
 addvaultwizard.new.reenterPassword=Confirm the password
 addvaultwizard.new.passwordsMatch=Passwords match!
 addvaultwizard.new.passwordsDoNotMatch=Passwords do not match
 addvaultwizard.new.createVaultBtn=Create Vault
 addvaultwizard.new.recoveryKeyInstruction=This is your recovery key. Keep it safe, it is your only chance to recover your data if you lose your password.
 addvaultwizard.new.recoveryKeySavedCheckbox=Yes, I've made a secure backup of this recovery key
+### Information
 addvault.new.readme.storageLocation.fileName=WHAT IS THIS DIRECTORY.rtf
 addvault.new.readme.storageLocation.1=\\fs40\\qc ⚠️  VAULT FILES  ⚠️
 addvault.new.readme.storageLocation.2=This is your vault's storage location. {\\b DO NOT} alter any files within this directory.
@@ -54,6 +58,7 @@ addvault.new.readme.accessLocation.3=Feel free to remove this file.
 addvaultwizard.existing.instruction=Choose the "masterkey.cryptomator" file of your existing vault.
 addvaultwizard.existing.chooseBtn=Choose…
 addvaultwizard.existing.filePickerTitle=Select Masterkey File
+addvaultwizard.existing.error=Unable to add vault "%s": Not a valid vault. Please look into the log for more information.
 ## Success
 addvaultwizard.success.nextStepsInstructions=Added vault "%s".\nYou need to unlock this vault to access or add contents. Alternatively you can unlock it at any later point in time.
 addvaultwizard.success.unlockNow=Unlock Now

+ 5 - 0
main/ui/src/main/resources/i18n/strings_de.properties

@@ -21,14 +21,17 @@ addvaultwizard.title=Tresor hinzufügen
 addvaultwizard.welcome.newButton=Neuen Tresor erstellen
 addvaultwizard.welcome.existingButton=Existierenden Tresor öffnen
 ## New
+### Name
 addvaultwizard.new.nameInstruction=Wähle einen Namen für den Tresor
 addvaultwizard.new.namePrompt=Tresorname
+### Location
 addvaultwizard.new.locationInstruction=Wo soll Cryptomator die verschlüsselten Daten deines Tresors ablegen?
 addvaultwizard.new.locationLabel=Speicherort
 addvaultwizard.new.locationPrompt=…
 addvaultwizard.new.directoryPickerLabel=Eigenen Ort wählen…
 addvaultwizard.new.directoryPickerButton=Durchsuchen…
 addvaultwizard.new.directoryPickerTitle=Wähle ein Verzeichnis
+### Password
 addvaultwizard.new.enterPassword=Vergib ein Passwort für den Tresor
 addvaultwizard.new.fileAlreadyExists=Der Tresor konnte nicht erstellt werden, da der Speicherort bereits belegt ist.
 addvaultwizard.new.invalidName=Ungültiger Tresorname. Tresore müssen wie Verzeichnisse benannt werden.
@@ -37,6 +40,7 @@ addvaultwizard.new.passwordsMatch=Passwörter stimmen überein!
 addvaultwizard.new.passwordsDoNotMatch=Passwörter stimmen nicht überein
 addvaultwizard.new.finalConfirmation=Mir ist bewusst, dass ich den Tresor ohne das Passwort NICHT mehr öffnen kann.
 addvaultwizard.new.createVaultBtn=Tresor erstellen
+### Information
 addvault.new.readme.storageLocation.fileName=WAS BEDEUTET DIESER ORDNER.rtf
 addvault.new.readme.storageLocation.1=\\fs40\\qc ⚠️  TRESORDATEIEN  ⚠️
 addvault.new.readme.storageLocation.2=Dies ist der Speicherort deines Tresor. Ändere {\\b KEINE} Dateien in diesem Verzeichnis.
@@ -50,6 +54,7 @@ addvault.new.readme.accessLocation.3=Diese Datei kannst du löschen.
 addvaultwizard.existing.instruction=Bitte wähle die Datei "masterkey.cryptomator" des exsitierenden Tresors aus.
 addvaultwizard.existing.chooseBtn=Dursuchen…
 addvaultwizard.existing.filePickerTitle=Masterkey-Datei auswählen
+addvaultwizard.existing.error=Tresor %s kann nicht hinzugefügt werden: Kein gültiger Tresor. Für mehr Informationen schaue bitte in die Log-Datei.
 ## Success
 addvaultwizard.success.nextStepsInstructions=Tresor "%s" hinzugefügt.\nEntsperre diesen Tresor jetzt, um auf die Inhalte zugreifen oder welche hinzufügen zu können. Andernfalls entsperre diesen Tresor zu einem späteren Zeitpunkt.
 addvaultwizard.success.unlockNow=Jetzt entsperren