removing defaultMountDir from the settings

This commit is contained in:
infeo
2018-02-19 23:14:28 +01:00
parent c957f93ce6
commit d0d83c6833
14 changed files with 65 additions and 136 deletions

View File

@@ -30,8 +30,7 @@ public class Settings {
public static final int DEFAULT_NUM_TRAY_NOTIFICATIONS = 3;
public static final String DEFAULT_GVFS_SCHEME = "dav";
public static final boolean DEFAULT_DEBUG_MODE = false;
public static final String DEFAULT_DEFAULT_MOUNT_DIR = System.getProperty("user.home");
public static final String DEFAULT_NIO_ADAPTER = "webdav";
public static final String DEFAULT_NIO_ADAPTER = "WEBDAV";
private final ObservableList<VaultSettings> directories = FXCollections.observableArrayList(VaultSettings::observables);
private final BooleanProperty checkForUpdates = new SimpleBooleanProperty(DEFAULT_CHECK_FOR_UDPATES);
@@ -40,7 +39,6 @@ public class Settings {
private final StringProperty preferredGvfsScheme = new SimpleStringProperty(DEFAULT_GVFS_SCHEME);
private final BooleanProperty debugMode = new SimpleBooleanProperty(DEFAULT_DEBUG_MODE);
private final StringProperty nioAdapterImpl = new SimpleStringProperty(DEFAULT_NIO_ADAPTER);
private final StringProperty defaultMountDir = new SimpleStringProperty(DEFAULT_DEFAULT_MOUNT_DIR);
private Consumer<Settings> saveCmd;
@@ -55,7 +53,6 @@ public class Settings {
preferredGvfsScheme.addListener(this::somethingChanged);
debugMode.addListener(this::somethingChanged);
nioAdapterImpl.addListener(this::somethingChanged);
defaultMountDir.addListener(this::somethingChanged);
}
void setSaveCmd(Consumer<Settings> saveCmd) {
@@ -102,7 +99,4 @@ public class Settings {
return nioAdapterImpl;
}
public StringProperty defaultMountDir() {
return defaultMountDir;
}
}

View File

@@ -34,7 +34,6 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
out.name("preferredGvfsScheme").value(value.preferredGvfsScheme().get());
out.name("debugMode").value(value.debugMode().get());
out.name("nioAdapterImpl").value(value.usedNioAdapterImpl().get());
out.name("defaultMountDir").value(value.defaultMountDir().get());
out.endObject();
}
@@ -54,33 +53,30 @@ public class SettingsJsonAdapter extends TypeAdapter<Settings> {
while (in.hasNext()) {
String name = in.nextName();
switch (name) {
case "directories":
settings.getDirectories().addAll(readVaultSettingsArray(in));
break;
case "checkForUpdatesEnabled":
settings.checkForUpdates().set(in.nextBoolean());
break;
case "port":
settings.port().set(in.nextInt());
break;
case "numTrayNotifications":
settings.numTrayNotifications().set(in.nextInt());
break;
case "preferredGvfsScheme":
settings.preferredGvfsScheme().set(in.nextString());
break;
case "debugMode":
settings.debugMode().set(in.nextBoolean());
break;
case "nioAdapterImpl":
settings.usedNioAdapterImpl().set(in.nextString());
break;
case "defaultMountDir":
settings.defaultMountDir().set(in.nextString());
break;
default:
LOG.warn("Unsupported vault setting found in JSON: " + name);
in.skipValue();
case "directories":
settings.getDirectories().addAll(readVaultSettingsArray(in));
break;
case "checkForUpdatesEnabled":
settings.checkForUpdates().set(in.nextBoolean());
break;
case "port":
settings.port().set(in.nextInt());
break;
case "numTrayNotifications":
settings.numTrayNotifications().set(in.nextInt());
break;
case "preferredGvfsScheme":
settings.preferredGvfsScheme().set(in.nextString());
break;
case "debugMode":
settings.debugMode().set(in.nextBoolean());
break;
case "nioAdapterImpl":
settings.usedNioAdapterImpl().set(in.nextString());
break;
default:
LOG.warn("Unsupported vault setting found in JSON: " + name);
in.skipValue();
}
}
in.endObject();

View File

@@ -36,7 +36,7 @@ public class VaultSettings {
private final BooleanProperty unlockAfterStartup = new SimpleBooleanProperty(DEFAULT_UNLOCK_AFTER_STARTUP);
private final BooleanProperty mountAfterUnlock = new SimpleBooleanProperty(DEFAULT_MOUNT_AFTER_UNLOCK);
private final BooleanProperty revealAfterMount = new SimpleBooleanProperty(DEFAULT_REAVEAL_AFTER_MOUNT);
private final StringProperty mountPath = new SimpleStringProperty(Settings.DEFAULT_DEFAULT_MOUNT_DIR);
private final StringProperty mountPath = new SimpleStringProperty();
public VaultSettings(String id) {
this.id = Objects.requireNonNull(id);
@@ -45,7 +45,7 @@ public class VaultSettings {
}
Observable[] observables() {
return new Observable[] {path, mountName, winDriveLetter, unlockAfterStartup, mountAfterUnlock, revealAfterMount};
return new Observable[]{path, mountName, winDriveLetter, unlockAfterStartup, mountAfterUnlock, revealAfterMount};
}
private void deriveMountNameFromPath(Path path) {

View File

@@ -35,7 +35,6 @@ public class SettingsJsonAdapterTest {
Assert.assertEquals(42, settings.numTrayNotifications().get());
Assert.assertEquals("dav", settings.preferredGvfsScheme().get());
Assert.assertEquals("webdav", settings.usedNioAdapterImpl().get());
Assert.assertEquals("/home/test/crypto", settings.defaultMountDir().get());
}
}

View File

@@ -28,7 +28,7 @@
<cryptomator.cryptofs.version>1.4.5</cryptomator.cryptofs.version>
<cryptomator.webdav.version>1.0.3</cryptomator.webdav.version>
<cryptomator.jni.version>1.0.2</cryptomator.jni.version>
<cryptomator.fuse.version>0.1.1-SNAPSHOT</cryptomator.fuse.version>
<cryptomator.fuse.version>0.1.0-SNAPSHOT</cryptomator.fuse.version>
<commons-io.version>2.5</commons-io.version>
<commons-lang3.version>3.6</commons-lang3.version>

View File

@@ -2,22 +2,18 @@
* Copyright (c) 2014, 2017 Sebastian Stenzel
* All rights reserved.
* This program and the accompanying materials are made available under the terms of the accompanying LICENSE file.
*
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
******************************************************************************/
package org.cryptomator.ui.controllers;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javafx.beans.Observable;
import javafx.beans.value.ObservableValue;
import javafx.scene.layout.GridPane;
import org.apache.commons.lang3.SystemUtils;
@@ -80,15 +76,6 @@ public class SettingsController implements ViewController {
@FXML
private Label prefGvfsSchemeLabel;
@FXML
private Label defaultMountDirLabel;
@FXML
private TextField defaultMountDir;
@FXML
private Button changeDefaultMountDirButton;
@FXML
private ChoiceBox<String> prefGvfsScheme;
@@ -114,7 +101,7 @@ public class SettingsController implements ViewController {
nioAdapter.getItems().addAll(getSupportedAdapters());
nioAdapter.setValue(settings.usedNioAdapterImpl().get());
nioAdapter.setVisible(true);
nioAdapter.getSelectionModel().selectedItemProperty().addListener( (ObservableValue<? extends String> observable, String oldVal, String newVal) -> changeNioView(newVal) );
nioAdapter.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends String> observable, String oldVal, String newVal) -> changeNioView(newVal));
//WEBDAV
@@ -136,20 +123,6 @@ public class SettingsController implements ViewController {
//FUSE
fuseNioAdapter.managedProperty().bind(fuseNioAdapter.visibleProperty());
defaultMountDirLabel.managedProperty().bind(fuseNioAdapter.visibleProperty());
defaultMountDir.managedProperty().bind(fuseNioAdapter.visibleProperty());
defaultMountDirLabel.setVisible(!SystemUtils.IS_OS_WINDOWS);
defaultMountDir.setVisible(!SystemUtils.IS_OS_WINDOWS);
defaultMountDir.setText(String.valueOf(settings.defaultMountDir().get()));
changeDefaultMountDirButton.setVisible(false);
changeDefaultMountDirButton.visibleProperty().bind(
Bindings.createBooleanBinding(
() -> fuseNioAdapter.visibleProperty().get() && settings.defaultMountDir().isNotEqualTo(Strings.nullToEmpty(defaultMountDir.getText())).get() ,
fuseNioAdapter.visibleProperty(),
settings.defaultMountDir().isNotEqualTo(defaultMountDir.textProperty())
)
);
changeDefaultMountDirButton.disableProperty().bind(Bindings.createBooleanBinding(this::isDirValid, defaultMountDir.textProperty()).not());
debugModeCheckbox.setSelected(settings.debugMode().get());
@@ -160,7 +133,7 @@ public class SettingsController implements ViewController {
}
//TODO: how to implement this?
private String [] getSupportedAdapters() {
private String[] getSupportedAdapters() {
return new String[]{NioAdapterImpl.FUSE.name(), NioAdapterImpl.WEBDAV.name()};
}
@@ -185,23 +158,6 @@ public class SettingsController implements ViewController {
}
}
@FXML
private void changeDefaultMountDir(ActionEvent event){
assert isDirValid() : "Error. Not a valid Directory. Does and exist and do you have the needed Rights?";
settings.defaultMountDir().set(defaultMountDir.getText());
}
private boolean isDirValid(){
if(SystemUtils.IS_OS_WINDOWS){
//this should never ever happen!
return false;
}
else{
Path path = Paths.get(defaultMountDir.getText());
return Files.isDirectory(path) && Files.isReadable(path) && Files.isWritable(path) && Files.isExecutable(path);
}
}
private boolean isPortValid() {
try {
int port = Integer.parseInt(portField.getText());

View File

@@ -2,13 +2,12 @@
* Copyright (c) 2014, 2017 Sebastian Stenzel
* All rights reserved.
* This program and the accompanying materials are made available under the terms of the accompanying LICENSE file.
*
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
******************************************************************************/
package org.cryptomator.ui.controllers;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.util.Arrays;
@@ -18,8 +17,8 @@ import java.util.Optional;
import javax.inject.Inject;
import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.scene.layout.HBox;
import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.common.settings.VaultSettings;
@@ -116,6 +115,9 @@ public class UnlockController implements ViewController {
@FXML
private ChoiceBox<Character> winDriveLetter;
@FXML
private HBox mountPathBox;
@FXML
private Label mountPathLabel;
@@ -155,6 +157,7 @@ public class UnlockController implements ViewController {
unlockAfterStartup.disableProperty().bind(savePassword.disabledProperty().or(savePassword.selectedProperty().not()));
if (SystemUtils.IS_OS_WINDOWS) {
winDriveLetter.setConverter(new WinDriveLetterLabelConverter());
mountPathBox.setMouseTransparent(true);
mountPathLabel.setVisible(false);
mountPathLabel.setManaged(false);
mountPath.setVisible(false);
@@ -170,7 +173,7 @@ public class UnlockController implements ViewController {
changeMountPathButton.disableProperty().bind(Bindings.createBooleanBinding(this::isDirVaild, mountPath.textProperty()).not());
changeMountPathButton.visibleProperty().bind(
Bindings.createBooleanBinding(
()-> mountPathLabel.isVisible() && mountPath.textProperty().isEmpty().not().get(),
() -> mountPathLabel.isVisible() && mountPath.textProperty().isEmpty().not().get(),
mountPathLabel.visibleProperty(),
mountPath.textProperty().isEmpty().not()
)
@@ -262,31 +265,28 @@ public class UnlockController implements ViewController {
}
@FXML
private void didClickchangeMountPathButton(ActionEvent event){
private void didClickchangeMountPathButton(ActionEvent event) {
assert isDirVaild();
vault.setMountPath(mountPath.getText());
}
private boolean isDirVaild(){
try{
if(!mountPath.textProperty().isEmpty().get()){
private boolean isDirVaild() {
try {
if (!mountPath.textProperty().isEmpty().get()) {
Path p = Paths.get(mountPath.textProperty().get());
return Files.isDirectory(p) && Files.isReadable(p) && Files.isWritable(p) && Files.isExecutable(p);
}
else{
} else {
//default path will be taken
return true;
}
}
catch (InvalidPathException e){
} catch (InvalidPathException e) {
LOG.info("Invalid path");
return false;
}
}
private void filterAlphanumericKeyEvents(KeyEvent t) {
if (!Strings.isNullOrEmpty(t.getCharacter()) && !ALPHA_NUMERIC_MATCHER.matchesAllOf(t.getCharacter())) {
t.consume();
@@ -451,6 +451,7 @@ public class UnlockController implements ViewController {
@FunctionalInterface
interface UnlockListener {
void didUnlock(Vault vault);
}

View File

@@ -23,35 +23,30 @@ public class FuseNioAdapter implements NioAdapter {
}
@Override
public void unlock(CryptoFileSystem fs) {
public void prepare(CryptoFileSystem fs) {
this.cfs = fs;
ffs = AdapterFactory.createReadWriteAdapter(fs.getPath("/"));
}
/**
* TODO: should createTempDirectory() be used instead of createDirectory()?
*
* @throws CommandFailedException
*/
@Override
public void mount() throws CommandFailedException {
try {
fuseEnv.prepare();
ffs.mount(fuseEnv.getFsRootPath(), false, false, fuseEnv.getMountParameters());
} catch (Exception e) {
try {
fuseEnv.prepare();
ffs.mount(fuseEnv.getFsRootPath(), false, false, fuseEnv.getMountParameters());
} catch (Exception e) {
throw new CommandFailedException("Unable to mount Filesystem", e);
}
}
@Override
public void reveal() throws CommandFailedException{
public void reveal() throws CommandFailedException {
fuseEnv.revealFsRootInFilesystemManager();
}
@Override
public synchronized void unmount() throws CommandFailedException {
if (cfs.getStats().pollBytesRead() == 0 && cfs.getStats().pollBytesWritten() == 0) {
unmountForced();
unmountRaw();
} else {
throw new CommandFailedException("Pending read or write operations.");
}
@@ -59,6 +54,10 @@ public class FuseNioAdapter implements NioAdapter {
@Override
public synchronized void unmountForced() throws CommandFailedException {
this.unmountRaw();
}
private synchronized void unmountRaw() {
ffs.umount();
}
@@ -68,7 +67,7 @@ public class FuseNioAdapter implements NioAdapter {
}
@Override
public String getFsRootUrlString() {
public String getMountUrl() {
return fuseEnv.getFsRootPath().toUri().toString();
}

View File

@@ -4,7 +4,7 @@ import org.cryptomator.cryptofs.CryptoFileSystem;
public interface NioAdapter {
void unlock(CryptoFileSystem fs);
void prepare(CryptoFileSystem fs);
void mount() throws CommandFailedException;
@@ -20,7 +20,7 @@ public interface NioAdapter {
void stop();
String getFsRootUrlString();
String getMountUrl();
default boolean isSupported() {
return false;

View File

@@ -30,7 +30,6 @@ import org.cryptomator.cryptolib.api.CryptoException;
import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.cryptomator.ui.model.VaultModule.PerVault;
import com.google.common.base.Strings;
import javafx.application.Platform;
import javafx.beans.Observable;
import javafx.beans.binding.Binding;
@@ -68,10 +67,6 @@ public class Vault {
this.settings = settings;
this.vaultSettings = vaultSettings;
this.nioAdapter = nioAdapter;
if (Strings.isNullOrEmpty(vaultSettings.mountPath().get())) {
vaultSettings.mountPath().set(settings.defaultMountDir().get() + "/" + vaultSettings.mountName().get());
}
}
// ******************************************************************************
@@ -105,7 +100,7 @@ public class Vault {
public synchronized void unlock(CharSequence passphrase) throws CryptoException, IOException {
CryptoFileSystem fs = getCryptoFileSystem(passphrase);
nioAdapter.unlock(fs);
nioAdapter.prepare(fs);
Platform.runLater(() -> {
state.set(State.UNLOCKED);
});
@@ -267,11 +262,7 @@ public class Vault {
}
public void setMountPath(String mountPath) {
if (mountPath.isEmpty()) {
vaultSettings.mountPath().set(settings.defaultMountDir().get());
} else {
vaultSettings.mountPath().set(mountPath);
}
vaultSettings.mountPath().set(mountPath);
}
public void setMountName(String mountName) throws IllegalArgumentException {
@@ -299,7 +290,7 @@ public class Vault {
}
public String getFilesystemRootUrl() {
return nioAdapter.getFsRootUrlString();
return nioAdapter.getMountUrl();
}
public String getId() {

View File

@@ -33,7 +33,7 @@ public class WebDavNioAdapter implements NioAdapter {
}
@Override
public void unlock(CryptoFileSystem fs) {
public void prepare(CryptoFileSystem fs) {
if (!server.isRunning()) {
server.start();
}
@@ -104,7 +104,7 @@ public class WebDavNioAdapter implements NioAdapter {
}
public synchronized String getFsRootUrlString() {
public synchronized String getMountUrl() {
return servlet.getServletRootUri().toString();
}

View File

@@ -59,11 +59,6 @@
<!-- Row 3 Alt 2-->
<GridPane fx:id="fuseNioAdapter" vgap="12.0" hgap="12.0" GridPane.rowIndex="3" GridPane.columnIndex="0" GridPane.columnSpan="2" visible="false" cacheShape="true" cache="true">
<Label fx:id="defaultMountDirLabel" GridPane.rowIndex="3" GridPane.columnIndex="0" text="%settings.fuse.defaultMntDir.label" cacheShape="true" cache="true"/>
<HBox GridPane.rowIndex="3" GridPane.columnIndex="1" spacing="6.0">
<TextField fx:id="defaultMountDir" cacheShape="true" cache="true" promptText="%settings.fuse.defaultMntDir.defaultVal" />
<Button text="%settings.webdav.port.apply" fx:id="changeDefaultMountDirButton" onAction="#changeDefaultMountDir"/>
</HBox>
</GridPane>
</children>

View File

@@ -90,7 +90,7 @@
<!-- Row 3.6 Alt2 -->
<Label GridPane.rowIndex="6" GridPane.columnIndex="0" fx:id="mountPathLabel" text="%unlock.label.mountPath" cacheShape="true" cache="true" />
<HBox GridPane.rowIndex="6" GridPane.columnIndex="1" spacing="6.0">
<HBox GridPane.rowIndex="6" GridPane.columnIndex="1" fx:id="mountPathBox" spacing="6.0">
<TextField GridPane.rowIndex="6" GridPane.columnIndex="1" fx:id="mountPath" cacheShape="true" cache="true" />
<Button text="%unlock.label.mountPathButton" fx:id="changeMountPathButton" onAction="#didClickchangeMountPathButton"/>
</HBox>

View File

@@ -122,8 +122,6 @@ settings.requiresRestartLabel=* Cryptomator needs to restart
settings.nioAdapter.label= Mount-Methode *
settings.nioAdapter.webdav=WebDAV
settings.nioAdapter.fuse=FUSE
settings.fuse.defaultMntDir.label=Default mounting point
settings.fuse.defaultMntDir.defaultVal=/dev/null
# tray icon
tray.menu.open=Open