From 1134c1b2fff597795264150a301d78d62b39497d Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 19 Jan 2021 15:27:46 +0100 Subject: [PATCH 01/13] 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() { From 0312f045aad8ec41e33e8375def43a7e68a28224 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 19 Jan 2021 15:28:50 +0100 Subject: [PATCH 02/13] add a logger to WebDAV-Volume --- .../main/java/org/cryptomator/common/vaults/WebDavVolume.java | 4 ++++ 1 file changed, 4 insertions(+) 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 dc4cefe5a..e25e07465 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 @@ -10,6 +10,8 @@ import org.cryptomator.frontend.webdav.WebDavServer; import org.cryptomator.frontend.webdav.mount.MountParams; import org.cryptomator.frontend.webdav.mount.Mounter; import org.cryptomator.frontend.webdav.servlet.WebDavServletController; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.inject.Provider; @@ -20,6 +22,7 @@ import java.util.Optional; public class WebDavVolume implements Volume { + private static final Logger LOG = LoggerFactory.getLogger(WebDavVolume.class); private static final String LOCALHOST_ALIAS = "cryptomator-vault"; private final Provider serverProvider; @@ -74,6 +77,7 @@ public class WebDavVolume implements Volume { try { mount.reveal(r); } catch (Mounter.RevealException e) { + LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); throw new VolumeException(e); } } From 93445e22d4cf27c78a6cb77859eb8dc8be3bb254 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Thu, 21 Jan 2021 06:37:41 +0100 Subject: [PATCH 03/13] update library versions --- main/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main/pom.xml b/main/pom.xml index bcc9f0d9f..dda21d3b6 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.3.0-SNAPSHOT - 1.3.0-SNAPSHOT - 1.1.0-SNAPSHOT + 1.2.7 + 1.2.2 + 1.1.0 15 From 77db435b4fec3a9b39e5c8bab7cc433a538b36dc Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 21 Jan 2021 12:41:52 +0100 Subject: [PATCH 04/13] Refactor reveal call stack to apply facade pattern. --- .../cryptomator/common/vaults/DokanyVolume.java | 16 +++++++++++++--- .../cryptomator/common/vaults/FuseVolume.java | 16 +++++++++++++--- .../org/cryptomator/common/vaults/Vault.java | 2 +- .../org/cryptomator/common/vaults/Volume.java | 13 ++++++------- .../cryptomator/common/vaults/WebDavVolume.java | 16 +++++++++++++--- .../org/cryptomator/ui/common/VaultService.java | 8 ++++---- 6 files changed, 50 insertions(+), 21 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 0da6452cc..e00c7c6ee 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 @@ -53,12 +53,22 @@ public class DokanyVolume extends AbstractVolume { } @Override - public void reveal(Revealer r) throws VolumeException { + public void reveal(RevealerFacade r) throws VolumeException { try { - mount.reveal(r); + mount.reveal(p -> { + try { + r.reveal(p); + } catch (VolumeException e) { + throw new RevealException(e); + } + }); } catch (RevealException e) { LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); - throw new VolumeException(e); + if (e.getCause() instanceof VolumeException) { + throw (VolumeException) e.getCause(); + } else { + throw new VolumeException(e); + } } } 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 46db1221c..191b47526 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 @@ -73,12 +73,22 @@ public class FuseVolume extends AbstractVolume { } @Override - public void reveal(Revealer r) throws VolumeException { + public void reveal(RevealerFacade r) throws VolumeException { try { - mount.reveal(r); + mount.reveal(p -> { + try { + r.reveal(p); + } catch (VolumeException e) { + throw new RevealException(e); + } + }); } catch (RevealException e) { LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); - throw new VolumeException(e); + if (e.getCause() instanceof VolumeException) { + throw (VolumeException) e.getCause(); + } else { + 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 adf39c6f2..fd301c3bd 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,7 +148,7 @@ public class Vault { } } - public void reveal(Volume.Revealer vaultRevealer) throws VolumeException { + public void reveal(Volume.RevealerFacade 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 5760ab1fe..644cd9ac1 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,8 +3,6 @@ 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; @@ -38,9 +36,10 @@ public interface Volume { /** * 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 reveal(RevealerFacade revealer) throws VolumeException; void unmount() throws VolumeException; @@ -85,10 +84,10 @@ 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{ + @FunctionalInterface + interface RevealerFacade { + + void reveal(Path p) throws VolumeException; } 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 e25e07465..7af21d01a 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 @@ -73,12 +73,22 @@ public class WebDavVolume implements Volume { } @Override - public void reveal(Revealer r) throws VolumeException { + public void reveal(RevealerFacade r) throws VolumeException { try { - mount.reveal(r); + mount.reveal(p -> { + try { + r.reveal(p); + } catch (VolumeException e) { + throw new Mounter.RevealException(e); + } + }); } catch (Mounter.RevealException e) { LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); - throw new VolumeException(e); + if (e.getCause() instanceof VolumeException) { + throw (VolumeException) e.getCause(); + } else { + throw new VolumeException(e); + } } } 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 2bd99ef98..4b9226acd 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 @@ -25,7 +25,7 @@ public class VaultService { private final ExecutorService executorService; - private AtomicReference vaultRevealer; + private AtomicReference vaultRevealer; @Inject public VaultService(ExecutorService executorService) { @@ -37,7 +37,7 @@ public class VaultService { executorService.execute(createRevealTask(vault)); } - public void setVaultRevealer(Volume.Revealer revealer){ + public void setVaultRevealer(Volume.RevealerFacade revealer) { this.vaultRevealer.set(revealer); } @@ -107,13 +107,13 @@ public class VaultService { private static class RevealVaultTask extends Task { private final Vault vault; - private final Volume.Revealer revealer; + private final Volume.RevealerFacade 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, Volume.Revealer revealer) { + public RevealVaultTask(Vault vault, Volume.RevealerFacade revealer) { this.vault = vault; this.revealer = revealer; From 886753221029ac0135b99f98f9c360904d65e65f Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 21 Jan 2021 12:42:00 +0100 Subject: [PATCH 05/13] add javadoc --- .../main/java/org/cryptomator/common/vaults/Volume.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 644cd9ac1..bf59423b4 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 @@ -35,8 +35,11 @@ public interface Volume { void mount(CryptoFileSystem fs, String mountFlags) throws IOException, VolumeException, InvalidMountPointException; /** - * TODO: refactor, such that this method accepts a (new) interface revealer and document that it could be ignored. + * Reveals the mounted volume. + *

+ * The given {@code revealer} might be used to do it, but not necessarily. * + * @param revealer An object capable of revealing the location of the mounted vault to view the content (e.g. in the default file browser). * @throws VolumeException */ void reveal(RevealerFacade revealer) throws VolumeException; @@ -84,6 +87,9 @@ public interface Volume { } + /** + * Hides and unifies the different Revealer implementations in the different nio-adapters. + */ @FunctionalInterface interface RevealerFacade { From 92b390d5bb68384caf0e3d4648d758071a5caefd Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 21 Jan 2021 12:44:32 +0100 Subject: [PATCH 06/13] update third-party licenses --- main/ui/src/main/resources/license/THIRD-PARTY.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main/ui/src/main/resources/license/THIRD-PARTY.txt b/main/ui/src/main/resources/license/THIRD-PARTY.txt index b4f3ee28e..30a364776 100644 --- a/main/ui/src/main/resources/license/THIRD-PARTY.txt +++ b/main/ui/src/main/resources/license/THIRD-PARTY.txt @@ -11,7 +11,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. -Cryptomator uses 47 third-party dependencies under the following licenses: +Cryptomator uses 46 third-party dependencies under the following licenses: Apache License v2.0: - jffi (com.github.jnr:jffi:1.2.23 - http://github.com/jnr/jffi) - jnr-a64asm (com.github.jnr:jnr-a64asm:1.0.0 - http://nexus.sonatype.org/oss-repository-hosting.html/jnr-a64asm) @@ -26,7 +26,6 @@ Cryptomator uses 47 third-party dependencies under the following licenses: - Guava ListenableFuture only (com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava - https://github.com/google/guava/listenablefuture) - J2ObjC Annotations (com.google.j2objc:j2objc-annotations:1.3 - https://github.com/google/j2objc/) - Apache Commons CLI (commons-cli:commons-cli:1.4 - http://commons.apache.org/proper/commons-cli/) - - Apache Commons IO (commons-io:commons-io:2.6 - http://commons.apache.org/proper/commons-io/) - javax.inject (javax.inject:javax.inject:1 - http://code.google.com/p/atinject/) - Java Native Access (net.java.dev.jna:jna:5.6.0 - https://github.com/java-native-access/jna) - Java Native Access Platform (net.java.dev.jna:jna-platform:5.5.0 - https://github.com/java-native-access/jna) From 81fb6b879453aeebc0d414703d1d2c6050c77c5c Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Thu, 21 Jan 2021 15:06:37 +0100 Subject: [PATCH 07/13] get rid of RevealException --- .../common/vaults/DokanyVolume.java | 20 ++++--------------- .../cryptomator/common/vaults/FuseVolume.java | 20 ++++--------------- .../common/vaults/WebDavVolume.java | 19 ++++-------------- main/pom.xml | 6 +++--- 4 files changed, 15 insertions(+), 50 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 e00c7c6ee..e51d50fd3 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,7 +8,6 @@ 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; @@ -53,22 +52,11 @@ public class DokanyVolume extends AbstractVolume { } @Override - public void reveal(RevealerFacade r) throws VolumeException { + public void reveal(RevealerFacade revealer) throws VolumeException { try { - mount.reveal(p -> { - try { - r.reveal(p); - } catch (VolumeException e) { - throw new RevealException(e); - } - }); - } catch (RevealException e) { - LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); - if (e.getCause() instanceof VolumeException) { - throw (VolumeException) e.getCause(); - } else { - throw new VolumeException(e); - } + mount.reveal(revealer::reveal); + } catch (Exception e) { + throw new VolumeException(e); } } 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 191b47526..b8d3b650d 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,7 +12,6 @@ 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; @@ -73,22 +72,11 @@ public class FuseVolume extends AbstractVolume { } @Override - public void reveal(RevealerFacade r) throws VolumeException { + public void reveal(RevealerFacade revealer) throws VolumeException { try { - mount.reveal(p -> { - try { - r.reveal(p); - } catch (VolumeException e) { - throw new RevealException(e); - } - }); - } catch (RevealException e) { - LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); - if (e.getCause() instanceof VolumeException) { - throw (VolumeException) e.getCause(); - } else { - throw new VolumeException(e); - } + mount.reveal(revealer::reveal); + } catch (Exception e) { + throw new VolumeException(e); } } 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 7af21d01a..312098303 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 @@ -73,22 +73,11 @@ public class WebDavVolume implements Volume { } @Override - public void reveal(RevealerFacade r) throws VolumeException { + public void reveal(RevealerFacade revealer) throws VolumeException { try { - mount.reveal(p -> { - try { - r.reveal(p); - } catch (VolumeException e) { - throw new Mounter.RevealException(e); - } - }); - } catch (Mounter.RevealException e) { - LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); - if (e.getCause() instanceof VolumeException) { - throw (VolumeException) e.getCause(); - } else { - throw new VolumeException(e); - } + mount.reveal(revealer::reveal); + } catch (Exception e) { + throw new VolumeException(e); } } diff --git a/main/pom.xml b/main/pom.xml index dda21d3b6..fbeed196e 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.7 - 1.2.2 - 1.1.0 + 1.2.8 + 1.2.3 + 1.1.1 15 From d5eb84a000d6273366eda487fa05171271e84f10 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 21 Jan 2021 15:26:35 +0100 Subject: [PATCH 08/13] change reveal method in vault service: * revealer is no member anymore * reveal() takes as second argument revealer object * several other classes hand over a revealer object * added awt-revealer if application is not yet started --- .../cryptomator/ui/common/VaultService.java | 15 +++-------- .../cryptomator/ui/fxapp/FxApplication.java | 2 -- .../VaultDetailUnlockedController.java | 2 +- .../ui/traymenu/TrayMenuComponent.java | 3 +-- .../ui/traymenu/TrayMenuController.java | 7 +++-- .../ui/traymenu/TrayMenuModule.java | 27 +++++++++++++++++++ .../ui/unlock/UnlockSuccessController.java | 7 +++-- .../cryptomator/ui/unlock/UnlockWorkflow.java | 7 +++-- 8 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java 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 4b9226acd..4baa9526c 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 @@ -25,20 +25,13 @@ 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.RevealerFacade revealer) { - this.vaultRevealer.set(revealer); + public void reveal(Vault vault, Volume.RevealerFacade vaultRevealCmd) { + executorService.execute(createRevealTask(vault, vaultRevealCmd)); } /** @@ -46,8 +39,8 @@ public class VaultService { * * @param vault The vault to reveal */ - public Task createRevealTask(Vault vault) { - Task task = new RevealVaultTask(vault, vaultRevealer.get()); + public Task createRevealTask(Vault vault, Volume.RevealerFacade vaultRevealCmd) { + Task task = new RevealVaultTask(vault, vaultRevealCmd); task.setOnSucceeded(evt -> LOG.info("Revealed {}", vault.getDisplayName())); task.setOnFailed(evt -> LOG.error("Failed to reveal " + vault.getDisplayName(), evt.getSource().getException())); return task; 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 8633b6e8b..65e6d1c6c 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,8 +68,6 @@ 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() { diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java index 0af909bbc..b85fa8bda 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java @@ -42,7 +42,7 @@ public class VaultDetailUnlockedController implements FxController { @FXML public void revealAccessLocation() { - vaultService.reveal(vault.get()); + vaultService.reveal(vault.get(), p -> application.getHostServices().showDocument(p.toUri().toString())); } @FXML diff --git a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuComponent.java b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuComponent.java index a4e068f8d..75e1b793c 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuComponent.java +++ b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuComponent.java @@ -7,11 +7,10 @@ package org.cryptomator.ui.traymenu; import dagger.Lazy; import dagger.Subcomponent; - import java.awt.SystemTray; @TrayMenuScoped -@Subcomponent +@Subcomponent(modules = TrayMenuModule.class) public interface TrayMenuComponent { Lazy trayIconController(); diff --git a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java index 96529c5fb..fada2b061 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java @@ -1,6 +1,7 @@ package org.cryptomator.ui.traymenu; import org.cryptomator.common.vaults.Vault; +import org.cryptomator.common.vaults.Volume; import org.cryptomator.ui.fxapp.FxApplication; import org.cryptomator.ui.launcher.AppLifecycleListener; import org.cryptomator.ui.launcher.FxApplicationStarter; @@ -27,14 +28,16 @@ class TrayMenuController { private final AppLifecycleListener appLifecycle; private final FxApplicationStarter fxApplicationStarter; private final ObservableList vaults; + private final Volume.RevealerFacade revealer; private final PopupMenu menu; @Inject - TrayMenuController(ResourceBundle resourceBundle, AppLifecycleListener appLifecycle, FxApplicationStarter fxApplicationStarter, ObservableList vaults) { + TrayMenuController(ResourceBundle resourceBundle, AppLifecycleListener appLifecycle, FxApplicationStarter fxApplicationStarter, ObservableList vaults, Volume.RevealerFacade revealer) { this.resourceBundle = resourceBundle; this.appLifecycle = appLifecycle; this.fxApplicationStarter = fxApplicationStarter; this.vaults = vaults; + this.revealer = revealer; this.menu = new PopupMenu(); } @@ -121,7 +124,7 @@ class TrayMenuController { } private void revealVault(Vault vault) { - showMainAppAndThen(app -> app.getVaultService().reveal(vault)); + showMainAppAndThen(app -> app.getVaultService().reveal(vault, revealer)); } void showMainWindow(@SuppressWarnings("unused") ActionEvent actionEvent) { diff --git a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java new file mode 100644 index 000000000..65227a880 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java @@ -0,0 +1,27 @@ +package org.cryptomator.ui.traymenu; + +import dagger.Module; +import dagger.Provides; +import org.cryptomator.common.vaults.Volume; + +import java.awt.Desktop; +import java.io.IOException; + +@Module +abstract class TrayMenuModule { + + @Provides + static Volume.RevealerFacade provideAwtRevealer(){ + return p -> { + if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { + try { + Desktop.getDesktop().open(p.toFile()); + } catch (IOException e) { + throw new Volume.VolumeException(e); + } + } else { + throw new Volume.VolumeException("API to browse files not supported. Please try again from inside the application."); + } + }; + } +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockSuccessController.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockSuccessController.java index ee3ffc5ae..ef1d4fdf3 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockSuccessController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockSuccessController.java @@ -4,6 +4,7 @@ import org.cryptomator.common.settings.WhenUnlocked; import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.VaultService; +import org.cryptomator.ui.fxapp.FxApplication; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,17 +30,19 @@ public class UnlockSuccessController implements FxController { private final Vault vault; private final ExecutorService executor; private final VaultService vaultService; + private final FxApplication application; private final ObjectProperty revealButtonState; private final BooleanProperty revealButtonDisabled; public CheckBox rememberChoiceCheckbox; @Inject - public UnlockSuccessController(@UnlockWindow Stage window, @UnlockWindow Vault vault, ExecutorService executor, VaultService vaultService) { + public UnlockSuccessController(@UnlockWindow Stage window, @UnlockWindow Vault vault, ExecutorService executor, VaultService vaultService, FxApplication application) { this.window = window; this.vault = vault; this.executor = executor; this.vaultService = vaultService; + this.application = application; this.revealButtonState = new SimpleObjectProperty<>(ContentDisplay.TEXT_ONLY); this.revealButtonDisabled = new SimpleBooleanProperty(); } @@ -59,7 +62,7 @@ public class UnlockSuccessController implements FxController { revealButtonState.set(ContentDisplay.LEFT); revealButtonDisabled.set(true); - Task revealTask = vaultService.createRevealTask(vault); + Task revealTask = vaultService.createRevealTask(vault, p -> application.getHostServices().showDocument(p.toUri().toString())); revealTask.setOnSucceeded(evt -> { revealButtonState.set(ContentDisplay.TEXT_ONLY); revealButtonDisabled.set(false); diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index 8cb7e0752..87e666f2d 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java @@ -15,6 +15,7 @@ import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.common.UserInteractionLock; import org.cryptomator.ui.common.VaultService; +import org.cryptomator.ui.fxapp.FxApplication; import org.cryptomator.ui.unlock.UnlockModule.PasswordEntry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,9 +59,10 @@ public class UnlockWorkflow extends Task { private final Lazy successScene; private final Lazy invalidMountPointScene; private final ErrorComponent.Builder errorComponent; + private final FxApplication application; @Inject - UnlockWorkflow(@UnlockWindow Stage window, @UnlockWindow Vault vault, VaultService vaultService, AtomicReference password, @Named("savePassword") AtomicBoolean savePassword, @Named("savedPassword") Optional savedPassword, UserInteractionLock passwordEntryLock, KeychainManager keychain, @FxmlScene(FxmlFile.UNLOCK) Lazy unlockScene, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy invalidMountPointScene, ErrorComponent.Builder errorComponent) { + UnlockWorkflow(@UnlockWindow Stage window, @UnlockWindow Vault vault, VaultService vaultService, AtomicReference password, @Named("savePassword") AtomicBoolean savePassword, @Named("savedPassword") Optional savedPassword, UserInteractionLock passwordEntryLock, KeychainManager keychain, @FxmlScene(FxmlFile.UNLOCK) Lazy unlockScene, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy invalidMountPointScene, ErrorComponent.Builder errorComponent, FxApplication application) { this.window = window; this.vault = vault; this.vaultService = vaultService; @@ -73,6 +75,7 @@ public class UnlockWorkflow extends Task { this.successScene = successScene; this.invalidMountPointScene = invalidMountPointScene; this.errorComponent = errorComponent; + this.application = application; setOnFailed(event -> { Throwable throwable = event.getSource().getException(); @@ -143,7 +146,7 @@ public class UnlockWorkflow extends Task { }); case REVEAL -> { Platform.runLater(window::close); - vaultService.reveal(vault); + vaultService.reveal(vault, p -> application.getHostServices().showDocument(p.toUri().toString())); } case IGNORE -> Platform.runLater(window::close); } From 89774406974f07f8d371672dcef8cdbe43dbc785 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 21 Jan 2021 15:29:04 +0100 Subject: [PATCH 09/13] Rename RevealerFacade to Revealer --- .../java/org/cryptomator/common/vaults/DokanyVolume.java | 2 +- .../java/org/cryptomator/common/vaults/FuseVolume.java | 2 +- .../main/java/org/cryptomator/common/vaults/Vault.java | 2 +- .../main/java/org/cryptomator/common/vaults/Volume.java | 4 ++-- .../java/org/cryptomator/common/vaults/WebDavVolume.java | 2 +- .../java/org/cryptomator/ui/common/VaultService.java | 9 ++++----- .../org/cryptomator/ui/traymenu/TrayMenuController.java | 4 ++-- .../java/org/cryptomator/ui/traymenu/TrayMenuModule.java | 2 +- 8 files changed, 13 insertions(+), 14 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 e51d50fd3..a33dbd5ee 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 @@ -52,7 +52,7 @@ public class DokanyVolume extends AbstractVolume { } @Override - public void reveal(RevealerFacade revealer) throws VolumeException { + public void reveal(Revealer revealer) throws VolumeException { try { mount.reveal(revealer::reveal); } catch (Exception e) { 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 b8d3b650d..5400f8ff2 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 @@ -72,7 +72,7 @@ public class FuseVolume extends AbstractVolume { } @Override - public void reveal(RevealerFacade revealer) throws VolumeException { + public void reveal(Revealer revealer) throws VolumeException { try { mount.reveal(revealer::reveal); } catch (Exception 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 fd301c3bd..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,7 +148,7 @@ public class Vault { } } - public void reveal(Volume.RevealerFacade vaultRevealer) throws VolumeException { + 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 bf59423b4..74a307d5a 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 @@ -42,7 +42,7 @@ public interface Volume { * @param revealer An object capable of revealing the location of the mounted vault to view the content (e.g. in the default file browser). * @throws VolumeException */ - void reveal(RevealerFacade revealer) throws VolumeException; + void reveal(Revealer revealer) throws VolumeException; void unmount() throws VolumeException; @@ -91,7 +91,7 @@ public interface Volume { * Hides and unifies the different Revealer implementations in the different nio-adapters. */ @FunctionalInterface - interface RevealerFacade { + interface Revealer { void reveal(Path p) throws VolumeException; 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 312098303..072851272 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 @@ -73,7 +73,7 @@ public class WebDavVolume implements Volume { } @Override - public void reveal(RevealerFacade revealer) throws VolumeException { + public void reveal(Revealer revealer) throws VolumeException { try { mount.reveal(revealer::reveal); } catch (Exception e) { 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 4baa9526c..775b953bb 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,7 +15,6 @@ 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 @@ -30,7 +29,7 @@ public class VaultService { this.executorService = executorService; } - public void reveal(Vault vault, Volume.RevealerFacade vaultRevealCmd) { + public void reveal(Vault vault, Volume.Revealer vaultRevealCmd) { executorService.execute(createRevealTask(vault, vaultRevealCmd)); } @@ -39,7 +38,7 @@ public class VaultService { * * @param vault The vault to reveal */ - public Task createRevealTask(Vault vault, Volume.RevealerFacade vaultRevealCmd) { + public Task createRevealTask(Vault vault, Volume.Revealer vaultRevealCmd) { Task task = new RevealVaultTask(vault, vaultRevealCmd); task.setOnSucceeded(evt -> LOG.info("Revealed {}", vault.getDisplayName())); task.setOnFailed(evt -> LOG.error("Failed to reveal " + vault.getDisplayName(), evt.getSource().getException())); @@ -100,13 +99,13 @@ public class VaultService { private static class RevealVaultTask extends Task { private final Vault vault; - private final Volume.RevealerFacade revealer; + 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, Volume.RevealerFacade revealer) { + public RevealVaultTask(Vault vault, Volume.Revealer revealer) { this.vault = vault; this.revealer = revealer; diff --git a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java index fada2b061..9d45b1b68 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java @@ -28,11 +28,11 @@ class TrayMenuController { private final AppLifecycleListener appLifecycle; private final FxApplicationStarter fxApplicationStarter; private final ObservableList vaults; - private final Volume.RevealerFacade revealer; + private final Volume.Revealer revealer; private final PopupMenu menu; @Inject - TrayMenuController(ResourceBundle resourceBundle, AppLifecycleListener appLifecycle, FxApplicationStarter fxApplicationStarter, ObservableList vaults, Volume.RevealerFacade revealer) { + TrayMenuController(ResourceBundle resourceBundle, AppLifecycleListener appLifecycle, FxApplicationStarter fxApplicationStarter, ObservableList vaults, Volume.Revealer revealer) { this.resourceBundle = resourceBundle; this.appLifecycle = appLifecycle; this.fxApplicationStarter = fxApplicationStarter; diff --git a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java index 65227a880..99cf3d441 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java @@ -11,7 +11,7 @@ import java.io.IOException; abstract class TrayMenuModule { @Provides - static Volume.RevealerFacade provideAwtRevealer(){ + static Volume.Revealer provideAwtRevealer(){ return p -> { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { try { From 95cef3423465b45fe3c374adc67f440f974ff966 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 21 Jan 2021 16:09:16 +0100 Subject: [PATCH 10/13] remove unnecessary awtReavealer and trayModule --- .../ui/traymenu/TrayMenuComponent.java | 2 +- .../ui/traymenu/TrayMenuController.java | 9 +++---- .../ui/traymenu/TrayMenuModule.java | 27 ------------------- 3 files changed, 5 insertions(+), 33 deletions(-) delete mode 100644 main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java diff --git a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuComponent.java b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuComponent.java index 75e1b793c..c4cbfd456 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuComponent.java +++ b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuComponent.java @@ -10,7 +10,7 @@ import dagger.Subcomponent; import java.awt.SystemTray; @TrayMenuScoped -@Subcomponent(modules = TrayMenuModule.class) +@Subcomponent public interface TrayMenuComponent { Lazy trayIconController(); diff --git a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java index 9d45b1b68..3311450e9 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java @@ -1,7 +1,6 @@ package org.cryptomator.ui.traymenu; import org.cryptomator.common.vaults.Vault; -import org.cryptomator.common.vaults.Volume; import org.cryptomator.ui.fxapp.FxApplication; import org.cryptomator.ui.launcher.AppLifecycleListener; import org.cryptomator.ui.launcher.FxApplicationStarter; @@ -28,16 +27,14 @@ class TrayMenuController { private final AppLifecycleListener appLifecycle; private final FxApplicationStarter fxApplicationStarter; private final ObservableList vaults; - private final Volume.Revealer revealer; private final PopupMenu menu; @Inject - TrayMenuController(ResourceBundle resourceBundle, AppLifecycleListener appLifecycle, FxApplicationStarter fxApplicationStarter, ObservableList vaults, Volume.Revealer revealer) { + TrayMenuController(ResourceBundle resourceBundle, AppLifecycleListener appLifecycle, FxApplicationStarter fxApplicationStarter, ObservableList vaults) { this.resourceBundle = resourceBundle; this.appLifecycle = appLifecycle; this.fxApplicationStarter = fxApplicationStarter; this.vaults = vaults; - this.revealer = revealer; this.menu = new PopupMenu(); } @@ -124,7 +121,9 @@ class TrayMenuController { } private void revealVault(Vault vault) { - showMainAppAndThen(app -> app.getVaultService().reveal(vault, revealer)); + showMainAppAndThen(app -> // + app.getVaultService().reveal(vault, p -> app.getHostServices().showDocument(p.toUri().toString())) // + ); } void showMainWindow(@SuppressWarnings("unused") ActionEvent actionEvent) { diff --git a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java deleted file mode 100644 index 99cf3d441..000000000 --- a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.cryptomator.ui.traymenu; - -import dagger.Module; -import dagger.Provides; -import org.cryptomator.common.vaults.Volume; - -import java.awt.Desktop; -import java.io.IOException; - -@Module -abstract class TrayMenuModule { - - @Provides - static Volume.Revealer provideAwtRevealer(){ - return p -> { - if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { - try { - Desktop.getDesktop().open(p.toFile()); - } catch (IOException e) { - throw new Volume.VolumeException(e); - } - } else { - throw new Volume.VolumeException("API to browse files not supported. Please try again from inside the application."); - } - }; - } -} From 7cd5c6683607aa667d8cf43f3e86c6e6e2343773 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 21 Jan 2021 17:25:23 +0100 Subject: [PATCH 11/13] Refactor reveal() methods: * new class HostServiceRevealer implemeting the Volume.Revealer-Interface * this class is injected in vault service and always used for revealing * removed Revealer parameter from several reveal methods --- .../ui/common/HostServiceRevealer.java | 24 +++++++++++++++++++ .../cryptomator/ui/common/VaultService.java | 12 ++++++---- .../VaultDetailUnlockedController.java | 2 +- .../ui/traymenu/TrayMenuController.java | 4 +--- .../ui/unlock/UnlockSuccessController.java | 7 ++---- .../cryptomator/ui/unlock/UnlockWorkflow.java | 7 ++---- 6 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/common/HostServiceRevealer.java diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/HostServiceRevealer.java b/main/ui/src/main/java/org/cryptomator/ui/common/HostServiceRevealer.java new file mode 100644 index 000000000..966fd00bb --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/common/HostServiceRevealer.java @@ -0,0 +1,24 @@ +package org.cryptomator.ui.common; + +import org.cryptomator.common.vaults.Volume; +import org.cryptomator.ui.launcher.FxApplicationStarter; + +import javax.inject.Inject; +import javax.inject.Singleton; +import java.nio.file.Path; + +@Singleton +public class HostServiceRevealer implements Volume.Revealer { + + private final FxApplicationStarter fxApplicationStarter; + + @Inject + public HostServiceRevealer(FxApplicationStarter fxApplicationStarter) { + this.fxApplicationStarter = fxApplicationStarter; + } + + @Override + public void reveal(Path p) throws Volume.VolumeException { + fxApplicationStarter.get().thenAccept(app -> app.getHostServices().showDocument(p.toUri().toString())); + } +} 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 775b953bb..57393b858 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 @@ -23,14 +23,16 @@ public class VaultService { private static final Logger LOG = LoggerFactory.getLogger(VaultService.class); private final ExecutorService executorService; + private final HostServiceRevealer vaultRevealer; @Inject - public VaultService(ExecutorService executorService) { + public VaultService(ExecutorService executorService, HostServiceRevealer vaultRevealer) { this.executorService = executorService; + this.vaultRevealer = vaultRevealer; } - public void reveal(Vault vault, Volume.Revealer vaultRevealCmd) { - executorService.execute(createRevealTask(vault, vaultRevealCmd)); + public void reveal(Vault vault) { + executorService.execute(createRevealTask(vault)); } /** @@ -38,8 +40,8 @@ public class VaultService { * * @param vault The vault to reveal */ - public Task createRevealTask(Vault vault, Volume.Revealer vaultRevealCmd) { - Task task = new RevealVaultTask(vault, vaultRevealCmd); + public Task createRevealTask(Vault vault) { + Task task = new RevealVaultTask(vault, vaultRevealer); task.setOnSucceeded(evt -> LOG.info("Revealed {}", vault.getDisplayName())); task.setOnFailed(evt -> LOG.error("Failed to reveal " + vault.getDisplayName(), evt.getSource().getException())); return task; diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java index b85fa8bda..0af909bbc 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java @@ -42,7 +42,7 @@ public class VaultDetailUnlockedController implements FxController { @FXML public void revealAccessLocation() { - vaultService.reveal(vault.get(), p -> application.getHostServices().showDocument(p.toUri().toString())); + vaultService.reveal(vault.get()); } @FXML diff --git a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java index 3311450e9..96529c5fb 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java @@ -121,9 +121,7 @@ class TrayMenuController { } private void revealVault(Vault vault) { - showMainAppAndThen(app -> // - app.getVaultService().reveal(vault, p -> app.getHostServices().showDocument(p.toUri().toString())) // - ); + showMainAppAndThen(app -> app.getVaultService().reveal(vault)); } void showMainWindow(@SuppressWarnings("unused") ActionEvent actionEvent) { diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockSuccessController.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockSuccessController.java index ef1d4fdf3..ee3ffc5ae 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockSuccessController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockSuccessController.java @@ -4,7 +4,6 @@ import org.cryptomator.common.settings.WhenUnlocked; import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.VaultService; -import org.cryptomator.ui.fxapp.FxApplication; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,19 +29,17 @@ public class UnlockSuccessController implements FxController { private final Vault vault; private final ExecutorService executor; private final VaultService vaultService; - private final FxApplication application; private final ObjectProperty revealButtonState; private final BooleanProperty revealButtonDisabled; public CheckBox rememberChoiceCheckbox; @Inject - public UnlockSuccessController(@UnlockWindow Stage window, @UnlockWindow Vault vault, ExecutorService executor, VaultService vaultService, FxApplication application) { + public UnlockSuccessController(@UnlockWindow Stage window, @UnlockWindow Vault vault, ExecutorService executor, VaultService vaultService) { this.window = window; this.vault = vault; this.executor = executor; this.vaultService = vaultService; - this.application = application; this.revealButtonState = new SimpleObjectProperty<>(ContentDisplay.TEXT_ONLY); this.revealButtonDisabled = new SimpleBooleanProperty(); } @@ -62,7 +59,7 @@ public class UnlockSuccessController implements FxController { revealButtonState.set(ContentDisplay.LEFT); revealButtonDisabled.set(true); - Task revealTask = vaultService.createRevealTask(vault, p -> application.getHostServices().showDocument(p.toUri().toString())); + Task revealTask = vaultService.createRevealTask(vault); revealTask.setOnSucceeded(evt -> { revealButtonState.set(ContentDisplay.TEXT_ONLY); revealButtonDisabled.set(false); diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index 87e666f2d..8cb7e0752 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java @@ -15,7 +15,6 @@ import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.common.UserInteractionLock; import org.cryptomator.ui.common.VaultService; -import org.cryptomator.ui.fxapp.FxApplication; import org.cryptomator.ui.unlock.UnlockModule.PasswordEntry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,10 +58,9 @@ public class UnlockWorkflow extends Task { private final Lazy successScene; private final Lazy invalidMountPointScene; private final ErrorComponent.Builder errorComponent; - private final FxApplication application; @Inject - UnlockWorkflow(@UnlockWindow Stage window, @UnlockWindow Vault vault, VaultService vaultService, AtomicReference password, @Named("savePassword") AtomicBoolean savePassword, @Named("savedPassword") Optional savedPassword, UserInteractionLock passwordEntryLock, KeychainManager keychain, @FxmlScene(FxmlFile.UNLOCK) Lazy unlockScene, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy invalidMountPointScene, ErrorComponent.Builder errorComponent, FxApplication application) { + UnlockWorkflow(@UnlockWindow Stage window, @UnlockWindow Vault vault, VaultService vaultService, AtomicReference password, @Named("savePassword") AtomicBoolean savePassword, @Named("savedPassword") Optional savedPassword, UserInteractionLock passwordEntryLock, KeychainManager keychain, @FxmlScene(FxmlFile.UNLOCK) Lazy unlockScene, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy invalidMountPointScene, ErrorComponent.Builder errorComponent) { this.window = window; this.vault = vault; this.vaultService = vaultService; @@ -75,7 +73,6 @@ public class UnlockWorkflow extends Task { this.successScene = successScene; this.invalidMountPointScene = invalidMountPointScene; this.errorComponent = errorComponent; - this.application = application; setOnFailed(event -> { Throwable throwable = event.getSource().getException(); @@ -146,7 +143,7 @@ public class UnlockWorkflow extends Task { }); case REVEAL -> { Platform.runLater(window::close); - vaultService.reveal(vault, p -> application.getHostServices().showDocument(p.toUri().toString())); + vaultService.reveal(vault); } case IGNORE -> Platform.runLater(window::close); } From b1d7cfc81bb8ae73567af09b8d86c98ae2bdeec4 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Fri, 22 Jan 2021 09:31:43 +0100 Subject: [PATCH 12/13] change scope of HostServiceRevealer to @FxApplicationScoped because unlock always happens after application start anyway --- .../ui/common/HostServiceRevealer.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/HostServiceRevealer.java b/main/ui/src/main/java/org/cryptomator/ui/common/HostServiceRevealer.java index 966fd00bb..829480592 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/HostServiceRevealer.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/HostServiceRevealer.java @@ -1,24 +1,25 @@ package org.cryptomator.ui.common; +import dagger.Lazy; import org.cryptomator.common.vaults.Volume; -import org.cryptomator.ui.launcher.FxApplicationStarter; +import org.cryptomator.ui.fxapp.FxApplicationScoped; import javax.inject.Inject; -import javax.inject.Singleton; +import javafx.application.Application; import java.nio.file.Path; -@Singleton +@FxApplicationScoped public class HostServiceRevealer implements Volume.Revealer { - private final FxApplicationStarter fxApplicationStarter; + private final Lazy application; @Inject - public HostServiceRevealer(FxApplicationStarter fxApplicationStarter) { - this.fxApplicationStarter = fxApplicationStarter; + public HostServiceRevealer(Lazy application) { + this.application = application; } @Override public void reveal(Path p) throws Volume.VolumeException { - fxApplicationStarter.get().thenAccept(app -> app.getHostServices().showDocument(p.toUri().toString())); + application.get().getHostServices().showDocument(p.toUri().toString()); } } From b2f27c0a3d7784aac312eec4379a2ff924a8f738 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Fri, 22 Jan 2021 09:34:18 +0100 Subject: [PATCH 13/13] removed dead code [ci skip] --- .../main/java/org/cryptomator/common/vaults/WebDavVolume.java | 3 --- 1 file changed, 3 deletions(-) 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 072851272..5864b39e1 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 @@ -10,8 +10,6 @@ import org.cryptomator.frontend.webdav.WebDavServer; import org.cryptomator.frontend.webdav.mount.MountParams; import org.cryptomator.frontend.webdav.mount.Mounter; import org.cryptomator.frontend.webdav.servlet.WebDavServletController; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.inject.Provider; @@ -22,7 +20,6 @@ import java.util.Optional; public class WebDavVolume implements Volume { - private static final Logger LOG = LoggerFactory.getLogger(WebDavVolume.class); private static final String LOCALHOST_ALIAS = "cryptomator-vault"; private final Provider serverProvider;