Pārlūkot izejas kodu

clean code:
* remove unused methods
* combine or move methods

Armin Schrenk 1 gadu atpakaļ
vecāks
revīzija
dfe4b74f3d

+ 0 - 8
src/main/java/org/cryptomator/ui/unlock/UnlockComponent.java

@@ -19,16 +19,8 @@ import java.util.concurrent.Future;
 @Subcomponent(modules = {UnlockModule.class})
 public interface UnlockComponent {
 
-	ExecutorService defaultExecutorService();
-
 	UnlockWorkflow unlockWorkflow();
 
-	default Future<Boolean> startUnlockWorkflow() {
-		UnlockWorkflow workflow = unlockWorkflow();
-		defaultExecutorService().submit(workflow);
-		return workflow;
-	}
-
 	@Subcomponent.Factory
 	interface Factory {
 		UnlockComponent create(@BindsInstance @UnlockWindow Vault vault, @BindsInstance @Named("unlockWindowOwner") @Nullable Stage owner);

+ 21 - 30
src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java

@@ -1,6 +1,5 @@
 package org.cryptomator.ui.unlock;
 
-import com.google.common.base.Throwables;
 import dagger.Lazy;
 import org.cryptomator.common.mount.IllegalMountPointException;
 import org.cryptomator.common.vaults.Vault;
@@ -29,7 +28,7 @@ import java.io.IOException;
  * This class runs the unlock process and controls when to display which UI.
  */
 @UnlockScoped
-public class UnlockWorkflow extends Task<Boolean> {
+public class UnlockWorkflow extends Task<Void> {
 
 	private static final Logger LOG = LoggerFactory.getLogger(UnlockWorkflow.class);
 
@@ -55,41 +54,20 @@ public class UnlockWorkflow extends Task<Boolean> {
 	}
 
 	@Override
-	protected Boolean call() throws InterruptedException, IOException, CryptoException, MountFailedException {
+	protected Void call() throws InterruptedException, IOException, CryptoException, MountFailedException {
 		try {
-			attemptUnlock();
-			return true;
+			keyLoadingStrategy.use(vault::unlock);
+			return null;
 		} catch (UnlockCancelledException e) {
 			cancel(false); // set Tasks state to cancelled
-			return false;
-		}
-	}
-
-	private void attemptUnlock() throws IOException, CryptoException, MountFailedException {
-		try {
-			keyLoadingStrategy.use(vault::unlock);
+			return null;
+		} catch (IOException | RuntimeException | MountFailedException e) {
+			throw e;
 		} catch (Exception e) {
-			Throwables.propagateIfPossible(e, IOException.class);
-			Throwables.propagateIfPossible(e, CryptoException.class);
-			Throwables.propagateIfPossible(e, IllegalMountPointException.class);
-			Throwables.propagateIfPossible(e, MountFailedException.class);
-			throw new IllegalStateException("unexpected exception type", e);
+			throw new IllegalStateException("Unexpected exception type", e);
 		}
 	}
 
-	private void handleIllegalMountPointError(IllegalMountPointException impe) {
-		Platform.runLater(() -> {
-			illegalMountPointException.set(impe);
-			window.setScene(invalidMountPointScene.get());
-			window.show();
-		});
-	}
-
-	private void handleGenericError(Throwable e) {
-		LOG.error("Unlock failed for technical reasons.", e);
-		appWindows.showErrorWindow(e, window, null);
-	}
-
 	@Override
 	protected void succeeded() {
 		LOG.info("Unlock of '{}' succeeded.", vault.getDisplayName());
@@ -121,6 +99,19 @@ public class UnlockWorkflow extends Task<Boolean> {
 		vault.stateProperty().transition(VaultState.Value.PROCESSING, VaultState.Value.LOCKED);
 	}
 
+	private void handleIllegalMountPointError(IllegalMountPointException impe) {
+		Platform.runLater(() -> {
+			illegalMountPointException.set(impe);
+			window.setScene(invalidMountPointScene.get());
+			window.show();
+		});
+	}
+
+	private void handleGenericError(Throwable e) {
+		LOG.error("Unlock failed for technical reasons.", e);
+		appWindows.showErrorWindow(e, window, null);
+	}
+
 	@Override
 	protected void cancelled() {
 		LOG.debug("Unlock of '{}' canceled.", vault.getDisplayName());