mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-09-20 06:54:16 +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;
|
||||
}
|
||||
|
||||
|
||||
+10
-2
@@ -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();
|
||||
|
||||
+2
-5
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user