diff --git a/src/main/java/org/cryptomator/ui/sharevault/ShareVaultController.java b/src/main/java/org/cryptomator/ui/sharevault/ShareVaultController.java index c8a5abc5f..63230cbbf 100644 --- a/src/main/java/org/cryptomator/ui/sharevault/ShareVaultController.java +++ b/src/main/java/org/cryptomator/ui/sharevault/ShareVaultController.java @@ -9,28 +9,36 @@ import javax.inject.Inject; import javafx.application.Application; import javafx.fxml.FXML; import javafx.stage.Stage; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.URI; +import java.net.URISyntaxException; @ShareVaultScoped public class ShareVaultController implements FxController { + + private static final String SCHEME_PREFIX = "hub+"; private static final String VISIT_HUB_URL = "https://cryptomator.org/hub/"; - private static final String OPEN_HUB_URL = "https://cryptomator.org/hub/"; + private static final String BEST_PRACTICES_URL = "https://docs.cryptomator.org/en/latest/security/best-practices/#sharing-of-vaults"; private final Stage window; private final Lazy application; + private final Vault vault; private final Boolean hubVault; @Inject ShareVaultController(@ShareVaultWindow Stage window, // Lazy application, // - @ShareVaultWindow Vault vault){ + @ShareVaultWindow Vault vault) { this.window = window; this.application = application; + this.vault = vault; var vaultScheme = vault.getVaultConfigCache().getUnchecked().getKeyId().getScheme(); this.hubVault = (vaultScheme.equals(HubKeyLoadingStrategy.SCHEME_HUB_HTTP) || vaultScheme.equals(HubKeyLoadingStrategy.SCHEME_HUB_HTTPS)); } @FXML - public void close(){ + public void close() { window.close(); } @@ -38,9 +46,27 @@ public class ShareVaultController implements FxController { public void visitHub() { application.get().getHostServices().showDocument(VISIT_HUB_URL); } + @FXML public void openHub() { - application.get().getHostServices().showDocument(OPEN_HUB_URL); + application.get().getHostServices().showDocument(getHubUri(vault).toString()); + } + + @FXML + public void visitBestPractices() { + application.get().getHostServices().showDocument(BEST_PRACTICES_URL); + } + + private static URI getHubUri(Vault vault) { + try { + var keyID = new URI(vault.getVaultConfigCache().get().getKeyId().toString()); + assert keyID.getScheme().startsWith(SCHEME_PREFIX); + return new URI(keyID.getScheme().substring(SCHEME_PREFIX.length()) + "://" + keyID.getHost() + "/app/vaults"); + } catch (IOException e) { + throw new UncheckedIOException(e); + } catch (URISyntaxException e) { + throw new IllegalStateException("URI constructed from params known to be valid", e); + } } public boolean isHubVault() { diff --git a/src/main/resources/fxml/share_vault.fxml b/src/main/resources/fxml/share_vault.fxml index df9d7dcc8..6fd1782f0 100644 --- a/src/main/resources/fxml/share_vault.fxml +++ b/src/main/resources/fxml/share_vault.fxml @@ -12,20 +12,27 @@ - + + + + spacing="12"> - + - - + + + + + + + - - - - + + + + + - - - - - - -