mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-21 20:21:27 +00:00
Using enum instead of string to choose between FUSE and WebDAV
This commit is contained in:
@@ -12,8 +12,10 @@ import java.util.function.Consumer;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
@@ -30,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 String DEFAULT_NIO_ADAPTER = NioAdapterImpl.WEBDAV.name();
|
||||
public static final NioAdapterImpl DEFAULT_NIO_ADAPTER = NioAdapterImpl.WEBDAV;
|
||||
|
||||
private final ObservableList<VaultSettings> directories = FXCollections.observableArrayList(VaultSettings::observables);
|
||||
private final BooleanProperty checkForUpdates = new SimpleBooleanProperty(DEFAULT_CHECK_FOR_UDPATES);
|
||||
@@ -38,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 StringProperty nioAdapterImpl = new SimpleStringProperty(DEFAULT_NIO_ADAPTER);
|
||||
private final ObjectProperty<NioAdapterImpl> nioAdapterImpl = new SimpleObjectProperty<>(DEFAULT_NIO_ADAPTER);
|
||||
|
||||
private Consumer<Settings> saveCmd;
|
||||
|
||||
@@ -95,7 +97,7 @@ public class Settings {
|
||||
return debugMode;
|
||||
}
|
||||
|
||||
public StringProperty usedNioAdapterImpl() {
|
||||
public ObjectProperty<NioAdapterImpl> usedNioAdapterImpl() {
|
||||
return nioAdapterImpl;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
|
||||
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());
|
||||
out.name("nioAdapterImpl").value(value.usedNioAdapterImpl().get().name());
|
||||
out.endObject();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
|
||||
settings.debugMode().set(in.nextBoolean());
|
||||
break;
|
||||
case "nioAdapterImpl":
|
||||
settings.usedNioAdapterImpl().set(in.nextString());
|
||||
settings.usedNioAdapterImpl().set(parseNioAdapterName(in.nextString()));
|
||||
break;
|
||||
default:
|
||||
LOG.warn("Unsupported vault setting found in JSON: " + name);
|
||||
@@ -84,6 +84,14 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
|
||||
return settings;
|
||||
}
|
||||
|
||||
private NioAdapterImpl parseNioAdapterName(String nioAdapterName) {
|
||||
try {
|
||||
return NioAdapterImpl.valueOf(nioAdapterName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Settings.DEFAULT_NIO_ADAPTER;
|
||||
}
|
||||
}
|
||||
|
||||
private List<VaultSettings> readVaultSettingsArray(JsonReader in) throws IOException {
|
||||
List<VaultSettings> result = new ArrayList<>();
|
||||
in.beginArray();
|
||||
|
||||
@@ -21,20 +21,17 @@ public class SettingsJsonAdapterTest {
|
||||
String json = "{\"directories\": [" + vault1Json + "," + vault2Json + "]," //
|
||||
+ "\"checkForUpdatesEnabled\": true,"//
|
||||
+ "\"port\": 8080,"//
|
||||
+ "\"useIpv6\": true,"//
|
||||
+ "\"numTrayNotifications\": 42,"//
|
||||
+ "\"nioAdapterImpl\": \"webdav\","//
|
||||
+ "\"defaultMountDir\": \"/home/test/crypto\"}";
|
||||
+ "\"nioAdapterImpl\": \"webdav\"}";
|
||||
|
||||
Settings settings = adapter.fromJson(json);
|
||||
|
||||
Assert.assertTrue(settings.checkForUpdates().get());
|
||||
Assert.assertEquals(2, settings.getDirectories().size());
|
||||
Assert.assertEquals(8080, settings.port().get());
|
||||
// Assert.assertTrue(settings.useIpv6().get()); temporarily ignored
|
||||
Assert.assertEquals(42, settings.numTrayNotifications().get());
|
||||
Assert.assertEquals("dav", settings.preferredGvfsScheme().get());
|
||||
Assert.assertEquals("webdav", settings.usedNioAdapterImpl().get());
|
||||
Assert.assertEquals(NioAdapterImpl.WEBDAV, settings.usedNioAdapterImpl().get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import javax.inject.Singleton;
|
||||
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.util.StringConverter;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.ui.l10n.Localization;
|
||||
@@ -35,6 +36,7 @@ import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
|
||||
@Singleton
|
||||
public class SettingsController implements ViewController {
|
||||
@@ -83,7 +85,7 @@ public class SettingsController implements ViewController {
|
||||
private Label volumeLabel;
|
||||
|
||||
@FXML
|
||||
private ChoiceBox<String> volume;
|
||||
private ChoiceBox<NioAdapterImpl> volume;
|
||||
|
||||
@FXML
|
||||
private CheckBox debugModeCheckbox;
|
||||
@@ -101,11 +103,10 @@ public class SettingsController implements ViewController {
|
||||
volume.getItems().addAll(getSupportedAdapters());
|
||||
volume.setValue(settings.usedNioAdapterImpl().get());
|
||||
volume.setVisible(true);
|
||||
volume.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends String> observable, String oldVal, String newVal) -> changeNioView(newVal));
|
||||
|
||||
volume.setConverter(new NioAdapterImplStringConverter());
|
||||
|
||||
//WEBDAV
|
||||
webdavVolume.setVisible(settings.usedNioAdapterImpl().getValue().equals(NioAdapterImpl.WEBDAV.name()));
|
||||
webdavVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(NioAdapterImpl.WEBDAV));
|
||||
webdavVolume.managedProperty().bind(webdavVolume.visibleProperty());
|
||||
prefGvfsScheme.managedProperty().bind(webdavVolume.visibleProperty());
|
||||
prefGvfsSchemeLabel.managedProperty().bind(webdavVolume.visibleProperty());
|
||||
@@ -123,7 +124,7 @@ public class SettingsController implements ViewController {
|
||||
prefGvfsScheme.setVisible(SystemUtils.IS_OS_LINUX);
|
||||
|
||||
//FUSE
|
||||
fuseVolume.setVisible(settings.usedNioAdapterImpl().getValue().equals(NioAdapterImpl.FUSE.name()));
|
||||
fuseVolume.visibleProperty().bind(volume.valueProperty().isEqualTo(NioAdapterImpl.FUSE));
|
||||
fuseVolume.managedProperty().bind(fuseVolume.visibleProperty());
|
||||
|
||||
debugModeCheckbox.setSelected(settings.debugMode().get());
|
||||
@@ -135,13 +136,8 @@ public class SettingsController implements ViewController {
|
||||
}
|
||||
|
||||
//TODO: how to implement this?
|
||||
private String[] getSupportedAdapters() {
|
||||
return new String[]{NioAdapterImpl.FUSE.name(), NioAdapterImpl.WEBDAV.name()};
|
||||
}
|
||||
|
||||
private void changeNioView(String newVal) {
|
||||
fuseVolume.setVisible(newVal.equalsIgnoreCase(NioAdapterImpl.FUSE.name()));
|
||||
webdavVolume.setVisible(newVal.equalsIgnoreCase(NioAdapterImpl.WEBDAV.name()));
|
||||
private NioAdapterImpl[] getSupportedAdapters() {
|
||||
return new NioAdapterImpl[]{NioAdapterImpl.FUSE, NioAdapterImpl.WEBDAV};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,4 +179,17 @@ public class SettingsController implements ViewController {
|
||||
return Boolean.parseBoolean(System.getProperty("cryptomator.updatesManagedExternally", "false"));
|
||||
}
|
||||
|
||||
private static class NioAdapterImplStringConverter extends StringConverter<NioAdapterImpl> {
|
||||
|
||||
@Override
|
||||
public String toString(NioAdapterImpl object) {
|
||||
return object.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NioAdapterImpl fromString(String string) {
|
||||
return NioAdapterImpl.valueOf(string);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class UnlockController implements ViewController {
|
||||
winDriveLetterLabel.setManaged(false);
|
||||
winDriveLetter.setVisible(false);
|
||||
winDriveLetter.setManaged(false);
|
||||
if(settings.usedNioAdapterImpl().isEqualTo(NioAdapterImpl.WEBDAV.name()).get()){
|
||||
if(NioAdapterImpl.WEBDAV.equals(settings.usedNioAdapterImpl().get())){
|
||||
mountPathLabel.setVisible(false);
|
||||
mountPathLabel.setManaged(false);
|
||||
}
|
||||
|
||||
@@ -44,15 +44,14 @@ public class VaultModule {
|
||||
@Provides
|
||||
@PerVault
|
||||
public Volume provideNioAdpater(Settings settings, WebDavVolume webDavVolume, FuseVolume fuseVolume) {
|
||||
NioAdapterImpl impl = NioAdapterImpl.valueOf(settings.usedNioAdapterImpl().get());
|
||||
NioAdapterImpl impl = settings.usedNioAdapterImpl().get();
|
||||
switch (impl) {
|
||||
case WEBDAV:
|
||||
return webDavVolume;
|
||||
case FUSE:
|
||||
return fuseVolume;
|
||||
default:
|
||||
//this should not happen!
|
||||
throw new IllegalStateException("Unsupported NioAdapter: " + settings.usedNioAdapterImpl().get());
|
||||
throw new IllegalStateException("Unsupported NioAdapter: " + impl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user