Browse Source

closes #1471

hand the javafx hostservice showDocument() method from ui package to the underlying nio-adapter-libraries through
Armin Schrenk 4 years ago
parent
commit
1134c1b2ff

+ 8 - 4
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();

+ 4 - 4
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);
 		}

+ 2 - 2
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);
 	}
 
 	// ******************************************************************************

+ 14 - 1
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{
+
+	}
+
 }

+ 4 - 6
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<WebDavServer> 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<Path> getMountPoint() {
-		return Optional.ofNullable(mountPoint); //TODO
+		return mount.getMountPoint();
 	}
 
 	@Override

+ 3 - 3
main/pom.xml

@@ -29,9 +29,9 @@
 		<cryptomator.integrations.win.version>0.2.1</cryptomator.integrations.win.version>
 		<cryptomator.integrations.mac.version>0.1.0-beta3</cryptomator.integrations.mac.version>
 		<cryptomator.integrations.linux.version>0.1.0-beta2</cryptomator.integrations.linux.version>
-		<cryptomator.fuse.version>1.2.6</cryptomator.fuse.version>
-		<cryptomator.dokany.version>1.2.1</cryptomator.dokany.version>
-		<cryptomator.webdav.version>1.0.14</cryptomator.webdav.version>
+		<cryptomator.fuse.version>1.3.0-SNAPSHOT</cryptomator.fuse.version>
+		<cryptomator.dokany.version>1.3.0-SNAPSHOT</cryptomator.dokany.version>
+		<cryptomator.webdav.version>1.1.0-SNAPSHOT</cryptomator.webdav.version>
 
 		<!-- 3rd party dependencies -->
 		<javafx.version>15</javafx.version>

+ 14 - 3
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<Volume.Revealer> 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<Vault> createRevealTask(Vault vault) {
-		Task<Vault> task = new RevealVaultTask(vault);
+		Task<Vault> 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<Vault> {
 
 		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;
 		}
 	}

+ 2 - 0
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() {