fixes #100 (reveal script now running on background thread. to be confirmed on Windows Vista)

This commit is contained in:
Sebastian Stenzel
2015-11-03 00:29:39 +01:00
parent 0c116d0385
commit ebb421bd4c
2 changed files with 69 additions and 57 deletions

View File

@@ -20,6 +20,22 @@ import java.util.ResourceBundle;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.inject.Inject;
import javax.security.auth.DestroyFailedException;
import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.crypto.exceptions.UnsupportedKeyLengthException;
import org.cryptomator.crypto.exceptions.UnsupportedVaultException;
import org.cryptomator.crypto.exceptions.WrongPasswordException;
import org.cryptomator.ui.controls.SecPasswordField;
import org.cryptomator.ui.model.Vault;
import org.cryptomator.ui.util.FXThreads;
import org.cryptomator.ui.util.mount.CommandFailedException;
import org.cryptomator.ui.util.mount.WindowsDriveLetters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
@@ -37,22 +53,6 @@ import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.util.StringConverter;
import javax.inject.Inject;
import javax.security.auth.DestroyFailedException;
import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.crypto.exceptions.UnsupportedKeyLengthException;
import org.cryptomator.crypto.exceptions.UnsupportedVaultException;
import org.cryptomator.crypto.exceptions.WrongPasswordException;
import org.cryptomator.ui.controls.SecPasswordField;
import org.cryptomator.ui.model.Vault;
import org.cryptomator.ui.util.FXThreads;
import org.cryptomator.ui.util.mount.CommandFailedException;
import org.cryptomator.ui.util.mount.WindowsDriveLetters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UnlockController extends AbstractFXMLViewController {
private static final Logger LOG = LoggerFactory.getLogger(UnlockController.class);
@@ -65,10 +65,10 @@ public class UnlockController extends AbstractFXMLViewController {
@FXML
private TextField mountName;
@FXML
private Label winDriveLetterLabel;
@FXML
private ChoiceBox<Character> winDriveLetter;
@@ -177,7 +177,7 @@ public class UnlockController extends AbstractFXMLViewController {
advancedOptionsButton.setText(resourceBundle.getString("unlock.button.advancedOptions.show"));
}
}
private void filterAlphanumericKeyEvents(KeyEvent t) {
if (t.getCharacter() == null || t.getCharacter().length() == 0) {
return;
@@ -199,9 +199,9 @@ public class UnlockController extends AbstractFXMLViewController {
vault.setMountName(newValue);
}
}
/**
* Converts 'C' to "C:" to translate between model and GUI.
* Converts 'C' to "C:" to translate between model and GUI.
*/
private class WinDriveLetterLabelConverter extends StringConverter<Character> {
@@ -222,9 +222,9 @@ public class UnlockController extends AbstractFXMLViewController {
return CharUtils.toCharacterObject(string);
}
}
}
/**
* Natural sorting of ASCII letters, but <code>null</code> always on first, as this is "auto-assign".
*/
@@ -237,11 +237,11 @@ public class UnlockController extends AbstractFXMLViewController {
} else if (c2 == null) {
return 1;
} else {
return (char) c1 - (char) c2;
return c1 - c2;
}
}
}
private void winDriveLetterDidChange(ObservableValue<? extends Character> property, Character oldValue, Character newValue) {
if (vault == null) {
return;
@@ -317,14 +317,18 @@ public class UnlockController extends AbstractFXMLViewController {
progressIndicator.setVisible(false);
setControlsDisabled(false);
if (vault.isUnlocked() && !mountSuccess) {
vault.stopServer();
vault.setUnlocked(false);
exec.submit(() -> {
vault.stopServer();
vault.setUnlocked(false);
});
} else if (vault.isUnlocked() && mountSuccess) {
try {
vault.reveal();
} catch (CommandFailedException e) {
LOG.error("Failed to reveal mounted vault", e);
}
exec.submit(() -> {
try {
vault.reveal();
} catch (CommandFailedException e) {
LOG.error("Failed to reveal mounted vault", e);
}
});
}
if (mountSuccess && listener != null) {
listener.didUnlock(this);
@@ -345,7 +349,7 @@ public class UnlockController extends AbstractFXMLViewController {
chooseSelectedDriveLetter();
}
}
private void chooseSelectedDriveLetter() {
assert SystemUtils.IS_OS_WINDOWS;
// if the vault prefers a drive letter, that is currently occupied, this is our last chance to reset this:

View File

@@ -10,6 +10,7 @@ package org.cryptomator.ui.controllers;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Provider;
@@ -54,10 +55,12 @@ public class UnlockedController extends AbstractFXMLViewController {
private final Stage macWarningsWindow = new Stage();
private final MacWarningsController macWarningsController;
private final ExecutorService exec;
@Inject
public UnlockedController(Provider<MacWarningsController> macWarningsControllerProvider) {
public UnlockedController(Provider<MacWarningsController> macWarningsControllerProvider, ExecutorService exec) {
this.macWarningsController = macWarningsControllerProvider.get();
this.exec = exec;
}
@Override
@@ -78,27 +81,36 @@ public class UnlockedController extends AbstractFXMLViewController {
@FXML
private void didClickRevealVault(ActionEvent event) {
try {
vault.reveal();
} catch (CommandFailedException e) {
messageLabel.setText(resourceBundle.getString("unlocked.label.revealFailed"));
return;
}
exec.submit(() -> {
try {
vault.reveal();
} catch (CommandFailedException e) {
Platform.runLater(() -> {
messageLabel.setText(resourceBundle.getString("unlocked.label.revealFailed"));
});
}
});
}
@FXML
private void didClickCloseVault(ActionEvent event) {
try {
vault.unmount();
} catch (CommandFailedException e) {
messageLabel.setText(resourceBundle.getString("unlocked.label.unmountFailed"));
return;
}
vault.stopServer();
vault.setUnlocked(false);
if (listener != null) {
listener.didLock(this);
}
exec.submit(() -> {
try {
vault.unmount();
} catch (CommandFailedException e) {
Platform.runLater(() -> {
messageLabel.setText(resourceBundle.getString("unlocked.label.unmountFailed"));
});
return;
}
vault.stopServer();
vault.setUnlocked(false);
if (listener != null) {
Platform.runLater(() -> {
listener.didLock(this);
});
}
});
}
// ****************************************
@@ -107,13 +119,9 @@ public class UnlockedController extends AbstractFXMLViewController {
private void macWarningsDidChange(ListChangeListener.Change<? extends String> change) {
if (change.getList().size() > 0) {
Platform.runLater(() -> {
macWarningsWindow.show();
});
Platform.runLater(macWarningsWindow::show);
} else {
Platform.runLater(() -> {
macWarningsWindow.hide();
});
Platform.runLater(macWarningsWindow::hide);
}
}