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 aab0bd01a..f6ce632f4 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 @@ -17,6 +17,7 @@ public enum FxmlFile { PREFERENCES("/fxml/preferences.fxml"), // QUIT("/fxml/quit.fxml"), // RECOVERYKEY_CREATE("/fxml/recoverykey_create.fxml"), // + RECOVERYKEY_DISPLAY("/fxml/recoverykey_display.fxml"), // REMOVE_VAULT("/fxml/remove_vault.fxml"), // UNLOCK("/fxml/unlock.fxml"), UNLOCK_SUCCESS("/fxml/unlock_success.fxml"), // diff --git a/main/ui/src/main/java/org/cryptomator/ui/controls/NiceSecurePasswordField.java b/main/ui/src/main/java/org/cryptomator/ui/controls/NiceSecurePasswordField.java index 6cc2ac57c..3a85fbad6 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controls/NiceSecurePasswordField.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controls/NiceSecurePasswordField.java @@ -67,6 +67,10 @@ public class NiceSecurePasswordField extends StackPane { public void requestFocus() { passwordField.requestFocus(); } + + public String getText() { + return passwordField.getText(); + } public StringProperty textProperty() { return passwordField.textProperty(); diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyComponent.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyComponent.java index f317a140f..25fa319b4 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyComponent.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyComponent.java @@ -36,9 +36,6 @@ public interface RecoveryKeyComponent { @BindsInstance Builder vault(@RecoveryKeyWindow Vault vault); - @BindsInstance - Builder password(@Nullable CharSequence password); - @BindsInstance Builder owner(@Named("keyRecoveryOwner") Stage owner); diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java index b69b6612e..4135d2318 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java @@ -1,14 +1,16 @@ package org.cryptomator.ui.recoverykey; +import dagger.Lazy; import javafx.beans.property.ReadOnlyStringProperty; -import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.fxml.FXML; +import javafx.scene.Scene; import javafx.stage.Stage; import org.cryptomator.common.vaults.Vault; -import org.cryptomator.cryptofs.CryptoFileSystemProvider; import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.common.Tasks; import org.cryptomator.ui.controls.NiceSecurePasswordField; import org.slf4j.Logger; @@ -17,7 +19,6 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nullable; import javax.inject.Inject; import java.io.IOException; -import java.util.Arrays; import java.util.concurrent.ExecutorService; @RecoveryKeyScoped @@ -26,28 +27,21 @@ public class RecoveryKeyCreationController implements FxController { private static final Logger LOG = LoggerFactory.getLogger(RecoveryKeyCreationController.class); private final Stage window; + private final Lazy successScene; private final Vault vault; private final ExecutorService executor; - private final CharSequence prefilledPassword; private final RecoveryKeyFactory recoveryKeyFactory; - private final StringProperty recoveryKey; + private final StringProperty recoveryKeyProperty; public NiceSecurePasswordField passwordField; @Inject - public RecoveryKeyCreationController(@RecoveryKeyWindow Stage window, @RecoveryKeyWindow Vault vault, RecoveryKeyFactory recoveryKeyFactory, ExecutorService executor, @Nullable CharSequence prefilledPassword) { + public RecoveryKeyCreationController(@RecoveryKeyWindow Stage window, @FxmlScene(FxmlFile.RECOVERYKEY_DISPLAY) Lazy successScene, @RecoveryKeyWindow Vault vault, RecoveryKeyFactory recoveryKeyFactory, ExecutorService executor, @RecoveryKeyWindow StringProperty recoveryKey) { this.window = window; + this.successScene = successScene; this.vault = vault; this.executor = executor; - this.prefilledPassword = prefilledPassword; this.recoveryKeyFactory = recoveryKeyFactory; - this.recoveryKey = new SimpleStringProperty(); - } - - @FXML - public void initialize() { - if (prefilledPassword != null) { - passwordField.setPassword(prefilledPassword); - } + this.recoveryKeyProperty = recoveryKey; } @FXML @@ -55,7 +49,8 @@ public class RecoveryKeyCreationController implements FxController { Tasks.create(() -> { return recoveryKeyFactory.createRecoveryKey(vault.getPath(), passwordField.getCharacters()); }).onSuccess(result -> { - recoveryKey.set(result); + recoveryKeyProperty.set(result); + window.setScene(successScene.get()); }).onError(IOException.class, e -> { LOG.error("Creation of recovery key failed.", e); }).onError(InvalidPassphraseException.class, e -> { @@ -67,14 +62,5 @@ public class RecoveryKeyCreationController implements FxController { public void close() { window.close(); } - - /* Getter/Setter */ - public ReadOnlyStringProperty recoveryKeyProperty() { - return recoveryKey; - } - - public String getRecoveryKey() { - return recoveryKey.get(); - } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyDisplayController.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyDisplayController.java new file mode 100644 index 000000000..b15978e3e --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyDisplayController.java @@ -0,0 +1,37 @@ +package org.cryptomator.ui.recoverykey; + +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.property.StringProperty; +import javafx.fxml.FXML; +import javafx.stage.Stage; +import org.cryptomator.ui.common.FxController; + +import javax.inject.Inject; + +@RecoveryKeyScoped +public class RecoveryKeyDisplayController implements FxController { + + private final Stage window; + private final StringProperty recoveryKeyProperty; + + @Inject + public RecoveryKeyDisplayController(@RecoveryKeyWindow Stage window, @RecoveryKeyWindow StringProperty recoveryKey) { + this.window = window; + this.recoveryKeyProperty = recoveryKey; + } + + @FXML + public void close() { + window.close(); + } + + /* Getter/Setter */ + + public ReadOnlyStringProperty recoveryKeyProperty() { + return recoveryKeyProperty; + } + + public String getRecoveryKey() { + return recoveryKeyProperty.get(); + } +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyModule.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyModule.java index 118bd87c9..df8223314 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyModule.java @@ -4,6 +4,8 @@ import dagger.Binds; import dagger.Module; import dagger.Provides; import dagger.multibindings.IntoMap; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.stage.Modality; @@ -43,6 +45,15 @@ abstract class RecoveryKeyModule { windowIcon.ifPresent(stage.getIcons()::add); return stage; } + + @Provides + @RecoveryKeyWindow + @RecoveryKeyScoped + static StringProperty provideRecoveryKeyProperty() { + return new SimpleStringProperty(); + } + + // ------------------ @Provides @FxmlScene(FxmlFile.RECOVERYKEY_CREATE) @@ -51,10 +62,23 @@ abstract class RecoveryKeyModule { return fxmlLoaders.createScene("/fxml/recoverykey_create.fxml"); } + @Provides + @FxmlScene(FxmlFile.RECOVERYKEY_DISPLAY) + @RecoveryKeyScoped + static Scene provideRecoveryKeyDisplayScene(@RecoveryKeyWindow FXMLLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene("/fxml/recoverykey_display.fxml"); + } + // ------------------ @Binds @IntoMap @FxControllerKey(RecoveryKeyCreationController.class) abstract FxController bindRecoveryKeyCreationController(RecoveryKeyCreationController controller); + + @Binds + @IntoMap + @FxControllerKey(RecoveryKeyDisplayController.class) + abstract FxController bindRecoveryKeyDisplayController(RecoveryKeyDisplayController controller); + } diff --git a/main/ui/src/main/resources/fxml/recoverykey_create.fxml b/main/ui/src/main/resources/fxml/recoverykey_create.fxml index e44314d1f..da56bc993 100644 --- a/main/ui/src/main/resources/fxml/recoverykey_create.fxml +++ b/main/ui/src/main/resources/fxml/recoverykey_create.fxml @@ -3,13 +3,9 @@ - - - - - - + + - - - - - - - -