Skip to content

Commit

Permalink
Removed "Mount after unlock" option. Mounting/unmounting no longer vi…
Browse files Browse the repository at this point in the history
…sible to the user, but merged with unlocking/locking.
  • Loading branch information
overheadhunter committed May 14, 2018
1 parent b0ab46b commit d53af61
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
public class VaultSettings {

public static final boolean DEFAULT_UNLOCK_AFTER_STARTUP = false;
public static final boolean DEFAULT_MOUNT_AFTER_UNLOCK = true;
public static final boolean DEFAULT_REAVEAL_AFTER_MOUNT = true;
public static final boolean DEFAULT_USES_INDIVIDUAL_MOUNTPATH = false;

Expand All @@ -35,7 +34,6 @@ public class VaultSettings {
private final StringProperty mountName = new SimpleStringProperty();
private final StringProperty winDriveLetter = new SimpleStringProperty();
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 BooleanProperty usesIndividualMountPath = new SimpleBooleanProperty(DEFAULT_USES_INDIVIDUAL_MOUNTPATH);
private final StringProperty individualMountPath = new SimpleStringProperty();
Expand All @@ -47,7 +45,7 @@ public VaultSettings(String id) {
}

Observable[] observables() {
return new Observable[]{path, mountName, winDriveLetter, unlockAfterStartup, mountAfterUnlock, revealAfterMount, usesIndividualMountPath, individualMountPath};
return new Observable[]{path, mountName, winDriveLetter, unlockAfterStartup, revealAfterMount, usesIndividualMountPath, individualMountPath};
}

private void deriveMountNameFromPath(Path path) {
Expand Down Expand Up @@ -118,10 +116,6 @@ public BooleanProperty unlockAfterStartup() {
return unlockAfterStartup;
}

public BooleanProperty mountAfterUnlock() {
return mountAfterUnlock;
}

public BooleanProperty revealAfterMount() {
return revealAfterMount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void write(JsonWriter out, VaultSettings value) throws IOException {
out.name("mountName").value(value.mountName().get());
out.name("winDriveLetter").value(value.winDriveLetter().get());
out.name("unlockAfterStartup").value(value.unlockAfterStartup().get());
out.name("mountAfterUnlock").value(value.mountAfterUnlock().get());
out.name("revealAfterMount").value(value.revealAfterMount().get());
out.name("usesIndividualMountPath").value(value.usesIndividualMountPath().get());
//TODO: should this always be written? ( because it could contain metadata, which the user does not want to save!)
Expand All @@ -40,7 +39,6 @@ public VaultSettings read(JsonReader in) throws IOException {
String individualMountPath = null;
String winDriveLetter = null;
boolean unlockAfterStartup = VaultSettings.DEFAULT_UNLOCK_AFTER_STARTUP;
boolean mountAfterUnlock = VaultSettings.DEFAULT_MOUNT_AFTER_UNLOCK;
boolean revealAfterMount = VaultSettings.DEFAULT_REAVEAL_AFTER_MOUNT;
boolean usesIndividualMountPath = VaultSettings.DEFAULT_USES_INDIVIDUAL_MOUNTPATH;

Expand All @@ -63,9 +61,6 @@ public VaultSettings read(JsonReader in) throws IOException {
case "unlockAfterStartup":
unlockAfterStartup = in.nextBoolean();
break;
case "mountAfterUnlock":
mountAfterUnlock = in.nextBoolean();
break;
case "revealAfterMount":
revealAfterMount = in.nextBoolean();
break;
Expand All @@ -87,7 +82,6 @@ public VaultSettings read(JsonReader in) throws IOException {
vaultSettings.path().set(Paths.get(path));
vaultSettings.winDriveLetter().set(winDriveLetter);
vaultSettings.unlockAfterStartup().set(unlockAfterStartup);
vaultSettings.mountAfterUnlock().set(mountAfterUnlock);
vaultSettings.revealAfterMount().set(revealAfterMount);
vaultSettings.usesIndividualMountPath().set(usesIndividualMountPath);
vaultSettings.individualMountPath().set(individualMountPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ public UnlockController(Application app, Localization localization, AsyncTaskSer
@FXML
private CheckBox savePassword;

@FXML
private CheckBox mountAfterUnlock;

@FXML
private TextField mountName;

Expand Down Expand Up @@ -159,8 +156,6 @@ public UnlockController(Application app, Localization localization, AsyncTaskSer
public void initialize() {
advancedOptions.managedProperty().bind(advancedOptions.visibleProperty());
unlockButton.disableProperty().bind(passwordField.textProperty().isEmpty());
mountName.disableProperty().bind(mountAfterUnlock.selectedProperty().not());
revealAfterMount.disableProperty().bind(mountAfterUnlock.selectedProperty().not());
mountName.addEventFilter(KeyEvent.KEY_TYPED, this::filterAlphanumericKeyEvents);
mountName.textProperty().addListener(this::mountNameDidChange);
savePassword.setDisable(!keychainAccess.isPresent());
Expand Down Expand Up @@ -250,12 +245,10 @@ void setVault(Vault vault, State state) {
}
VaultSettings vaultSettings = vault.getVaultSettings();
unlockAfterStartup.setSelected(savePassword.isSelected() && vaultSettings.unlockAfterStartup().get());
mountAfterUnlock.setSelected(vaultSettings.mountAfterUnlock().get());
revealAfterMount.setSelected(vaultSettings.revealAfterMount().get());
useOwnMountPath.setSelected(vaultSettings.usesIndividualMountPath().get());

vaultSubs = vaultSubs.and(EasyBind.subscribe(unlockAfterStartup.selectedProperty(), vaultSettings.unlockAfterStartup()::set));
vaultSubs = vaultSubs.and(EasyBind.subscribe(mountAfterUnlock.selectedProperty(), vaultSettings.mountAfterUnlock()::set));
vaultSubs = vaultSubs.and(EasyBind.subscribe(revealAfterMount.selectedProperty(), vaultSettings.revealAfterMount()::set));
vaultSubs = vaultSubs.and(EasyBind.subscribe(useOwnMountPath.selectedProperty(), vaultSettings.usesIndividualMountPath()::set));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ public class UnlockedController implements ViewController {
@FXML
private ContextMenu moreOptionsMenu;

@FXML
private MenuItem mountVaultMenuItem;

@FXML
private MenuItem unmountVaultMenuItem;

@FXML
private MenuItem revealVaultMenuItem;

@FXML
private VBox root;

Expand All @@ -103,10 +94,6 @@ public UnlockedController(Localization localization, AsyncTaskService asyncTaskS

@Override
public void initialize() {
mountVaultMenuItem.disableProperty().bind(vaultState.isEqualTo(Vault.State.UNLOCKED).not()); // enable when unlocked
unmountVaultMenuItem.disableProperty().bind(vaultState.isEqualTo(Vault.State.MOUNTED).not()); // enable when mounted
revealVaultMenuItem.disableProperty().bind(vaultState.isEqualTo(Vault.State.MOUNTED).not()); // enable when mounted

EasyBind.subscribe(vault, this::vaultChanged);
EasyBind.subscribe(moreOptionsMenu.showingProperty(), moreOptionsButton::setSelected);
}
Expand All @@ -121,68 +108,23 @@ private void vaultChanged(Vault newVault) {
return;
}

if (newVault.getState() == Vault.State.UNLOCKED && newVault.getVaultSettings().mountAfterUnlock().get()) {
mountVault(newVault);
}

// (re)start throughput statistics:
stopIoSampling();
startIoSampling();
}

@FXML
private void didClickLockVault(ActionEvent event) {
regularUnmountVault(this::lockVault);
regularLockVault(this::lockVaultSucceeded);
}

private void lockVault() {
try {
vault.get().lock();
} catch (ServerLifecycleException | IOException e) {
LOG.error("Lock failed", e);
}
private void lockVaultSucceeded() {
listener.ifPresent(listener -> listener.didLock(this));
}

@FXML
private void didClickMoreOptions(ActionEvent event) {
if (moreOptionsMenu.isShowing()) {
moreOptionsMenu.hide();
} else {
moreOptionsMenu.setAnchorLocation(AnchorLocation.CONTENT_TOP_RIGHT);
moreOptionsMenu.show(moreOptionsButton, Side.BOTTOM, moreOptionsButton.getWidth(), 0.0);
}
}

@FXML
public void didClickMountVault(ActionEvent event) {
mountVault(vault.get());
}

private void mountVault(Vault vault) {
asyncTaskService.asyncTaskOf(() -> {
vault.mount();
}).onSuccess(() -> {
LOG.trace("Mount succeeded.");
messageLabel.setText(null);
if (vault.getVaultSettings().revealAfterMount().get()) {
revealVault(vault);
}
}).onError(CommandFailedException.class, e -> {
LOG.error("Mount failed.", e);
// TODO Markus Kreusch #393: hyperlink auf FAQ oder sowas?
messageLabel.setText(localization.getString("unlocked.label.mountFailed"));
}).run();
}

@FXML
public void didClickUnmountVault(ActionEvent event) {
regularUnmountVault(Runnables.doNothing());
}

private void regularUnmountVault(Runnable onSuccess) {
private void regularLockVault(Runnable onSuccess) {
asyncTaskService.asyncTaskOf(() -> {
vault.get().unmount();
vault.get().lock(false);
}).onSuccess(() -> {
LOG.trace("Regular unmount succeeded.");
onSuccess.run();
Expand All @@ -191,18 +133,6 @@ private void regularUnmountVault(Runnable onSuccess) {
}).run();
}

private void forcedUnmountVault(Runnable onSuccess) {
asyncTaskService.asyncTaskOf(() -> {
vault.get().unmountForced();
}).onSuccess(() -> {
LOG.trace("Forced unmount succeeded.");
onSuccess.run();
}).onError(Exception.class, e -> {
LOG.error("Forced unmount failed.", e);
messageLabel.setText(localization.getString("unlocked.label.unmountFailed"));
}).run();
}

private void onRegularUnmountVaultFailed(Exception e, Runnable onSuccess) {
if (vault.get().supportsForcedUnmount()) {
LOG.trace("Regular unmount failed.", e);
Expand All @@ -214,7 +144,7 @@ private void onRegularUnmountVaultFailed(Exception e, Runnable onSuccess) {

Optional<ButtonType> choice = confirmDialog.showAndWait();
if (ButtonType.YES.equals(choice.get())) {
forcedUnmountVault(onSuccess);
forcedLockVault(onSuccess);
} else {
LOG.trace("Unmount cancelled.", e);
}
Expand All @@ -224,6 +154,28 @@ private void onRegularUnmountVaultFailed(Exception e, Runnable onSuccess) {
}
}

private void forcedLockVault(Runnable onSuccess) {
asyncTaskService.asyncTaskOf(() -> {
vault.get().lock(true);
}).onSuccess(() -> {
LOG.trace("Forced unmount succeeded.");
onSuccess.run();
}).onError(Exception.class, e -> {
LOG.error("Forced unmount failed.", e);
messageLabel.setText(localization.getString("unlocked.label.unmountFailed"));
}).run();
}

@FXML
private void didClickMoreOptions(ActionEvent event) {
if (moreOptionsMenu.isShowing()) {
moreOptionsMenu.hide();
} else {
moreOptionsMenu.setAnchorLocation(AnchorLocation.CONTENT_TOP_RIGHT);
moreOptionsMenu.show(moreOptionsButton, Side.BOTTOM, moreOptionsButton.getWidth(), 0.0);
}
}

@FXML
private void didClickRevealVault(ActionEvent event) {
revealVault(vault.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ private String getStatusIconText(Vault.State state) {
}
switch (state) {
case UNLOCKED:
case MOUNTED:
case MOUNTING:
case UNMOUNTING:
case PROCESSING:
return "\uf09c";
case LOCKED:
default:
Expand All @@ -84,9 +82,7 @@ private Paint getStatusIconColor(Vault.State state, Paint lockedValue) {
}
switch (state) {
case UNLOCKED:
case MOUNTED:
case MOUNTING:
case UNMOUNTING:
case PROCESSING:
return UNLOCKED_ICON_COLOR;
case LOCKED:
default:
Expand Down
16 changes: 2 additions & 14 deletions main/ui/src/main/java/org/cryptomator/ui/model/AutoUnlocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,14 @@ private void unlockSilently(Vault vault) {
}
try {
vault.unlock(CharBuffer.wrap(storedPw));
mountSilently(vault);
} catch (IOException | CryptoException e) {
revealSilently(vault);
} catch (IOException | CryptoException | CommandFailedException e) {
LOG.error("Auto unlock failed.", e);
} finally {
Arrays.fill(storedPw, ' ');
}
}

private void mountSilently(Vault unlockedVault) {
if (!unlockedVault.getVaultSettings().mountAfterUnlock().get()) {
return;
}
try {
unlockedVault.mount();
revealSilently(unlockedVault);
} catch (CommandFailedException e) {
LOG.error("Auto unlock succeded, but mounting the drive failed.", e);
}
}

private void revealSilently(Vault mountedVault) {
if (!mountedVault.getVaultSettings().revealAfterMount().get()) {
return;
Expand Down
Loading

0 comments on commit d53af61

Please sign in to comment.