refactored code, global default volume type settings

This commit is contained in:
Jan-Peter Klein
2023-12-07 10:48:33 +01:00
parent da240ce8b9
commit 1b5125dfed
5 changed files with 57 additions and 24 deletions

View File

@@ -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.");
}

View File

@@ -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;
}

View File

@@ -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;
}