From 1134c1b2fff597795264150a301d78d62b39497d Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 19 Jan 2021 15:27:46 +0100 Subject: [PATCH] closes #1471 hand the javafx hostservice showDocument() method from ui package to the underlying nio-adapter-libraries through --- .../cryptomator/common/vaults/DokanyVolume.java | 12 ++++++++---- .../cryptomator/common/vaults/FuseVolume.java | 8 ++++---- .../org/cryptomator/common/vaults/Vault.java | 4 ++-- .../org/cryptomator/common/vaults/Volume.java | 15 ++++++++++++++- .../cryptomator/common/vaults/WebDavVolume.java | 10 ++++------ main/pom.xml | 6 +++--- .../org/cryptomator/ui/common/VaultService.java | 17 ++++++++++++++--- .../org/cryptomator/ui/fxapp/FxApplication.java | 2 ++ 8 files changed, 51 insertions(+), 23 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java index e0379e9db..0da6452cc 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java @@ -8,6 +8,7 @@ import org.cryptomator.cryptofs.CryptoFileSystem; import org.cryptomator.frontend.dokany.Mount; import org.cryptomator.frontend.dokany.MountFactory; import org.cryptomator.frontend.dokany.MountFailedException; +import org.cryptomator.frontend.dokany.RevealException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,10 +53,12 @@ public class DokanyVolume extends AbstractVolume { } @Override - public void reveal() throws VolumeException { - boolean success = mount.reveal(); - if (!success) { - throw new VolumeException("Reveal failed."); + public void reveal(Revealer r) throws VolumeException { + try { + mount.reveal(r); + } catch (RevealException e) { + LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); + throw new VolumeException(e); } } @@ -79,6 +82,7 @@ public class DokanyVolume extends AbstractVolume { public boolean supportsForcedUnmount() { return true; } + @Override public boolean isSupported() { return DokanyVolume.isSupportedStatic(); diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java index e5c49d025..46db1221c 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java @@ -12,6 +12,7 @@ import org.cryptomator.frontend.fuse.mount.FuseMountFactory; import org.cryptomator.frontend.fuse.mount.FuseNotSupportedException; import org.cryptomator.frontend.fuse.mount.Mount; import org.cryptomator.frontend.fuse.mount.Mounter; +import org.cryptomator.frontend.fuse.mount.RevealException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,7 +21,6 @@ import javax.inject.Named; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; -import java.util.SortedSet; import java.util.regex.Pattern; public class FuseVolume extends AbstractVolume { @@ -73,10 +73,10 @@ public class FuseVolume extends AbstractVolume { } @Override - public void reveal() throws VolumeException { + public void reveal(Revealer r) throws VolumeException { try { - mount.revealInFileManager(); - } catch (CommandFailedException e) { + mount.reveal(r); + } catch (RevealException e) { LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); throw new VolumeException(e); } diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java b/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java index 5205d0fdd..adf39c6f2 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java @@ -148,8 +148,8 @@ public class Vault { } } - public void reveal() throws VolumeException { - volume.reveal(); + public void reveal(Volume.Revealer vaultRevealer) throws VolumeException { + volume.reveal(vaultRevealer); } // ****************************************************************************** diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/Volume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/Volume.java index 624efea13..5760ab1fe 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/Volume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/Volume.java @@ -3,6 +3,8 @@ package org.cryptomator.common.vaults; import org.cryptomator.common.mountpoint.InvalidMountPointException; import org.cryptomator.common.settings.VolumeImpl; import org.cryptomator.cryptofs.CryptoFileSystem; +import org.cryptomator.frontend.fuse.mount.Revealer; +import org.cryptomator.frontend.webdav.mount.Mounter; import java.io.IOException; import java.nio.file.Path; @@ -34,7 +36,11 @@ public interface Volume { */ void mount(CryptoFileSystem fs, String mountFlags) throws IOException, VolumeException, InvalidMountPointException; - void reveal() throws VolumeException; + /** + * TODO: refactor, such that this method accepts a (new) interface revealer and document that it could be ignored. + * @throws VolumeException + */ + void reveal(Revealer revealer) throws VolumeException; void unmount() throws VolumeException; @@ -79,4 +85,11 @@ public interface Volume { } + /** + * Interface to bundle the different revealer interfaces in the used nio-adapters + */ + interface Revealer extends org.cryptomator.frontend.fuse.mount.Revealer, org.cryptomator.frontend.dokany.Revealer, Mounter.Revealer{ + + } + } diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java index fe9246085..dc4cefe5a 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java @@ -29,7 +29,6 @@ public class WebDavVolume implements Volume { private WebDavServer server; private WebDavServletController servlet; private Mounter.Mount mount; - private Path mountPoint; @Inject public WebDavVolume(Provider serverProvider, VaultSettings vaultSettings, Settings settings) { @@ -71,11 +70,10 @@ public class WebDavVolume implements Volume { } @Override - public void reveal() throws VolumeException { + public void reveal(Revealer r) throws VolumeException { try { - mount.reveal(); - } catch (Mounter.CommandFailedException e) { - e.printStackTrace(); + mount.reveal(r); + } catch (Mounter.RevealException e) { throw new VolumeException(e); } } @@ -102,7 +100,7 @@ public class WebDavVolume implements Volume { @Override public Optional getMountPoint() { - return Optional.ofNullable(mountPoint); //TODO + return mount.getMountPoint(); } @Override diff --git a/main/pom.xml b/main/pom.xml index 0be3baa81..bcc9f0d9f 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -29,9 +29,9 @@ 0.2.1 0.1.0-beta3 0.1.0-beta2 - 1.2.6 - 1.2.1 - 1.0.14 + 1.3.0-SNAPSHOT + 1.3.0-SNAPSHOT + 1.1.0-SNAPSHOT 15 diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java b/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java index 1f4ffc3fd..2bd99ef98 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java @@ -15,6 +15,7 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @FxApplicationScoped @@ -24,22 +25,29 @@ public class VaultService { private final ExecutorService executorService; + private AtomicReference vaultRevealer; + @Inject public VaultService(ExecutorService executorService) { this.executorService = executorService; + this.vaultRevealer = new AtomicReference<>(p -> {}); //the inital revealer does nuthin } public void reveal(Vault vault) { executorService.execute(createRevealTask(vault)); } + public void setVaultRevealer(Volume.Revealer revealer){ + this.vaultRevealer.set(revealer); + } + /** * Creates but doesn't start a reveal task. * * @param vault The vault to reveal */ public Task createRevealTask(Vault vault) { - Task task = new RevealVaultTask(vault); + Task task = new RevealVaultTask(vault, vaultRevealer.get()); task.setOnSucceeded(evt -> LOG.info("Revealed {}", vault.getDisplayName())); task.setOnFailed(evt -> LOG.error("Failed to reveal " + vault.getDisplayName(), evt.getSource().getException())); return task; @@ -99,19 +107,22 @@ public class VaultService { private static class RevealVaultTask extends Task { private final Vault vault; + private final Volume.Revealer revealer; /** * @param vault The vault to lock + * @param revealer The object to use to show the vault content to the user. */ - public RevealVaultTask(Vault vault) { + public RevealVaultTask(Vault vault, Volume.Revealer revealer) { this.vault = vault; + this.revealer = revealer; setOnFailed(evt -> LOG.error("Failed to reveal " + vault.getDisplayName(), getException())); } @Override protected Vault call() throws Volume.VolumeException { - vault.reveal(); + vault.reveal(revealer); return vault; } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java b/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java index 65e6d1c6c..8633b6e8b 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java +++ b/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java @@ -68,6 +68,8 @@ public class FxApplication extends Application { this.licenseHolder = licenseHolder; this.visibleWindows = Stage.getWindows().filtered(Window::isShowing); this.hasVisibleWindows = Bindings.isNotEmpty(visibleWindows); + + vaultService.setVaultRevealer(p -> this.getHostServices().showDocument(p.toUri().toString())); } public void start() {