From 874c5506a74712704dd1ba32cfe7970849af1e24 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Sun, 17 Jun 2018 14:19:22 +0200 Subject: [PATCH] Added Dokany to volume type setting. Restart no longer required, when changing preferred volume type. References #207 --- .../ui/controllers/SettingsController.java | 8 ++------ .../java/org/cryptomator/ui/model/DokanyVolume.java | 1 - .../java/org/cryptomator/ui/model/FuseVolume.java | 9 +++------ .../main/java/org/cryptomator/ui/model/Vault.java | 7 +++++-- .../java/org/cryptomator/ui/model/VaultModule.java | 13 +++++++++---- .../java/org/cryptomator/ui/model/WebDavVolume.java | 1 - main/ui/src/main/resources/localization/en.txt | 3 ++- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java index 8b96f80a6..0cc884943 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java @@ -77,9 +77,6 @@ public class SettingsController implements ViewController { @FXML private ChoiceBox prefGvfsScheme; - @FXML - private Label volumeLabel; - @FXML private ChoiceBox volume; @@ -98,7 +95,6 @@ public class SettingsController implements ViewController { //NIOADAPTER volume.getItems().addAll(getSupportedAdapters()); volume.setValue(settings.preferredVolumeImpl().get()); - volume.setVisible(true); volume.setConverter(new NioAdapterImplStringConverter()); //WEBDAV @@ -131,9 +127,9 @@ public class SettingsController implements ViewController { settings.debugMode().bind(debugModeCheckbox.selectedProperty()); } - //TODO: how to implement this? private VolumeImpl[] getSupportedAdapters() { - return new VolumeImpl[]{VolumeImpl.FUSE, VolumeImpl.WEBDAV}; + // TODO: filter depending on supported drivers + return VolumeImpl.values(); } @Override diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/DokanyVolume.java b/main/ui/src/main/java/org/cryptomator/ui/model/DokanyVolume.java index 38b5166de..9f7041107 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/DokanyVolume.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/DokanyVolume.java @@ -8,7 +8,6 @@ import org.cryptomator.cryptofs.CryptoFileSystem; import org.cryptomator.frontend.dokany.Mount; import org.cryptomator.frontend.dokany.MountFactory; -@VaultModule.PerVault public class DokanyVolume implements Volume { private static final String FS_TYPE_NAME = "Cryptomator File System"; diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java b/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java index 510fe211f..0249a198d 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java @@ -20,7 +20,6 @@ import org.cryptomator.frontend.fuse.mount.Mount; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@VaultModule.PerVault public class FuseVolume implements Volume { private static final Logger LOG = LoggerFactory.getLogger(FuseVolume.class); @@ -34,7 +33,6 @@ public class FuseVolume implements Volume { private final VaultSettings vaultSettings; private Mount fuseMnt; - private CryptoFileSystem cfs; private Path mountPath; private boolean extraDirCreated; @@ -46,7 +44,6 @@ public class FuseVolume implements Volume { @Override public void mount(CryptoFileSystem fs) throws IOException, FuseNotSupportedException, VolumeException { - this.cfs = fs; String mountPath; if (vaultSettings.usesIndividualMountPath().get()) { //specific path given @@ -57,7 +54,7 @@ public class FuseVolume implements Volume { extraDirCreated = true; } this.mountPath = Paths.get(mountPath).toAbsolutePath(); - mount(); + mount(fs.getPath("/")); } private String createDirIfNotExist(String prefix, String dirName) throws IOException { @@ -78,13 +75,13 @@ public class FuseVolume implements Volume { } } - private void mount() throws VolumeException { + private void mount(Path root) throws VolumeException { try { EnvironmentVariables envVars = EnvironmentVariables.create() .withMountName(vaultSettings.mountName().getValue()) .withMountPath(mountPath) .build(); - this.fuseMnt = FuseMountFactory.getMounter().mount(cfs.getPath("/"), envVars); + this.fuseMnt = FuseMountFactory.getMounter().mount(root, envVars); } catch (CommandFailedException e) { throw new VolumeException("Unable to mount Filesystem", e); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java index 6972f5a13..ff7b842b6 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java @@ -19,6 +19,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import javax.inject.Inject; +import javax.inject.Provider; import javafx.application.Platform; import javafx.beans.Observable; @@ -52,6 +53,7 @@ public class Vault { private final Settings settings; private final VaultSettings vaultSettings; + private final Provider volumeProvider; private final AtomicReference cryptoFileSystem = new AtomicReference<>(); private final ObjectProperty state = new SimpleObjectProperty(State.LOCKED); @@ -62,10 +64,10 @@ public class Vault { } @Inject - Vault(Settings settings, VaultSettings vaultSettings, Volume volume) { + Vault(Settings settings, VaultSettings vaultSettings, Provider volumeProvider) { this.settings = settings; this.vaultSettings = vaultSettings; - this.volume = volume; + this.volumeProvider = volumeProvider; } // ****************************************************************************** @@ -102,6 +104,7 @@ public class Vault { state.set(State.PROCESSING); }); CryptoFileSystem fs = getCryptoFileSystem(passphrase); + volume = volumeProvider.get(); volume.mount(fs); Platform.runLater(() -> { state.set(State.UNLOCKED); diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/VaultModule.java b/main/ui/src/main/java/org/cryptomator/ui/model/VaultModule.java index 18b7dec05..141ba8975 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/VaultModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/VaultModule.java @@ -18,10 +18,13 @@ import org.cryptomator.common.settings.VaultSettings; import dagger.Module; import dagger.Provides; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Module public class VaultModule { + private static final Logger LOG = LoggerFactory.getLogger(VaultModule.class); private final VaultSettings vaultSettings; public VaultModule(VaultSettings vaultSettings) { @@ -42,14 +45,16 @@ public class VaultModule { } @Provides - @PerVault public Volume provideVolume(Settings settings, WebDavVolume webDavVolume, FuseVolume fuseVolume, DokanyVolume dokanyVolume) { - VolumeImpl impl = settings.preferredVolumeImpl().get(); - if (VolumeImpl.DOKANY == impl && dokanyVolume.isSupported()) { + VolumeImpl preferredImpl = settings.preferredVolumeImpl().get(); + if (VolumeImpl.DOKANY == preferredImpl && dokanyVolume.isSupported()) { return dokanyVolume; - } else if (VolumeImpl.FUSE == impl && fuseVolume.isSupported()) { + } else if (VolumeImpl.FUSE == preferredImpl && fuseVolume.isSupported()) { return fuseVolume; } else { + if (VolumeImpl.WEBDAV != preferredImpl) { + LOG.warn("Using WebDAV, because {} is not supported.", preferredImpl.getDisplayName()); + } assert webDavVolume.isSupported(); return webDavVolume; } diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/WebDavVolume.java b/main/ui/src/main/java/org/cryptomator/ui/model/WebDavVolume.java index 115642ada..6d1138c90 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/WebDavVolume.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/WebDavVolume.java @@ -15,7 +15,6 @@ import javax.inject.Provider; import java.net.InetAddress; import java.net.UnknownHostException; -@VaultModule.PerVault public class WebDavVolume implements Volume { private static final String LOCALHOST_ALIAS = "cryptomator-vault"; diff --git a/main/ui/src/main/resources/localization/en.txt b/main/ui/src/main/resources/localization/en.txt index 0926d2c49..42d63b7ce 100644 --- a/main/ui/src/main/resources/localization/en.txt +++ b/main/ui/src/main/resources/localization/en.txt @@ -122,9 +122,10 @@ settings.webdav.port.apply=Apply settings.webdav.prefGvfsScheme.label=WebDAV Scheme settings.debugMode.label=Debug Mode * settings.requiresRestartLabel=* Cryptomator needs to restart -settings.volume.label= Mount-Methode * +settings.volume.label=Preferred Volume Type settings.volume.webdav=WebDAV settings.volume.fuse=FUSE +settings.volume.dokany=Dokany # tray icon tray.menu.open=Open