Browse Source

refactor structure of LockWorkflow class

Armin Schrenk 4 years ago
parent
commit
19e24ba12c
1 changed files with 10 additions and 20 deletions
  1. 10 20
      main/ui/src/main/java/org/cryptomator/ui/lock/LockWorkflow.java

+ 10 - 20
main/ui/src/main/java/org/cryptomator/ui/lock/LockWorkflow.java

@@ -47,23 +47,22 @@ public class LockWorkflow extends Task<Void> {
 
 	@Override
 	protected Void call() throws Volume.VolumeException, InterruptedException {
-		if (!attemptLock()) {
-			attemptForcedLock();
-		}
-		return null;
-	}
-
-	private boolean attemptLock() {
 		try {
 			vault.lock(false);
-			return true;
 		} catch (Volume.VolumeException e) {
 			LOG.debug("Regular lock of {} failed.", vault.getDisplayName(), e);
-			return false;
+			var decision = askUserForAction();
+			switch (decision) {
+				case FORCE -> vault.lock(true);
+				case CANCEL -> cancel(false);
+				default -> throw new IllegalArgumentException("Unknown decision " + decision);
+			}
 		}
+
+		return null;
 	}
 
-	private boolean attemptForcedLock() throws Volume.VolumeException, InterruptedException {
+	private LockModule.ForceLockDecision askUserForAction() throws InterruptedException {
 		// show forcedLock dialogue ...
 		Platform.runLater(() -> {
 			lockWindow.setScene(lockForcedScene.get());
@@ -77,16 +76,7 @@ public class LockWorkflow extends Task<Void> {
 			}
 		});
 		// ... and wait for answer
-		switch (forceLockDecisionLock.awaitInteraction()) {
-			case FORCE:
-				vault.lock(true);
-				return true;
-			case CANCEL:
-				cancel(false);
-				return false;
-			default:
-				return false;
-		}
+		return forceLockDecisionLock.awaitInteraction();
 	}
 
 	@Override