Browse Source

Implements #1183 Saved Passwords are indicated

Martin Beyer 4 years ago
parent
commit
842a0d6ff3

+ 25 - 2
main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailLockedController.java

@@ -1,14 +1,19 @@
 package org.cryptomator.ui.mainwindow;
 
+import javafx.beans.binding.BooleanExpression;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.ReadOnlyObjectProperty;
+import javafx.beans.property.SimpleBooleanProperty;
 import javafx.fxml.FXML;
 import org.cryptomator.common.vaults.Vault;
+import org.cryptomator.keychain.KeychainManager;
 import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.fxapp.FxApplication;
 import org.cryptomator.ui.vaultoptions.VaultOptionsComponent;
+import org.fxmisc.easybind.EasyBind;
 
 import javax.inject.Inject;
+import java.util.Optional;
 
 @MainWindowScoped
 public class VaultDetailLockedController implements FxController {
@@ -16,12 +21,20 @@ public class VaultDetailLockedController implements FxController {
 	private final ReadOnlyObjectProperty<Vault> vault;
 	private final FxApplication application;
 	private final VaultOptionsComponent.Builder vaultOptionsWindow;
+	private final Optional<KeychainManager> keychainManagerOptional;
+	private final BooleanExpression passwordSaved;
 
 	@Inject
-	VaultDetailLockedController(ObjectProperty<Vault> vault, FxApplication application, VaultOptionsComponent.Builder vaultOptionsWindow) {
+	VaultDetailLockedController(ObjectProperty<Vault> vault, FxApplication application, VaultOptionsComponent.Builder vaultOptionsWindow, Optional<KeychainManager> keychainManagerOptional) {
 		this.vault = vault;
 		this.application = application;
 		this.vaultOptionsWindow = vaultOptionsWindow;
+		this.keychainManagerOptional = keychainManagerOptional;
+		if (keychainManagerOptional.isPresent()) {
+			this.passwordSaved = BooleanExpression.booleanExpression(EasyBind.select(vault).selectObject(v -> keychainManagerOptional.get().getPassphraseStoredProperty(v.getId())));
+		} else {
+			this.passwordSaved = new SimpleBooleanProperty(false);
+		}
 	}
 
 	@FXML
@@ -33,7 +46,7 @@ public class VaultDetailLockedController implements FxController {
 	public void showVaultOptions() {
 		vaultOptionsWindow.vault(vault.get()).build().showVaultOptionsWindow();
 	}
-	
+
 	/* Getter/Setter */
 
 	public ReadOnlyObjectProperty<Vault> vaultProperty() {
@@ -43,4 +56,14 @@ public class VaultDetailLockedController implements FxController {
 	public Vault getVault() {
 		return vault.get();
 	}
+
+	public BooleanExpression passwordSavedProperty() {
+		return passwordSaved;
+	}
+
+	public boolean isPasswordSaved() {
+		if (keychainManagerOptional.isPresent() && vault.get() != null) {
+			return keychainManagerOptional.get().getPassphraseStoredProperty(vault.get().getId()).get();
+		} else return false;
+	}
 }

+ 13 - 1
main/ui/src/main/resources/fxml/vault_detail_locked.fxml

@@ -5,6 +5,9 @@
 <?import javafx.scene.control.Hyperlink?>
 <?import javafx.scene.layout.VBox?>
 <?import org.cryptomator.ui.controls.FontAwesome5IconView?>
+<?import javafx.scene.layout.HBox?>
+<?import javafx.scene.control.Label?>
+<?import javafx.scene.layout.Region?>
 <VBox xmlns="http://javafx.com/javafx"
 	  xmlns:fx="http://javafx.com/fxml"
 	  fx:controller="org.cryptomator.ui.mainwindow.VaultDetailLockedController"
@@ -14,7 +17,12 @@
 		<Insets topRightBottomLeft="24"/>
 	</padding>
 	<children>
-		<Button styleClass="button-large" text="%main.vaultDetail.unlockBtn" minWidth="120" onAction="#unlock" defaultButton="${controller.vault.locked}">
+		<Button styleClass="button-large" text="%main.vaultDetail.unlockBtn" minWidth="120" onAction="#unlock" defaultButton="${controller.vault.locked}"  visible="${!controller.passwordSaved}" managed="${!controller.passwordSaved}">
+			<graphic>
+				<FontAwesome5IconView glyph="KEY" glyphSize="15"/>
+			</graphic>
+		</Button>
+		<Button styleClass="button-large" text="%main.vaultDetail.unlockNowBtn" minWidth="120" onAction="#unlock" defaultButton="${controller.vault.locked}" visible="${controller.passwordSaved}" managed="${controller.passwordSaved}">
 			<graphic>
 				<FontAwesome5IconView glyph="KEY" glyphSize="15"/>
 			</graphic>
@@ -24,5 +32,9 @@
 				<FontAwesome5IconView glyph="COG"/>
 			</graphic>
 		</Hyperlink>
+		<Region VBox.vgrow="ALWAYS"/>
+		<HBox alignment="CENTER_RIGHT" spacing="6">
+			<Label styleClass="label-small" text="%main.vaultDetail.passwordSavedInKeychain" visible="${controller.passwordSaved}"/>
+		</HBox>
 	</children>
 </VBox>

+ 3 - 1
main/ui/src/main/resources/i18n/strings.properties

@@ -176,8 +176,10 @@ main.vaultlist.addVaultBtn=Add Vault
 main.vaultDetail.welcomeOnboarding=Thanks for choosing Cryptomator to protect your files. If you need any assistance, check out our getting started guides:
 ### Locked
 main.vaultDetail.lockedStatus=LOCKED
-main.vaultDetail.unlockBtn=Unlock
+main.vaultDetail.unlockBtn=Unlock…
+main.vaultDetail.unlockNowBtn=Unlock Now
 main.vaultDetail.optionsBtn=Vault Options
+main.vaultDetail.passwordSavedInKeychain=Password saved
 ### Unlocked
 main.vaultDetail.unlockedStatus=UNLOCKED
 main.vaultDetail.accessLocation=Your vault's contents are accessible here: