add isHubVault dialog

This commit is contained in:
Jan-Peter Klein
2025-01-15 21:05:27 +01:00
parent 756672258d
commit 8191a7dae6
8 changed files with 140 additions and 7 deletions

View File

@@ -38,7 +38,6 @@ import static org.cryptomator.common.Constants.VAULTCONFIG_FILENAME;
import static org.cryptomator.common.vaults.VaultState.Value.ERROR;
import static org.cryptomator.common.vaults.VaultState.Value.LOCKED;
import static org.cryptomator.common.vaults.VaultState.Value.MASTERKEY_MISSING;
import static org.cryptomator.common.vaults.VaultState.Value.MISSING;
import static org.cryptomator.common.vaults.VaultState.Value.VAULT_CONFIG_MISSING;
@Singleton
@@ -167,7 +166,10 @@ public class VaultListManager {
private static VaultState.Value determineVaultState(Path pathToVault) throws IOException {
Path pathToVaultConfig = Path.of(pathToVault.toString(),"vault.cryptomator");
Path pathToMasterkey = Path.of(pathToVault.toString(),"masterkey.cryptomator");
if (!Files.exists(pathToVaultConfig)) {
if (!Files.exists(pathToVault)) {
return VaultState.Value.MISSING;
}
else if (!Files.exists(pathToVaultConfig)) {
try (Stream<Path> files = Files.list(pathToVaultConfig.getParent())) {
Path backupFile = files.filter(file -> {
String fileName = file.getFileName().toString();
@@ -213,9 +215,6 @@ public class VaultListManager {
return MASTERKEY_MISSING;
}
}
else if (!Files.exists(pathToVault)) {
return VaultState.Value.MISSING;
}
return switch (CryptoFileSystemProvider.checkDirStructureForVault(pathToVault, VAULTCONFIG_FILENAME, MASTERKEY_FILENAME)) {
case VAULT -> VaultState.Value.LOCKED;
case UNRELATED -> VaultState.Value.MISSING;

View File

@@ -41,6 +41,7 @@ public enum FxmlFile {
QUIT("/fxml/quit.fxml"), //
QUIT_FORCED("/fxml/quit_forced.fxml"), //
RECOVERYKEY_CREATE("/fxml/recoverykey_create.fxml"), //
RECOVERYKEY_IS_HUB_VAULT("/fxml/recoverykey_is_hub_vault.fxml"), //
RECOVERYKEY_RECOVER("/fxml/recoverykey_recover.fxml"), //
RECOVERYKEY_RESET_PASSWORD("/fxml/recoverykey_reset_password.fxml"), //
RECOVERYKEY_RESET_PASSWORD_SUCCESS("/fxml/recoverykey_reset_password_success.fxml"), //

View File

@@ -48,8 +48,9 @@ public class VaultDetailMissingVaultController implements FxController {
@FXML
void restoreVaultConfig(){
recoveryKeyWindow.create(vault.get(), window).showRecoveryKeyRecoverWindow("Recover VaultConfig");
recoveryKeyWindow.create(vault.get(), window).showIsHubVaultDialogWindow();
}
@FXML
void restoreMasterkey(){
recoveryKeyWindow.create(vault.get(), window).showRecoveryKeyRecoverWindow("Recover Masterkey");

View File

@@ -24,6 +24,9 @@ public interface RecoveryKeyComponent {
@FxmlScene(FxmlFile.RECOVERYKEY_RECOVER)
Lazy<Scene> recoverScene();
@FxmlScene(FxmlFile.RECOVERYKEY_IS_HUB_VAULT)
Lazy<Scene> recoverIsHubVaultScene();
default void showRecoveryKeyCreationWindow() {
Stage stage = window();
stage.setScene(creationScene().get());
@@ -46,6 +49,14 @@ public interface RecoveryKeyComponent {
stage.show();
}
default void showIsHubVaultDialogWindow(){
Stage stage = window();
stage.setScene(recoverIsHubVaultScene().get());
stage.setTitle("Recover Vault Config");
stage.sizeToScene();
stage.show();
}
@Subcomponent.Factory
interface Factory {

View File

@@ -0,0 +1,50 @@
package org.cryptomator.ui.recoverykey;
import dagger.Lazy;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.util.ResourceBundle;
@RecoveryKeyScoped
public class RecoveryKeyIsHubVaultController implements FxController {
private static final Logger LOG = LoggerFactory.getLogger(RecoveryKeyIsHubVaultController.class);
private final Stage window;
private final Lazy<Scene> recoverykeyRecoverScene;
@Inject
public RecoveryKeyIsHubVaultController(@RecoveryKeyWindow Stage window,
@RecoveryKeyWindow Vault vault,
@RecoveryKeyWindow StringProperty recoveryKey,
@FxmlScene(FxmlFile.RECOVERYKEY_RECOVER) Lazy<Scene> recoverykeyRecoverScene,
ResourceBundle resourceBundle) {
this.window = window;
//window.setTitle("Is it a hub vault? Huh?");
this.recoverykeyRecoverScene = recoverykeyRecoverScene;
}
@FXML
public void initialize() {
}
@FXML
public void close() {
window.close();
}
@FXML
public void recover() {
window.setScene(recoverykeyRecoverScene.get());
}
}

View File

@@ -112,6 +112,12 @@ abstract class RecoveryKeyModule {
return fxmlLoaders.createScene(FxmlFile.RECOVERYKEY_RESET_VAULT_CONFIG_SUCCESS);
}
@Provides
@FxmlScene(FxmlFile.RECOVERYKEY_IS_HUB_VAULT)
@RecoveryKeyScoped
static Scene provideRecoveryKeyIsHubVaultScene(@RecoveryKeyWindow FxmlLoaderFactory fxmlLoaders) {
return fxmlLoaders.createScene(FxmlFile.RECOVERYKEY_IS_HUB_VAULT);
}
// ------------------
@@ -127,6 +133,11 @@ abstract class RecoveryKeyModule {
return new RecoveryKeyDisplayController(window, vault.getDisplayName(), recoveryKey.get(), localization);
}
@Binds
@IntoMap
@FxControllerKey(RecoveryKeyIsHubVaultController.class)
abstract FxController provideRecoveryKeyIsHubVaultController(RecoveryKeyIsHubVaultController controller);
@Binds
@IntoMap
@FxControllerKey(RecoveryKeyRecoverController.class)

View File

@@ -2,6 +2,7 @@ package org.cryptomator.ui.recoverykey;
import dagger.Lazy;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.VaultState;
import org.cryptomator.cryptofs.CryptoFileSystemProperties;
import org.cryptomator.cryptofs.CryptoFileSystemProvider;
import org.cryptomator.cryptolib.api.CryptoException;
@@ -127,7 +128,12 @@ public class RecoveryKeyResetPasswordController implements FxController {
});
task.setOnSucceeded(event -> {
LOG.info("Used recovery key to reset password for {}.", vault.getDisplayablePath());
window.setScene(recoverResetPasswordSuccessScene.get());
if(vault.getState().equals(VaultState.Value.VAULT_CONFIG_MISSING)){
window.setScene(recoverResetVaultConfigSuccessScene.get());
}
else {
window.setScene(recoverResetPasswordSuccessScene.get());
}
});
task.setOnFailed(event -> {
LOG.error("Resetting password failed.", task.getException());

View File

@@ -0,0 +1,54 @@
<?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.Region?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.Group?>
<?import javafx.scene.shape.Circle?>
<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
<HBox xmlns:fx="http://javafx.com/fxml"
xmlns="http://javafx.com/javafx"
fx:controller="org.cryptomator.ui.recoverykey.RecoveryKeyIsHubVaultController"
minWidth="400"
maxWidth="400"
minHeight="145"
spacing="12"
alignment="TOP_CENTER">
<padding>
<Insets topRightBottomLeft="12"/>
</padding>
<children>
<Group>
<StackPane>
<padding>
<Insets topRightBottomLeft="6"/>
</padding>
<Circle styleClass="glyph-icon-primary" radius="24"/>
<FontAwesome5IconView styleClass="glyph-icon-white" glyph="QUESTION" glyphSize="24"/>
</StackPane>
</Group>
<VBox HBox.hgrow="ALWAYS">
<Label styleClass="label-large" text="Hub Vault or not?" wrapText="true">
<padding>
<Insets bottom="6" top="6"/>
</padding>
</Label>
<Label text="If your Vault is an Hub Vault you can restore the vault config .... Otherwise you need the recovery key of the vault to restore the config files." wrapText="true"/>
<Region VBox.vgrow="ALWAYS" minHeight="18"/>
<ButtonBar buttonMinWidth="120" buttonOrder="+C">
<buttons>
<Button text="%generic.button.close" ButtonBar.buttonData="CANCEL_CLOSE" cancelButton="true" onAction="#close"/>
<Button text="Use RecoveryKey" ButtonBar.buttonData="CANCEL_CLOSE" defaultButton="true" onAction="#recover"/>
</buttons>
</ButtonBar>
</VBox>
</children>
</HBox>