diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/NioAdapterImpl.java b/main/commons/src/main/java/org/cryptomator/common/settings/NioAdapterImpl.java deleted file mode 100644 index b34ad340d..000000000 --- a/main/commons/src/main/java/org/cryptomator/common/settings/NioAdapterImpl.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.cryptomator.common.settings; - -public enum NioAdapterImpl { - - WEBDAV, - FUSE - -} diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java b/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java index a48db80aa..f3b8a169f 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java @@ -32,7 +32,7 @@ public class Settings { public static final int DEFAULT_NUM_TRAY_NOTIFICATIONS = 3; public static final String DEFAULT_GVFS_SCHEME = "dav"; public static final boolean DEFAULT_DEBUG_MODE = false; - public static final NioAdapterImpl DEFAULT_NIO_ADAPTER = NioAdapterImpl.WEBDAV; + public static final VolumeImpl DEFAULT_VOLUME_IMPL = VolumeImpl.WEBDAV; private final ObservableList directories = FXCollections.observableArrayList(VaultSettings::observables); private final BooleanProperty checkForUpdates = new SimpleBooleanProperty(DEFAULT_CHECK_FOR_UDPATES); @@ -40,7 +40,7 @@ public class Settings { private final IntegerProperty numTrayNotifications = new SimpleIntegerProperty(DEFAULT_NUM_TRAY_NOTIFICATIONS); private final StringProperty preferredGvfsScheme = new SimpleStringProperty(DEFAULT_GVFS_SCHEME); private final BooleanProperty debugMode = new SimpleBooleanProperty(DEFAULT_DEBUG_MODE); - private final ObjectProperty nioAdapterImpl = new SimpleObjectProperty<>(DEFAULT_NIO_ADAPTER); + private final ObjectProperty volumeImpl = new SimpleObjectProperty<>(DEFAULT_VOLUME_IMPL); private Consumer saveCmd; @@ -54,7 +54,7 @@ public class Settings { numTrayNotifications.addListener(this::somethingChanged); preferredGvfsScheme.addListener(this::somethingChanged); debugMode.addListener(this::somethingChanged); - nioAdapterImpl.addListener(this::somethingChanged); + volumeImpl.addListener(this::somethingChanged); } void setSaveCmd(Consumer saveCmd) { @@ -97,8 +97,8 @@ public class Settings { return debugMode; } - public ObjectProperty usedNioAdapterImpl() { - return nioAdapterImpl; + public ObjectProperty volumeImpl() { + return volumeImpl; } } diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java b/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java index 7a911c1fb..00dc439f7 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java @@ -33,7 +33,7 @@ public class SettingsJsonAdapter extends TypeAdapter { out.name("numTrayNotifications").value(value.numTrayNotifications().get()); out.name("preferredGvfsScheme").value(value.preferredGvfsScheme().get()); out.name("debugMode").value(value.debugMode().get()); - out.name("nioAdapterImpl").value(value.usedNioAdapterImpl().get().name()); + out.name("volumeImpl").value(value.volumeImpl().get().name()); out.endObject(); } @@ -71,8 +71,8 @@ public class SettingsJsonAdapter extends TypeAdapter { case "debugMode": settings.debugMode().set(in.nextBoolean()); break; - case "nioAdapterImpl": - settings.usedNioAdapterImpl().set(parseNioAdapterName(in.nextString())); + case "volumeImpl": + settings.volumeImpl().set(parseNioAdapterName(in.nextString())); break; default: LOG.warn("Unsupported vault setting found in JSON: " + name); @@ -84,11 +84,11 @@ public class SettingsJsonAdapter extends TypeAdapter { return settings; } - private NioAdapterImpl parseNioAdapterName(String nioAdapterName) { + private VolumeImpl parseNioAdapterName(String nioAdapterName) { try { - return NioAdapterImpl.valueOf(nioAdapterName); + return VolumeImpl.valueOf(nioAdapterName); } catch (IllegalArgumentException e) { - return Settings.DEFAULT_NIO_ADAPTER; + return Settings.DEFAULT_VOLUME_IMPL; } } diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/VolumeImpl.java b/main/commons/src/main/java/org/cryptomator/common/settings/VolumeImpl.java new file mode 100644 index 000000000..0862c499b --- /dev/null +++ b/main/commons/src/main/java/org/cryptomator/common/settings/VolumeImpl.java @@ -0,0 +1,33 @@ +package org.cryptomator.common.settings; + +import java.util.Arrays; + +public enum VolumeImpl { + WEBDAV("WebDAV"), + FUSE("FUSE"); + + private String displayName; + + VolumeImpl(String displayName) { + this.displayName = displayName; + } + + public String getDisplayName() { + return displayName; + } + + /** + * Finds a VolumeImpl by display name. + * + * @param displayName Display name of the VolumeImpl + * @return VolumeImpl with the given displayName. + * @throws IllegalArgumentException if not volumeImpl with the given displayName was found. + */ + public static VolumeImpl forDisplayName(String displayName) throws IllegalArgumentException { + return Arrays.stream(values()) // + .filter(impl -> impl.displayName.equals(displayName)) // + .findAny() // + .orElseThrow(IllegalArgumentException::new); + } + +} diff --git a/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java b/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java index 237df648b..511197d29 100644 --- a/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java +++ b/main/commons/src/test/java/org/cryptomator/common/settings/SettingsJsonAdapterTest.java @@ -22,7 +22,7 @@ public class SettingsJsonAdapterTest { + "\"checkForUpdatesEnabled\": true,"// + "\"port\": 8080,"// + "\"numTrayNotifications\": 42,"// - + "\"nioAdapterImpl\": \"webdav\"}"; + + "\"volumeImpl\": \"FUSE\"}"; Settings settings = adapter.fromJson(json); @@ -31,7 +31,7 @@ public class SettingsJsonAdapterTest { Assert.assertEquals(8080, settings.port().get()); Assert.assertEquals(42, settings.numTrayNotifications().get()); Assert.assertEquals("dav", settings.preferredGvfsScheme().get()); - Assert.assertEquals(NioAdapterImpl.WEBDAV, settings.usedNioAdapterImpl().get()); + Assert.assertEquals(VolumeImpl.FUSE, settings.volumeImpl().get()); } } 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 97d838ed6..f4b997314 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 @@ -30,7 +30,7 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.VBox; import javafx.util.StringConverter; import org.apache.commons.lang3.SystemUtils; -import org.cryptomator.common.settings.NioAdapterImpl; +import org.cryptomator.common.settings.VolumeImpl; import org.cryptomator.common.settings.Settings; import org.cryptomator.ui.l10n.Localization; @@ -81,7 +81,7 @@ public class SettingsController implements ViewController { private Label volumeLabel; @FXML - private ChoiceBox volume; + private ChoiceBox volume; @FXML private CheckBox debugModeCheckbox; @@ -97,12 +97,12 @@ public class SettingsController implements ViewController { //NIOADAPTER volume.getItems().addAll(getSupportedAdapters()); - volume.setValue(settings.usedNioAdapterImpl().get()); + volume.setValue(settings.volumeImpl().get()); volume.setVisible(true); volume.setConverter(new NioAdapterImplStringConverter()); //WEBDAV - webdavVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(NioAdapterImpl.WEBDAV)); + webdavVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(VolumeImpl.WEBDAV)); webdavVolume.managedProperty().bind(webdavVolume.visibleProperty()); prefGvfsScheme.managedProperty().bind(webdavVolume.visibleProperty()); prefGvfsSchemeLabel.managedProperty().bind(webdavVolume.visibleProperty()); @@ -120,20 +120,20 @@ public class SettingsController implements ViewController { prefGvfsScheme.setVisible(SystemUtils.IS_OS_LINUX); //FUSE - fuseVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(NioAdapterImpl.FUSE)); + fuseVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(VolumeImpl.FUSE)); fuseVolume.managedProperty().bind(fuseVolume.visibleProperty()); debugModeCheckbox.setSelected(settings.debugMode().get()); settings.checkForUpdates().bind(checkForUpdatesCheckbox.selectedProperty()); settings.preferredGvfsScheme().bind(prefGvfsScheme.valueProperty()); - settings.usedNioAdapterImpl().bind(volume.valueProperty()); + settings.volumeImpl().bind(volume.valueProperty()); settings.debugMode().bind(debugModeCheckbox.selectedProperty()); } //TODO: how to implement this? - private NioAdapterImpl[] getSupportedAdapters() { - return new NioAdapterImpl[]{NioAdapterImpl.FUSE, NioAdapterImpl.WEBDAV}; + private VolumeImpl[] getSupportedAdapters() { + return new VolumeImpl[]{VolumeImpl.FUSE, VolumeImpl.WEBDAV}; } @Override @@ -175,16 +175,16 @@ public class SettingsController implements ViewController { return Boolean.parseBoolean(System.getProperty("cryptomator.updatesManagedExternally", "false")); } - private static class NioAdapterImplStringConverter extends StringConverter { + private static class NioAdapterImplStringConverter extends StringConverter { @Override - public String toString(NioAdapterImpl object) { - return object.name(); + public String toString(VolumeImpl object) { + return object.getDisplayName(); } @Override - public NioAdapterImpl fromString(String string) { - return NioAdapterImpl.valueOf(string); + public VolumeImpl fromString(String string) { + return VolumeImpl.forDisplayName(string); } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java index e79522b22..59017d320 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java @@ -21,7 +21,7 @@ import javafx.beans.binding.Bindings; import javafx.scene.layout.HBox; import org.apache.commons.lang3.CharUtils; import org.apache.commons.lang3.SystemUtils; -import org.cryptomator.common.settings.NioAdapterImpl; +import org.cryptomator.common.settings.VolumeImpl; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.VaultSettings; import org.cryptomator.cryptolib.api.InvalidPassphraseException; @@ -175,7 +175,7 @@ public class UnlockController implements ViewController { winDriveLetterLabel.setManaged(false); winDriveLetter.setVisible(false); winDriveLetter.setManaged(false); - if(NioAdapterImpl.WEBDAV.equals(settings.usedNioAdapterImpl().get())){ + if(VolumeImpl.WEBDAV.equals(settings.volumeImpl().get())){ mountPathLabel.setVisible(false); mountPathLabel.setManaged(false); } 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 a8bf66178..0012b63e5 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 @@ -12,7 +12,7 @@ import java.util.Objects; import javax.inject.Scope; -import org.cryptomator.common.settings.NioAdapterImpl; +import org.cryptomator.common.settings.VolumeImpl; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.VaultSettings; @@ -44,7 +44,7 @@ public class VaultModule { @Provides @PerVault public Volume provideNioAdpater(Settings settings, WebDavVolume webDavVolume, FuseVolume fuseVolume) { - NioAdapterImpl impl = settings.usedNioAdapterImpl().get(); + VolumeImpl impl = settings.volumeImpl().get(); switch (impl) { case WEBDAV: return webDavVolume;