mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-19 11:11:28 +00:00
fixed switching to unlock view after initializing vault
This commit is contained in:
@@ -10,6 +10,7 @@ package org.cryptomator.ui.controllers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -35,7 +36,7 @@ public class ChangePasswordController extends AbstractFXMLViewController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChangePasswordController.class);
|
||||
|
||||
private ChangePasswordListener listener;
|
||||
private Optional<ChangePasswordListener> listener = Optional.empty();
|
||||
private Vault vault;
|
||||
|
||||
@FXML
|
||||
@@ -111,7 +112,7 @@ public class ChangePasswordController extends AbstractFXMLViewController {
|
||||
try {
|
||||
vault.changePassphrase(oldPasswordField.getCharacters(), newPasswordField.getCharacters());
|
||||
messageText.setText(resourceBundle.getString("changePassword.infoMessage.success"));
|
||||
Platform.runLater(this::didChangePassword);
|
||||
listener.ifPresent(this::invokeListenerLater);
|
||||
} catch (InvalidPassphraseException e) {
|
||||
messageText.setText(resourceBundle.getString("changePassword.errorMessage.wrongPassword"));
|
||||
newPasswordField.swipe();
|
||||
@@ -141,12 +142,6 @@ public class ChangePasswordController extends AbstractFXMLViewController {
|
||||
}
|
||||
}
|
||||
|
||||
private void didChangePassword() {
|
||||
if (listener != null) {
|
||||
listener.didChangePassword(this);
|
||||
}
|
||||
}
|
||||
|
||||
/* Getter/Setter */
|
||||
|
||||
public Vault getVault() {
|
||||
@@ -158,15 +153,22 @@ public class ChangePasswordController extends AbstractFXMLViewController {
|
||||
}
|
||||
|
||||
public ChangePasswordListener getListener() {
|
||||
return listener;
|
||||
return listener.orElse(null);
|
||||
}
|
||||
|
||||
public void setListener(ChangePasswordListener listener) {
|
||||
this.listener = listener;
|
||||
this.listener = Optional.ofNullable(listener);
|
||||
}
|
||||
|
||||
/* callback */
|
||||
|
||||
private void invokeListenerLater(ChangePasswordListener listener) {
|
||||
Platform.runLater(() -> {
|
||||
listener.didChangePassword(this);
|
||||
});
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface ChangePasswordListener {
|
||||
void didChangePassword(ChangePasswordController ctrl);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ package org.cryptomator.ui.controllers;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -21,6 +22,7 @@ import org.cryptomator.ui.model.Vault;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
@@ -33,7 +35,7 @@ public class InitializeController extends AbstractFXMLViewController {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InitializeController.class);
|
||||
|
||||
private Vault vault;
|
||||
private InitializationListener listener;
|
||||
private Optional<InitializationListener> listener = Optional.empty();
|
||||
|
||||
@FXML
|
||||
private SecPasswordField passwordField;
|
||||
@@ -87,6 +89,7 @@ public class InitializeController extends AbstractFXMLViewController {
|
||||
final CharSequence passphrase = passwordField.getCharacters();
|
||||
try {
|
||||
vault.create(passphrase);
|
||||
listener.ifPresent(this::invokeListenerLater);
|
||||
} catch (FileAlreadyExistsException ex) {
|
||||
messageLabel.setText(resourceBundle.getString("initialize.messageLabel.alreadyInitialized"));
|
||||
} catch (IOException ex) {
|
||||
@@ -115,15 +118,22 @@ public class InitializeController extends AbstractFXMLViewController {
|
||||
}
|
||||
|
||||
public InitializationListener getListener() {
|
||||
return listener;
|
||||
return listener.orElse(null);
|
||||
}
|
||||
|
||||
public void setListener(InitializationListener listener) {
|
||||
this.listener = listener;
|
||||
this.listener = Optional.ofNullable(listener);
|
||||
}
|
||||
|
||||
/* callback */
|
||||
|
||||
private void invokeListenerLater(InitializationListener listener) {
|
||||
Platform.runLater(() -> {
|
||||
listener.didInitialize(this);
|
||||
});
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface InitializationListener {
|
||||
void didInitialize(InitializeController ctrl);
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.cryptomator.ui.controllers.ChangePasswordController.ChangePasswordListener;
|
||||
import org.cryptomator.ui.controllers.InitializeController.InitializationListener;
|
||||
import org.cryptomator.ui.controllers.UnlockController.UnlockListener;
|
||||
import org.cryptomator.ui.controllers.UnlockedController.LockListener;
|
||||
import org.cryptomator.ui.controls.DirectoryListCell;
|
||||
import org.cryptomator.ui.model.Vault;
|
||||
import org.cryptomator.ui.model.VaultFactory;
|
||||
@@ -53,7 +49,7 @@ import javafx.stage.Stage;
|
||||
import javafx.stage.WindowEvent;
|
||||
|
||||
@Singleton
|
||||
public class MainController extends AbstractFXMLViewController implements InitializationListener, UnlockListener, LockListener, ChangePasswordListener {
|
||||
public class MainController extends AbstractFXMLViewController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MainController.class);
|
||||
|
||||
@@ -273,10 +269,9 @@ public class MainController extends AbstractFXMLViewController implements Initia
|
||||
contentPane.getChildren().clear();
|
||||
contentPane.getChildren().add(root);
|
||||
ctrl.setVault(vault);
|
||||
ctrl.setListener(this);
|
||||
ctrl.setListener(this::didInitialize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didInitialize(InitializeController ctrl) {
|
||||
showUnlockView(ctrl.getVault());
|
||||
}
|
||||
@@ -287,10 +282,9 @@ public class MainController extends AbstractFXMLViewController implements Initia
|
||||
contentPane.getChildren().clear();
|
||||
contentPane.getChildren().add(root);
|
||||
ctrl.setVault(vault);
|
||||
ctrl.setListener(this);
|
||||
ctrl.setListener(this::didUnlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didUnlock(UnlockController ctrl) {
|
||||
showUnlockedView(ctrl.getVault());
|
||||
Platform.setImplicitExit(false);
|
||||
@@ -302,10 +296,9 @@ public class MainController extends AbstractFXMLViewController implements Initia
|
||||
contentPane.getChildren().clear();
|
||||
contentPane.getChildren().add(root);
|
||||
ctrl.setVault(vault);
|
||||
ctrl.setListener(this);
|
||||
ctrl.setListener(this::didLock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didLock(UnlockedController ctrl) {
|
||||
showUnlockView(ctrl.getVault());
|
||||
if (getUnlockedVaults().isEmpty()) {
|
||||
@@ -319,10 +312,9 @@ public class MainController extends AbstractFXMLViewController implements Initia
|
||||
contentPane.getChildren().clear();
|
||||
contentPane.getChildren().add(root);
|
||||
ctrl.setVault(vault);
|
||||
ctrl.setListener(this);
|
||||
ctrl.setListener(this::didChangePassword);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didChangePassword(ChangePasswordController ctrl) {
|
||||
showUnlockView(ctrl.getVault());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.cryptomator.ui.controllers;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Comparator;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -49,7 +50,7 @@ public class UnlockController extends AbstractFXMLViewController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UnlockController.class);
|
||||
|
||||
private UnlockListener listener;
|
||||
private Optional<UnlockListener> listener = Optional.empty();
|
||||
private Vault vault;
|
||||
|
||||
@FXML
|
||||
@@ -300,8 +301,8 @@ public class UnlockController extends AbstractFXMLViewController {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (mountSuccess && listener != null) {
|
||||
listener.didUnlock(this);
|
||||
if (mountSuccess) {
|
||||
listener.ifPresent(this::invokeListenerLater);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,15 +337,22 @@ public class UnlockController extends AbstractFXMLViewController {
|
||||
}
|
||||
|
||||
public UnlockListener getListener() {
|
||||
return listener;
|
||||
return listener.orElse(null);
|
||||
}
|
||||
|
||||
public void setListener(UnlockListener listener) {
|
||||
this.listener = listener;
|
||||
this.listener = Optional.ofNullable(listener);
|
||||
}
|
||||
|
||||
/* callback */
|
||||
|
||||
private void invokeListenerLater(UnlockListener listener) {
|
||||
Platform.runLater(() -> {
|
||||
listener.didUnlock(this);
|
||||
});
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface UnlockListener {
|
||||
void didUnlock(UnlockController ctrl);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.cryptomator.ui.controllers;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
@@ -39,7 +40,7 @@ public class UnlockedController extends AbstractFXMLViewController {
|
||||
|
||||
private static final int IO_SAMPLING_STEPS = 100;
|
||||
private static final double IO_SAMPLING_INTERVAL = 0.25;
|
||||
private LockListener listener;
|
||||
private Optional<LockListener> listener = Optional.empty();
|
||||
private Vault vault;
|
||||
private Timeline ioAnimation;
|
||||
|
||||
@@ -103,11 +104,7 @@ public class UnlockedController extends AbstractFXMLViewController {
|
||||
return;
|
||||
}
|
||||
vault.deactivateFrontend();
|
||||
if (listener != null) {
|
||||
Platform.runLater(() -> {
|
||||
listener.didLock(this);
|
||||
});
|
||||
}
|
||||
listener.ifPresent(this::invokeListenerLater);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -217,15 +214,22 @@ public class UnlockedController extends AbstractFXMLViewController {
|
||||
}
|
||||
|
||||
public LockListener getListener() {
|
||||
return listener;
|
||||
return listener.orElse(null);
|
||||
}
|
||||
|
||||
public void setListener(LockListener listener) {
|
||||
this.listener = listener;
|
||||
this.listener = Optional.ofNullable(listener);
|
||||
}
|
||||
|
||||
/* callback */
|
||||
|
||||
private void invokeListenerLater(LockListener listener) {
|
||||
Platform.runLater(() -> {
|
||||
listener.didLock(this);
|
||||
});
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface LockListener {
|
||||
void didLock(UnlockedController ctrl);
|
||||
}
|
||||
|
||||
@@ -88,10 +88,9 @@ public class Vault implements Serializable, CryptoFileSystemDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* Commands
|
||||
********************************************************************************/
|
||||
// ******************************************************************************
|
||||
// Commands
|
||||
// ********************************************************************************/
|
||||
|
||||
public void create(CharSequence passphrase) throws IOException {
|
||||
try {
|
||||
@@ -162,10 +161,9 @@ public class Vault implements Serializable, CryptoFileSystemDelegate {
|
||||
Optionals.ifPresent(filesystemFrontend.get(), Frontend::unmount);
|
||||
}
|
||||
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* Delegate methods
|
||||
********************************************************************************/
|
||||
// ******************************************************************************
|
||||
// Delegate methods
|
||||
// ********************************************************************************/
|
||||
|
||||
@Override
|
||||
public void authenticationFailed(String cleartextPath) {
|
||||
@@ -177,10 +175,9 @@ public class Vault implements Serializable, CryptoFileSystemDelegate {
|
||||
return namesOfResourcesWithInvalidMac.contains(cleartextPath);
|
||||
}
|
||||
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* Getter/Setter
|
||||
********************************************************************************/
|
||||
// ******************************************************************************
|
||||
// Getter/Setter
|
||||
// *******************************************************************************/
|
||||
|
||||
public Path getPath() {
|
||||
return path;
|
||||
@@ -278,10 +275,9 @@ public class Vault implements Serializable, CryptoFileSystemDelegate {
|
||||
this.winDriveLetter = winDriveLetter;
|
||||
}
|
||||
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* Hashcode / Equals
|
||||
********************************************************************************/
|
||||
// ******************************************************************************
|
||||
// Hashcode / Equals
|
||||
// *******************************************************************************/
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
Reference in New Issue
Block a user