From dfe4b74f3d13202fef3e4778bef36fed2fc555c3 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 7 Dec 2023 17:48:58 +0100 Subject: [PATCH] clean code: * remove unused methods * combine or move methods --- .../ui/unlock/UnlockComponent.java | 8 --- .../cryptomator/ui/unlock/UnlockWorkflow.java | 53 ++++++++----------- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockComponent.java b/src/main/java/org/cryptomator/ui/unlock/UnlockComponent.java index 67e905200..825d0fc2d 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockComponent.java +++ b/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 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); diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index 564d57ab6..0d2183d23 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/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 { +public class UnlockWorkflow extends Task { private static final Logger LOG = LoggerFactory.getLogger(UnlockWorkflow.class); @@ -55,41 +54,20 @@ public class UnlockWorkflow extends Task { } @Override - protected Boolean call() throws InterruptedException, IOException, CryptoException, MountFailedException { - try { - attemptUnlock(); - return true; - } catch (UnlockCancelledException e) { - cancel(false); // set Tasks state to cancelled - return false; - } - } - - private void attemptUnlock() throws IOException, CryptoException, MountFailedException { + protected Void call() throws InterruptedException, IOException, CryptoException, MountFailedException { try { keyLoadingStrategy.use(vault::unlock); + return null; + } catch (UnlockCancelledException e) { + cancel(false); // set Tasks state to cancelled + 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 { 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());