diff --git a/src/main/java/org/cryptomator/common/settings/Settings.java b/src/main/java/org/cryptomator/common/settings/Settings.java index 13e3d32ec..4e0e0df97 100644 --- a/src/main/java/org/cryptomator/common/settings/Settings.java +++ b/src/main/java/org/cryptomator/common/settings/Settings.java @@ -36,6 +36,7 @@ public class Settings { static final boolean DEFAULT_START_HIDDEN = false; static final boolean DEFAULT_AUTO_CLOSE_VAULTS = false; static final boolean DEFAULT_USE_KEYCHAIN = true; + static final int DEFAULT_PORT = 42427; static final int DEFAULT_NUM_TRAY_NOTIFICATIONS = 3; static final boolean DEFAULT_DEBUG_MODE = false; static final UiTheme DEFAULT_THEME = UiTheme.LIGHT; @@ -51,6 +52,7 @@ public class Settings { public final BooleanProperty startHidden; public final BooleanProperty autoCloseVaults; public final BooleanProperty useKeychain; + public final IntegerProperty port; public final IntegerProperty numTrayNotifications; public final BooleanProperty debugMode; public final ObjectProperty theme; @@ -87,6 +89,7 @@ public class Settings { this.startHidden = new SimpleBooleanProperty(this, "startHidden", json.startHidden); this.autoCloseVaults = new SimpleBooleanProperty(this, "autoCloseVaults", json.autoCloseVaults); this.useKeychain = new SimpleBooleanProperty(this, "useKeychain", json.useKeychain); + this.port = new SimpleIntegerProperty(this, "webDavPort", json.port); this.numTrayNotifications = new SimpleIntegerProperty(this, "numTrayNotifications", json.numTrayNotifications); this.debugMode = new SimpleBooleanProperty(this, "debugMode", json.debugMode); this.theme = new SimpleObjectProperty<>(this, "theme", json.theme); @@ -106,7 +109,6 @@ public class Settings { this.directories.addAll(json.directories.stream().map(VaultSettings::new).toList()); migrateLegacySettings(json); - migratePortToVaultSettings(json); directories.addListener(this::somethingChanged); askedForUpdateCheck.addListener(this::somethingChanged); @@ -114,6 +116,7 @@ public class Settings { startHidden.addListener(this::somethingChanged); autoCloseVaults.addListener(this::somethingChanged); useKeychain.addListener(this::somethingChanged); + port.addListener(this::somethingChanged); numTrayNotifications.addListener(this::somethingChanged); debugMode.addListener(this::somethingChanged); theme.addListener(this::somethingChanged); @@ -131,15 +134,6 @@ public class Settings { lastUpdateCheck.addListener(this::somethingChanged); } - @SuppressWarnings("deprecation") - private void migratePortToVaultSettings(SettingsJson json) { - if(json.port != 0){ - for (VaultSettings vaultSettings : directories) { - vaultSettings.port.set(json.port); - } - } - } - @SuppressWarnings("deprecation") private void migrateLegacySettings(SettingsJson json) { // implicit migration of 1.6.x legacy setting "preferredVolumeImpl": @@ -176,6 +170,7 @@ public class Settings { json.startHidden = startHidden.get(); json.autoCloseVaults = autoCloseVaults.get(); json.useKeychain = useKeychain.get(); + json.port = port.get(); json.numTrayNotifications = numTrayNotifications.get(); json.debugMode = debugMode.get(); json.theme = theme.get(); diff --git a/src/main/java/org/cryptomator/common/settings/SettingsJson.java b/src/main/java/org/cryptomator/common/settings/SettingsJson.java index bf1514b1d..2c7c963da 100644 --- a/src/main/java/org/cryptomator/common/settings/SettingsJson.java +++ b/src/main/java/org/cryptomator/common/settings/SettingsJson.java @@ -46,9 +46,8 @@ class SettingsJson { @JsonProperty("numTrayNotifications") int numTrayNotifications = Settings.DEFAULT_NUM_TRAY_NOTIFICATIONS; - @Deprecated(since = "1.12.0") - @JsonProperty(value = "port", access = JsonProperty.Access.WRITE_ONLY) // WRITE_ONLY means value is "written" into the java object during deserialization. Upvote this: https://github.com/FasterXML/jackson-annotations/issues/233 - int port; + @JsonProperty("port") + int port = Settings.DEFAULT_PORT; @JsonProperty("showMinimizeButton") boolean showMinimizeButton = Settings.DEFAULT_SHOW_MINIMIZE_BUTTON; diff --git a/src/main/java/org/cryptomator/ui/preferences/VolumePreferencesController.java b/src/main/java/org/cryptomator/ui/preferences/VolumePreferencesController.java index c06a4596b..c02a59ee5 100644 --- a/src/main/java/org/cryptomator/ui/preferences/VolumePreferencesController.java +++ b/src/main/java/org/cryptomator/ui/preferences/VolumePreferencesController.java @@ -9,8 +9,12 @@ import org.cryptomator.ui.common.FxController; import javax.inject.Inject; import javafx.application.Application; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.BooleanExpression; import javafx.beans.value.ObservableValue; +import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; +import javafx.scene.control.TextField; import javafx.util.StringConverter; import java.util.List; import java.util.Optional; @@ -20,10 +24,13 @@ import java.util.ResourceBundle; public class VolumePreferencesController implements FxController { private static final String DOCS_MOUNTING_URL = "https://docs.cryptomator.org/en/1.7/desktop/volume-type/"; + private static final int MIN_PORT = 1024; + private static final int MAX_PORT = 65535; private final Settings settings; private final ObservableValue selectedMountService; private final ResourceBundle resourceBundle; + private final BooleanExpression loopbackPortSupported; private final ObservableValue mountToDirSupported; private final ObservableValue mountToDriveLetterSupported; private final ObservableValue mountFlagsSupported; @@ -31,6 +38,8 @@ public class VolumePreferencesController implements FxController { private final Lazy application; private final List mountProviders; public ChoiceBox volumeTypeChoiceBox; + public TextField loopbackPortField; + public Button loopbackPortApplyButton; @Inject VolumePreferencesController(Settings settings, @@ -44,6 +53,7 @@ public class VolumePreferencesController implements FxController { var fallbackProvider = mountProviders.stream().findFirst().orElse(null); this.selectedMountService = ObservableUtil.mapWithDefault(settings.mountService, serviceName -> mountProviders.stream().filter(s -> s.getClass().getName().equals(serviceName)).findFirst().orElse(fallbackProvider), fallbackProvider); + this.loopbackPortSupported = BooleanExpression.booleanExpression(selectedMountService.map(s -> s.hasCapability(MountCapability.LOOPBACK_PORT))); this.mountToDirSupported = selectedMountService.map(s -> s.hasCapability(MountCapability.MOUNT_WITHIN_EXISTING_PARENT) || s.hasCapability(MountCapability.MOUNT_TO_EXISTING_DIR)); this.mountToDriveLetterSupported = selectedMountService.map(s -> s.hasCapability(MountCapability.MOUNT_AS_DRIVE_LETTER)); this.mountFlagsSupported = selectedMountService.map(s -> s.hasCapability(MountCapability.MOUNT_FLAGS)); @@ -60,9 +70,37 @@ public class VolumePreferencesController implements FxController { var toSet = Optional.ofNullable(newProvider).map(nP -> nP.getClass().getName()).orElse(null); settings.mountService.set(toSet); }); + + 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()); + } + + private boolean validateLoopbackPort() { + try { + int port = Integer.parseInt(loopbackPortField.getText()); + return port == 0 // choose port automatically + || port >= MIN_PORT && port <= MAX_PORT; // port within range + } catch (NumberFormatException e) { + return false; + } + } + + public void doChangeLoopbackPort() { + if (validateLoopbackPort()) { + settings.port.set(Integer.parseInt(loopbackPortField.getText())); + } } /* Property Getters */ + + public BooleanExpression loopbackPortSupportedProperty() { + return loopbackPortSupported; + } + + public boolean isLoopbackPortSupported() { + return loopbackPortSupported.get(); + } public ObservableValue readonlySupportedProperty() { return readonlySupported; } diff --git a/src/main/resources/fxml/preferences_volume.fxml b/src/main/resources/fxml/preferences_volume.fxml index b2f955801..fef85aadc 100644 --- a/src/main/resources/fxml/preferences_volume.fxml +++ b/src/main/resources/fxml/preferences_volume.fxml @@ -32,6 +32,12 @@ + +