Przeglądaj źródła

refactored code, global default volume type settings

Jan-Peter Klein 1 rok temu
rodzic
commit
1b5125dfed

+ 12 - 6
src/main/java/org/cryptomator/common/mount/Mounter.java

@@ -28,8 +28,8 @@ import static org.cryptomator.integrations.mount.MountCapability.UNMOUNT_FORCED;
 public class Mounter {
 
 	private static final List<String> problematicFuseMountServices = List.of("org.cryptomator.frontend.fuse.mount.MacFuseMountProvider", "org.cryptomator.frontend.fuse.mount.FuseTMountProvider");
-
 	private final Environment env;
+	private final Settings settings;
 	private final WindowsDriveLetters driveLetters;
 	private final List<MountService> mountProviders;
 	private final AtomicReference<MountService> firstUsedProblematicFuseMountService;
@@ -37,11 +37,12 @@ public class Mounter {
 
 	@Inject
 	public Mounter(Environment env, //
+				   Settings settings, //
 				   WindowsDriveLetters driveLetters, //
 				   List<MountService> mountProviders, //
-				   @Named("FUPFMS") AtomicReference<MountService> firstUsedProblematicFuseMountService,
-				   ObservableValue<MountService> defaultMountService) {
+				   @Named("FUPFMS") AtomicReference<MountService> firstUsedProblematicFuseMountService, ObservableValue<MountService> defaultMountService) {
 		this.env = env;
+		this.settings = settings;
 		this.driveLetters = driveLetters;
 		this.mountProviders = mountProviders;
 		this.firstUsedProblematicFuseMountService = firstUsedProblematicFuseMountService;
@@ -64,7 +65,13 @@ public class Mounter {
 			for (var capability : service.capabilities()) {
 				switch (capability) {
 					case FILE_SYSTEM_NAME -> builder.setFileSystemName("cryptoFs");
-					case LOOPBACK_PORT -> builder.setLoopbackPort(vaultSettings.port.get());
+					case LOOPBACK_PORT -> {
+						if (vaultSettings.mountService.getValue() == null) {
+							builder.setLoopbackPort(settings.port.get());
+						} else {
+							builder.setLoopbackPort(vaultSettings.port.get());
+						}
+					}
 					case LOOPBACK_HOST_NAME -> env.getLoopbackAlias().ifPresent(builder::setLoopbackHostName);
 					case READ_ONLY -> builder.setReadOnly(vaultSettings.usesReadOnlyMode.get());
 					case MOUNT_FLAGS -> {
@@ -146,8 +153,7 @@ public class Mounter {
 		var targetIsProblematicFuse = isProblematicFuseService(selMntServ);
 		if (targetIsProblematicFuse && firstUsedProblematicFuseMountService.get() == null) {
 			firstUsedProblematicFuseMountService.set(selMntServ);
-		}
-		else if (targetIsProblematicFuse && !firstUsedProblematicFuseMountService.get().equals(selMntServ)) {
+		} else if (targetIsProblematicFuse && !firstUsedProblematicFuseMountService.get().equals(selMntServ)) {
 			throw new FuseRestartRequiredException("Failed to mount the specified mount service.");
 		}
 

+ 7 - 6
src/main/java/org/cryptomator/ui/preferences/VolumePreferencesController.java

@@ -23,9 +23,9 @@ import java.util.ResourceBundle;
 @PreferencesScoped
 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;
+	public static final String DOCS_MOUNTING_URL = "https://docs.cryptomator.org/en/1.7/desktop/volume-type/";
+	public static final int MIN_PORT = 1024;
+	public static final int MAX_PORT = 65535;
 
 	private final Settings settings;
 	private final ObservableValue<MountService> selectedMountService;
@@ -42,9 +42,9 @@ public class VolumePreferencesController implements FxController {
 	public Button loopbackPortApplyButton;
 
 	@Inject
-	VolumePreferencesController(Settings settings,
-								Lazy<Application> application,
-								List<MountService> mountProviders,
+	VolumePreferencesController(Settings settings, //
+								Lazy<Application> application, //
+								List<MountService> mountProviders, //
 								ResourceBundle resourceBundle) {
 		this.settings = settings;
 		this.application = application;
@@ -101,6 +101,7 @@ public class VolumePreferencesController implements FxController {
 	public boolean isLoopbackPortSupported() {
 		return loopbackPortSupported.get();
 	}
+
 	public ObservableValue<Boolean> readonlySupportedProperty() {
 		return readonlySupported;
 	}

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

@@ -4,12 +4,14 @@ import com.google.common.base.Strings;
 import dagger.Lazy;
 import org.cryptomator.common.mount.Mounter;
 import org.cryptomator.common.mount.WindowsDriveLetters;
-import org.cryptomator.common.settings.Settings;
 import org.cryptomator.common.settings.VaultSettings;
 import org.cryptomator.common.vaults.Vault;
 import org.cryptomator.integrations.mount.MountCapability;
 import org.cryptomator.integrations.mount.MountService;
 import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.fxapp.FxApplicationWindows;
+import org.cryptomator.ui.preferences.SelectedPreferencesTab;
+import org.cryptomator.ui.preferences.VolumePreferencesController;
 
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -41,10 +43,6 @@ import java.util.concurrent.atomic.AtomicReference;
 @VaultOptionsScoped
 public class MountOptionsController 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 Stage window;
 	private final VaultSettings vaultSettings;
 	private final WindowsDriveLetters windowsDriveLetters;
@@ -56,7 +54,9 @@ public class MountOptionsController implements FxController {
 	private final ObservableValue<Boolean> mountpointDriveLetterSupported;
 	private final ObservableValue<Boolean> readOnlySupported;
 	private final ObservableValue<Boolean> mountFlagsSupported;
+	private final ObservableValue<Boolean> defaultMountServiceSelected;
 	private final ObservableValue<String> directoryPath;
+	private final FxApplicationWindows applicationWindows;
 	private final List<MountService> mountProviders;
 	private final ObservableValue<MountService> defaultMountService;
 	private final ObservableValue<MountService> selectedMountService;
@@ -81,17 +81,19 @@ public class MountOptionsController implements FxController {
 
 	@Inject
 	MountOptionsController(@VaultOptionsWindow Stage window, //
-						   Settings settings, //
 						   @VaultOptionsWindow Vault vault, //
 						   WindowsDriveLetters windowsDriveLetters, //
 						   ResourceBundle resourceBundle, //
+						   FxApplicationWindows applicationWindows, //
 						   Lazy<Application> application, //
 						   List<MountService> mountProviders, //
-						   @Named("FUPFMS") AtomicReference<MountService> firstUsedProblematicFuseMountService, ObservableValue<MountService> defaultMountService) {
+						   @Named("FUPFMS") AtomicReference<MountService> firstUsedProblematicFuseMountService, //
+						   ObservableValue<MountService> defaultMountService) {
 		this.window = window;
 		this.vaultSettings = vault.getVaultSettings();
 		this.windowsDriveLetters = windowsDriveLetters;
 		this.resourceBundle = resourceBundle;
+		this.applicationWindows = applicationWindows;
 		this.directoryPath = vault.getVaultSettings().mountPoint.map(p -> isDriveLetter(p) ? null : p.toString());
 		this.application = application;
 		this.mountProviders = mountProviders;
@@ -102,7 +104,7 @@ public class MountOptionsController implements FxController {
 					&& Mounter.isProblematicFuseService(s) //
 					&& !firstUsedProblematicFuseMountService.get().equals(s);
 		});
-		this.loopbackPortSupported = BooleanExpression.booleanExpression(selectedMountService.map(s -> s.hasCapability(MountCapability.LOOPBACK_PORT)));
+		this.loopbackPortSupported = BooleanExpression.booleanExpression(selectedMountService.map(s -> s.hasCapability(MountCapability.LOOPBACK_PORT) && vaultSettings.mountService.getValue() != null));
 
 		this.defaultMountFlags = selectedMountService.map(s -> {
 			if (s.hasCapability(MountCapability.MOUNT_FLAGS)) {
@@ -112,6 +114,7 @@ public class MountOptionsController implements FxController {
 			}
 		});
 		this.mountFlagsSupported = selectedMountService.map(s -> s.hasCapability(MountCapability.MOUNT_FLAGS));
+		this.defaultMountServiceSelected = selectedMountService.map(_ -> vaultSettings.mountService.getValue() == null);
 		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));
@@ -170,6 +173,11 @@ public class MountOptionsController implements FxController {
 
 	}
 
+	@FXML
+	public void openVolumePreferences() {
+		applicationWindows.showPreferencesWindow(SelectedPreferencesTab.VOLUME);
+	}
+
 	@FXML
 	public void toggleUseCustomMountFlags() {
 		if (customMountFlagsCheckbox.isSelected()) {
@@ -287,14 +295,14 @@ public class MountOptionsController implements FxController {
 	}
 
 	public void openDocs() {
-		application.get().getHostServices().showDocument(DOCS_MOUNTING_URL);
+		application.get().getHostServices().showDocument(VolumePreferencesController.DOCS_MOUNTING_URL);
 	}
 
 	private boolean validateLoopbackPort() {
 		try {
 			int port = Integer.parseInt(vaultLoopbackPortField.getText());
 			return port == 0 // choose port automatically
-					|| port >= MIN_PORT && port <= MAX_PORT; // port within range
+					|| port >= VolumePreferencesController.MIN_PORT && port <= VolumePreferencesController.MAX_PORT; // port within range
 		} catch (NumberFormatException e) {
 			return false;
 		}
@@ -320,6 +328,14 @@ public class MountOptionsController implements FxController {
 		return mountFlagsSupported.getValue();
 	}
 
+	public ObservableValue<Boolean> defaultMountServiceSelectedProperty() {
+		return defaultMountServiceSelected;
+	}
+
+	public boolean isDefaultMountServiceSelected() {
+		return defaultMountServiceSelected.getValue();
+	}
+
 	public ObservableValue<Boolean> mountpointDirSupportedProperty() {
 		return mountpointDirSupported;
 	}

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

@@ -14,6 +14,7 @@
 <?import javafx.scene.layout.HBox?>
 <?import javafx.scene.layout.VBox?>
 <?import javafx.scene.control.Tooltip?>
+<?import javafx.scene.text.TextFlow?>
 <VBox xmlns:fx="http://javafx.com/fxml"
 	  xmlns="http://javafx.com/javafx"
 	  fx:controller="org.cryptomator.ui.vaultoptions.MountOptionsController"
@@ -38,10 +39,16 @@
 			</Hyperlink>
 		</HBox>
 
+		<TextFlow visible="${controller.defaultMountServiceSelected}" managed="${controller.defaultMountServiceSelected}">
+			<Label text="%vaultOptions.mount.info"/>
+			<Label text=" "/>
+			<Hyperlink styleClass="hyperlink-underline" text="%vaultOptions.mount.linkToPreferences" onAction="#openVolumePreferences" wrapText="true"/>
+		</TextFlow>
+
 		<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}">
-			<Label text="%preferences.volume.tcp.port"/>
+			<Label text="%vaultOptions.mount.volume.tcp.port"/>
 			<NumericTextField fx:id="vaultLoopbackPortField"/>
 			<Button text="%generic.button.apply" fx:id="vaultLoopbackPortApplyButton" onAction="#doChangeLoopbackPort"/>
 		</HBox>

+ 4 - 1
src/main/resources/i18n/strings.properties

@@ -303,7 +303,7 @@ preferences.volume.defaultVolumeTypeLabel=Default Volume Type
 preferences.volume.type.automatic=Automatic
 preferences.volume.docsTooltip=Open the documentation to learn more about the different volume types.
 preferences.volume.fuseRestartRequired=To apply the changes, Cryptomator needs to be restarted.
-preferences.volume.tcp.port=TCP Port
+preferences.volume.tcp.port=Default TCP Port
 preferences.volume.supportedFeatures=The chosen volume type supports the following features:
 preferences.volume.feature.mountAuto=Automatic mount point selection
 preferences.volume.feature.mountToDir=Custom directory as mount point
@@ -442,6 +442,8 @@ vaultOptions.general.startHealthCheckBtn=Start Health Check
 
 ## Mount
 vaultOptions.mount=Mounting
+vaultOptions.mount.info=Default options can be changed in preferences.
+vaultOptions.mount.linkToPreferences=Open virtual drive preferences
 vaultOptions.mount.readonly=Read-only
 vaultOptions.mount.customMountFlags=Custom mount flags
 vaultOptions.mount.winDriveLetterOccupied=occupied
@@ -453,6 +455,7 @@ vaultOptions.mount.mountPoint.directoryPickerButton=Choose…
 vaultOptions.mount.mountPoint.directoryPickerTitle=Pick a directory
 vaultOptions.mount.volumeType.default=Default (%s)
 vaultOptions.mount.volumeType.fuseRestartRequired=To use this volume type, Cryptomator needs to be restarted.
+vaultOptions.mount.volume.tcp.port=TCP Port
 ## Master Key
 vaultOptions.masterkey=Password
 vaultOptions.masterkey.changePasswordBtn=Change Password