Browse Source

pr mentioned changes

Jan-Peter Klein 1 year ago
parent
commit
65788f3c1f

+ 1 - 2
src/main/java/org/cryptomator/common/mount/MountModule.java

@@ -22,8 +22,7 @@ public class MountModule {
 	@Provides
 	@Singleton
 	static ObservableValue<MountService> provideDefaultMountService(List<MountService> mountProviders, Settings settings) {
-		var fallbackProvider = mountProviders.stream().findFirst().orElse(null);
-
+		var fallbackProvider = mountProviders.stream().findFirst().get(); //there should always be a mount provider, at least webDAV
 		return ObservableUtil.mapWithDefault(settings.mountService, //
 				serviceName -> mountProviders.stream().filter(s -> s.getClass().getName().equals(serviceName)).findFirst().orElse(fallbackProvider), //
 				fallbackProvider);

+ 10 - 10
src/main/java/org/cryptomator/ui/vaultoptions/MountOptionsController.java

@@ -2,6 +2,7 @@ package org.cryptomator.ui.vaultoptions;
 
 import com.google.common.base.Strings;
 import dagger.Lazy;
+import org.cryptomator.common.ObservableUtil;
 import org.cryptomator.common.mount.Mounter;
 import org.cryptomator.common.mount.WindowsDriveLetters;
 import org.cryptomator.common.settings.VaultSettings;
@@ -60,7 +61,7 @@ public class MountOptionsController implements FxController {
 	private final ObservableValue<MountService> defaultMountService;
 	private final ObservableValue<MountService> selectedMountService;
 	private final ObservableValue<Boolean> fuseRestartRequired;
-	private final ObservableValue<Boolean> loopbackPortSupported;
+	private final ObservableValue<Boolean> loopbackPortChangeable;
 
 
 	//-- FXML objects --
@@ -112,11 +113,11 @@ public class MountOptionsController implements FxController {
 			}
 		});
 		this.mountFlagsSupported = selectedMountService.map(s -> s.hasCapability(MountCapability.MOUNT_FLAGS));
-		this.defaultMountServiceSelected = selectedMountService.map(_ -> vaultSettings.mountService.getValue() == null);
+		this.defaultMountServiceSelected = ObservableUtil.mapWithDefault(vaultSettings.mountService, _ -> false, true);
 		this.readOnlySupported = selectedMountService.map(s -> s.hasCapability(MountCapability.READ_ONLY));
 		this.mountpointDirSupported = selectedMountService.map(s -> s.hasCapability(MountCapability.MOUNT_TO_EXISTING_DIR) || s.hasCapability(MountCapability.MOUNT_WITHIN_EXISTING_PARENT));
 		this.mountpointDriveLetterSupported = selectedMountService.map(s -> s.hasCapability(MountCapability.MOUNT_AS_DRIVE_LETTER));
-		this.loopbackPortSupported = selectedMountService.map(s -> s.hasCapability(MountCapability.LOOPBACK_PORT) && vaultSettings.mountService.getValue() != null);
+		this.loopbackPortChangeable = selectedMountService.map(s -> s.hasCapability(MountCapability.LOOPBACK_PORT) && vaultSettings.mountService.getValue() != null);
 	}
 
 	private MountService reselectMountService() {
@@ -159,9 +160,8 @@ public class MountOptionsController implements FxController {
 		vaultVolumeTypeChoiceBox.getItems().add(null);
 		vaultVolumeTypeChoiceBox.getItems().addAll(mountProviders);
 		vaultVolumeTypeChoiceBox.setConverter(new MountServiceConverter());
-		boolean autoSelected = vaultSettings.mountService.get() == null;
-		vaultVolumeTypeChoiceBox.getSelectionModel().select(autoSelected ? null : selectedMountService.getValue());
-		vaultVolumeTypeChoiceBox.valueProperty().addListener((observableValue, oldProvider, newProvider) -> {
+		vaultVolumeTypeChoiceBox.getSelectionModel().select(isDefaultMountServiceSelected() ? null : selectedMountService.getValue());
+		vaultVolumeTypeChoiceBox.valueProperty().addListener((_, _, newProvider) -> {
 			var toSet = Optional.ofNullable(newProvider).map(nP -> nP.getClass().getName()).orElse(null);
 			vaultSettings.mountService.set(toSet);
 		});
@@ -375,12 +375,12 @@ public class MountOptionsController implements FxController {
 		return fuseRestartRequired.getValue();
 	}
 
-	public ObservableValue<Boolean> loopbackPortSupportedProperty() {
-		return loopbackPortSupported;
+	public ObservableValue<Boolean> loopbackPortChangeableProperty() {
+		return loopbackPortChangeable;
 	}
 
-	public boolean isLoopbackPortSupported() {
-		return loopbackPortSupported.getValue();
+	public boolean isLoopbackPortChangeable() {
+		return loopbackPortChangeable.getValue();
 	}
 
 	private class MountServiceConverter extends StringConverter<MountService> {

+ 1 - 2
src/main/resources/fxml/vault_options_mount.fxml

@@ -14,7 +14,6 @@
 <?import javafx.scene.control.Tooltip?>
 <?import javafx.scene.layout.HBox?>
 <?import javafx.scene.layout.VBox?>
-<?import javafx.scene.text.TextFlow?>
 <VBox xmlns:fx="http://javafx.com/fxml"
 	  xmlns="http://javafx.com/javafx"
 	  fx:controller="org.cryptomator.ui.vaultoptions.MountOptionsController"
@@ -49,7 +48,7 @@
 
 		<Label styleClass="label-red" text="%vaultOptions.mount.volumeType.fuseRestartRequired" visible="${controller.fuseRestartRequired}" managed="${controller.fuseRestartRequired}"/>
 
-		<HBox spacing="12" alignment="CENTER_LEFT" visible="${controller.loopbackPortSupported}" managed="${controller.loopbackPortSupported}">
+		<HBox spacing="12" alignment="CENTER_LEFT" visible="${controller.loopbackPortChangeable}" managed="${controller.loopbackPortChangeable}">
 			<Label text="%vaultOptions.mount.volume.tcp.port"/>
 			<NumericTextField fx:id="vaultLoopbackPortField"/>
 			<Button text="%generic.button.apply" fx:id="vaultLoopbackPortApplyButton" onAction="#doChangeLoopbackPort"/>