mirror of
https://github.com/cryptomator/cryptomator.git
synced 2024-11-27 05:50:26 +00:00
volume settings → change tcp port
This commit is contained in:
parent
3e5a7fadd0
commit
1b4117de38
@ -36,9 +36,7 @@ public class Settings {
|
||||
public static final boolean DEFAULT_USE_KEYCHAIN = true;
|
||||
public static final int DEFAULT_PORT = 42427;
|
||||
public static final int DEFAULT_NUM_TRAY_NOTIFICATIONS = 3;
|
||||
public static final WebDavUrlScheme DEFAULT_GVFS_SCHEME = WebDavUrlScheme.DAV;
|
||||
public static final boolean DEFAULT_DEBUG_MODE = false;
|
||||
public static final VolumeImpl DEFAULT_PREFERRED_VOLUME_IMPL = VolumeImpl.FUSE;
|
||||
public static final UiTheme DEFAULT_THEME = UiTheme.LIGHT;
|
||||
@Deprecated // to be changed to "whatever is available" eventually
|
||||
public static final String DEFAULT_KEYCHAIN_PROVIDER = SystemUtils.IS_OS_WINDOWS ? "org.cryptomator.windows.keychain.WindowsProtectedKeychainAccess" : SystemUtils.IS_OS_MAC ? "org.cryptomator.macos.keychain.MacSystemKeychainAccess" : "org.cryptomator.linux.keychain.SecretServiceKeychainAccess";
|
||||
@ -57,9 +55,7 @@ public class Settings {
|
||||
private final BooleanProperty useKeychain = new SimpleBooleanProperty(DEFAULT_USE_KEYCHAIN);
|
||||
private final IntegerProperty port = new SimpleIntegerProperty(DEFAULT_PORT);
|
||||
private final IntegerProperty numTrayNotifications = new SimpleIntegerProperty(DEFAULT_NUM_TRAY_NOTIFICATIONS);
|
||||
private final ObjectProperty<WebDavUrlScheme> preferredGvfsScheme = new SimpleObjectProperty<>(DEFAULT_GVFS_SCHEME);
|
||||
private final BooleanProperty debugMode = new SimpleBooleanProperty(DEFAULT_DEBUG_MODE);
|
||||
private final ObjectProperty<VolumeImpl> preferredVolumeImpl = new SimpleObjectProperty<>(DEFAULT_PREFERRED_VOLUME_IMPL);
|
||||
private final ObjectProperty<UiTheme> theme = new SimpleObjectProperty<>(DEFAULT_THEME);
|
||||
private final ObjectProperty<String> keychainProvider = new SimpleObjectProperty<>(DEFAULT_KEYCHAIN_PROVIDER);
|
||||
private final ObjectProperty<NodeOrientation> userInterfaceOrientation = new SimpleObjectProperty<>(DEFAULT_USER_INTERFACE_ORIENTATION);
|
||||
@ -93,9 +89,7 @@ public class Settings {
|
||||
useKeychain.addListener(this::somethingChanged);
|
||||
port.addListener(this::somethingChanged);
|
||||
numTrayNotifications.addListener(this::somethingChanged);
|
||||
preferredGvfsScheme.addListener(this::somethingChanged);
|
||||
debugMode.addListener(this::somethingChanged);
|
||||
preferredVolumeImpl.addListener(this::somethingChanged);
|
||||
theme.addListener(this::somethingChanged);
|
||||
keychainProvider.addListener(this::somethingChanged);
|
||||
userInterfaceOrientation.addListener(this::somethingChanged);
|
||||
@ -157,18 +151,10 @@ public class Settings {
|
||||
return numTrayNotifications;
|
||||
}
|
||||
|
||||
public ObjectProperty<WebDavUrlScheme> preferredGvfsScheme() {
|
||||
return preferredGvfsScheme;
|
||||
}
|
||||
|
||||
public BooleanProperty debugMode() {
|
||||
return debugMode;
|
||||
}
|
||||
|
||||
public ObjectProperty<VolumeImpl> preferredVolumeImpl() {
|
||||
return preferredVolumeImpl;
|
||||
}
|
||||
|
||||
public StringProperty mountService() {
|
||||
return mountService;
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
|
||||
out.name("autoCloseVaults").value(value.autoCloseVaults().get());
|
||||
out.name("port").value(value.port().get());
|
||||
out.name("numTrayNotifications").value(value.numTrayNotifications().get());
|
||||
out.name("preferredGvfsScheme").value(value.preferredGvfsScheme().get().name());
|
||||
out.name("debugMode").value(value.debugMode().get());
|
||||
out.name("theme").value(value.theme().get().name());
|
||||
out.name("uiOrientation").value(value.userInterfaceOrientation().get().name());
|
||||
@ -86,7 +85,6 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
|
||||
case "autoCloseVaults" -> settings.autoCloseVaults().set(in.nextBoolean());
|
||||
case "port" -> settings.port().set(in.nextInt());
|
||||
case "numTrayNotifications" -> settings.numTrayNotifications().set(in.nextInt());
|
||||
case "preferredGvfsScheme" -> settings.preferredGvfsScheme().set(parseWebDavUrlSchemePrefix(in.nextString()));
|
||||
case "debugMode" -> settings.debugMode().set(in.nextBoolean());
|
||||
case "theme" -> settings.theme().set(parseUiTheme(in.nextString()));
|
||||
case "uiOrientation" -> settings.userInterfaceOrientation().set(parseUiOrientation(in.nextString()));
|
||||
@ -119,15 +117,6 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
|
||||
return settings;
|
||||
}
|
||||
|
||||
private WebDavUrlScheme parseWebDavUrlSchemePrefix(String webDavUrlSchemeName) {
|
||||
try {
|
||||
return WebDavUrlScheme.valueOf(webDavUrlSchemeName.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.warn("Invalid WebDAV url scheme {}. Defaulting to {}.", webDavUrlSchemeName, Settings.DEFAULT_GVFS_SCHEME);
|
||||
return Settings.DEFAULT_GVFS_SCHEME;
|
||||
}
|
||||
}
|
||||
|
||||
private UiTheme parseUiTheme(String uiThemeName) {
|
||||
try {
|
||||
return UiTheme.valueOf(uiThemeName.toUpperCase());
|
||||
|
@ -1,22 +0,0 @@
|
||||
package org.cryptomator.common.settings;
|
||||
|
||||
public enum WebDavUrlScheme {
|
||||
DAV("dav", "dav:// (Gnome, Nautilus, ...)"),
|
||||
WEBDAV("webdav", "webdav:// (KDE, Dolphin, ...)");
|
||||
|
||||
private final String prefix;
|
||||
private final String displayName;
|
||||
|
||||
WebDavUrlScheme(String prefix, String displayName) {
|
||||
this.prefix = prefix;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
}
|
@ -1,16 +1,13 @@
|
||||
package org.cryptomator.ui.preferences;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.settings.VolumeImpl;
|
||||
import org.cryptomator.common.settings.WebDavUrlScheme;
|
||||
import org.cryptomator.integrations.mount.MountCapability;
|
||||
import org.cryptomator.integrations.mount.MountService;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.BooleanBinding;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.binding.BooleanExpression;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
@ -25,22 +22,19 @@ import java.util.List;
|
||||
public class VolumePreferencesController implements FxController {
|
||||
|
||||
private final Settings settings;
|
||||
private final BooleanBinding showWebDavSettings;
|
||||
private final ObservableValue<MountService> selectedMountService;
|
||||
private final BooleanBinding showWebDavScheme;
|
||||
private final BooleanExpression loopbackPortSupported;
|
||||
private final List<MountService> mountProviders;
|
||||
public ChoiceBox<MountService> volumeTypeChoiceBox;
|
||||
public TextField webDavPortField;
|
||||
public Button changeWebDavPortButton;
|
||||
public ChoiceBox<WebDavUrlScheme> webDavUrlSchemeChoiceBox;
|
||||
public TextField loopbackPortField;
|
||||
public Button loopbackPortApplyButton;
|
||||
|
||||
@Inject
|
||||
VolumePreferencesController(Settings settings, List<MountService> mountProviders, ObservableValue<MountService> selectedMountService) {
|
||||
this.settings = settings;
|
||||
this.mountProviders = mountProviders;
|
||||
this.showWebDavSettings = Bindings.equal(settings.preferredVolumeImpl(), VolumeImpl.WEBDAV);
|
||||
this.selectedMountService = selectedMountService;
|
||||
this.showWebDavScheme = showWebDavSettings.and(new SimpleBooleanProperty(SystemUtils.IS_OS_LINUX)); //TODO: remove SystemUtils
|
||||
this.loopbackPortSupported = BooleanExpression.booleanExpression(selectedMountService.map(s -> s.hasCapability(MountCapability.LOOPBACK_PORT)));
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
@ -49,18 +43,15 @@ public class VolumePreferencesController implements FxController {
|
||||
volumeTypeChoiceBox.getSelectionModel().select(selectedMountService.getValue());
|
||||
volumeTypeChoiceBox.valueProperty().addListener((observableValue, oldProvide, newProvider) -> settings.mountService().set(newProvider.getClass().getName()));
|
||||
|
||||
webDavPortField.setText(String.valueOf(settings.port().get()));
|
||||
changeWebDavPortButton.visibleProperty().bind(settings.port().asString().isNotEqualTo(webDavPortField.textProperty()));
|
||||
changeWebDavPortButton.disableProperty().bind(Bindings.createBooleanBinding(this::validateWebDavPort, webDavPortField.textProperty()).not());
|
||||
loopbackPortField.setText(String.valueOf(settings.port().get()));
|
||||
loopbackPortApplyButton.visibleProperty().bind(settings.port().asString().isNotEqualTo(loopbackPortField.textProperty()));
|
||||
loopbackPortApplyButton.disableProperty().bind(Bindings.createBooleanBinding(this::validateLoopbackPort, loopbackPortField.textProperty()).not());
|
||||
|
||||
webDavUrlSchemeChoiceBox.getItems().addAll(WebDavUrlScheme.values());
|
||||
webDavUrlSchemeChoiceBox.valueProperty().bindBidirectional(settings.preferredGvfsScheme());
|
||||
webDavUrlSchemeChoiceBox.setConverter(new WebDavUrlSchemeConverter());
|
||||
}
|
||||
|
||||
private boolean validateWebDavPort() {
|
||||
private boolean validateLoopbackPort() {
|
||||
try {
|
||||
int port = Integer.parseInt(webDavPortField.getText());
|
||||
int port = Integer.parseInt(loopbackPortField.getText());
|
||||
return port == 0 // choose port automatically
|
||||
|| port >= Settings.MIN_PORT && port <= Settings.MAX_PORT; // port within range
|
||||
} catch (NumberFormatException e) {
|
||||
@ -68,42 +59,23 @@ public class VolumePreferencesController implements FxController {
|
||||
}
|
||||
}
|
||||
|
||||
public void doChangeWebDavPort() {
|
||||
settings.port().set(Integer.parseInt(webDavPortField.getText()));
|
||||
public void doChangeLoopbackPort() {
|
||||
if (validateLoopbackPort()) {
|
||||
settings.port().set(Integer.parseInt(loopbackPortField.getText()));
|
||||
}
|
||||
}
|
||||
|
||||
/* Property Getters */
|
||||
|
||||
public BooleanBinding showWebDavSettingsProperty() {
|
||||
return showWebDavSettings;
|
||||
public BooleanExpression loopbackPortSupportedProperty() {
|
||||
return loopbackPortSupported;
|
||||
}
|
||||
|
||||
public Boolean getShowWebDavSettings() {
|
||||
return showWebDavSettings.get();
|
||||
public boolean isLoopbackPortSupported() {
|
||||
return loopbackPortSupported.get();
|
||||
}
|
||||
|
||||
public BooleanBinding showWebDavSchemeProperty() {
|
||||
return showWebDavScheme;
|
||||
}
|
||||
|
||||
public Boolean getShowWebDavScheme() {
|
||||
return showWebDavScheme.get();
|
||||
}
|
||||
|
||||
/* Helper classes */
|
||||
|
||||
private static class WebDavUrlSchemeConverter extends StringConverter<WebDavUrlScheme> {
|
||||
|
||||
@Override
|
||||
public String toString(WebDavUrlScheme scheme) {
|
||||
return scheme.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebDavUrlScheme fromString(String string) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
/* Helpers */
|
||||
|
||||
private static class MountServiceConverter extends StringConverter<MountService> {
|
||||
|
||||
@ -118,4 +90,5 @@ public class VolumePreferencesController implements FxController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -20,15 +20,10 @@
|
||||
<ChoiceBox fx:id="volumeTypeChoiceBox"/>
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="12" alignment="CENTER_LEFT" visible="${controller.showWebDavSettings}">
|
||||
<Label text="%preferences.volume.webdav.port"/>
|
||||
<NumericTextField fx:id="webDavPortField"/>
|
||||
<Button text="%generic.button.apply" fx:id="changeWebDavPortButton" onAction="#doChangeWebDavPort"/>
|
||||
</HBox>
|
||||
|
||||
<HBox spacing="12" alignment="CENTER_LEFT" visible="${controller.showWebDavScheme}">
|
||||
<Label text="%preferences.volume.webdav.scheme"/>
|
||||
<ChoiceBox fx:id="webDavUrlSchemeChoiceBox" maxWidth="Infinity"/>
|
||||
<HBox spacing="12" alignment="CENTER_LEFT" visible="${controller.loopbackPortSupported}">
|
||||
<Label text="%preferences.volume.tcp.port"/>
|
||||
<NumericTextField fx:id="loopbackPortField"/>
|
||||
<Button text="%generic.button.apply" fx:id="loopbackPortApplyButton" onAction="#doChangeLoopbackPort"/>
|
||||
</HBox>
|
||||
</children>
|
||||
</VBox>
|
||||
|
@ -252,8 +252,7 @@ preferences.interface.showTrayIcon=Show tray icon (requires restart)
|
||||
## Volume
|
||||
preferences.volume=Virtual Drive
|
||||
preferences.volume.type=Volume Type
|
||||
preferences.volume.webdav.port=WebDAV Port
|
||||
preferences.volume.webdav.scheme=WebDAV Scheme
|
||||
preferences.volume.tcp.port=TCP Port
|
||||
## Updates
|
||||
preferences.updates=Updates
|
||||
preferences.updates.currentVersion=Current Version: %s
|
||||
|
@ -32,7 +32,6 @@ public class SettingsJsonAdapterTest {
|
||||
"port": 8080,
|
||||
"language": "de-DE",
|
||||
"numTrayNotifications": 42,
|
||||
"preferredVolumeImpl": "FUSE"
|
||||
}
|
||||
""";
|
||||
|
||||
@ -44,8 +43,6 @@ public class SettingsJsonAdapterTest {
|
||||
Assertions.assertEquals(true, settings.autoCloseVaults().get());
|
||||
Assertions.assertEquals("de-DE", settings.languageProperty().get());
|
||||
Assertions.assertEquals(42, settings.numTrayNotifications().get());
|
||||
Assertions.assertEquals(WebDavUrlScheme.DAV, settings.preferredGvfsScheme().get());
|
||||
Assertions.assertEquals(VolumeImpl.FUSE, settings.preferredVolumeImpl().get());
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
|
@ -24,7 +24,7 @@ public class SettingsTest {
|
||||
Mockito.verify(changeListener, Mockito.times(0)).accept(settings);
|
||||
|
||||
// first change (to property):
|
||||
settings.preferredGvfsScheme().set(WebDavUrlScheme.WEBDAV);
|
||||
settings.port().set(42428);
|
||||
Mockito.verify(changeListener, Mockito.times(1)).accept(settings);
|
||||
|
||||
// second change (to list):
|
||||
|
Loading…
Reference in New Issue
Block a user