From 253abd493036ef940ced24942f2c84fd64695972 Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Thu, 22 Oct 2020 18:32:15 +0200 Subject: [PATCH 1/7] Refactored UnlockWorkflow Replaced protected state methods (scheduled, etc.) with lambdas in the constructor Replaced try-multi-catch with if-instanceof in onFailed-lambda --- .../cryptomator/ui/unlock/UnlockWorkflow.java | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index c339cb344..4db0836a4 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java @@ -73,6 +73,20 @@ public class UnlockWorkflow extends Task { this.successScene = successScene; this.invalidMountPointScene = invalidMountPointScene; this.errorComponent = errorComponent; + + setOnScheduled(event -> vault.setState(VaultState.PROCESSING)); + setOnSucceeded(event -> vault.setState(VaultState.UNLOCKED)); + setOnCancelled(event -> vault.setState(VaultState.LOCKED)); + + setOnFailed(event -> { + vault.setState(VaultState.LOCKED); + Throwable throwable = event.getSource().getException(); + if (throwable instanceof InvalidMountPointException) { + handleInvalidMountPoint((InvalidMountPointException) throwable); + } else { + handleGenericError(throwable); + } + }); } @Override @@ -85,12 +99,6 @@ public class UnlockWorkflow extends Task { cancel(false); // set Tasks state to cancelled return false; } - } catch (InvalidMountPointException e) { - handleInvalidMountPoint(e); - throw e; // rethrow to trigger correct exception handling in Task - } catch (Exception e) { - handleGenericError(e); - throw e; // rethrow to trigger correct exception handling in Task } finally { wipePassword(password.get()); wipePassword(savedPassword.orElse(null)); @@ -216,25 +224,4 @@ public class UnlockWorkflow extends Task { Arrays.fill(pw, ' '); } } - - @Override - protected void scheduled() { - vault.setState(VaultState.PROCESSING); - } - - @Override - protected void succeeded() { - vault.setState(VaultState.UNLOCKED); - } - - @Override - protected void failed() { - vault.setState(VaultState.LOCKED); - } - - @Override - protected void cancelled() { - vault.setState(VaultState.LOCKED); - } - } From 9c22adc97d63f0ffce15b2f594400dbd2ab25a0d Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Mon, 26 Oct 2020 21:15:37 +0100 Subject: [PATCH 2/7] Added/Fixed error logging Added error logging to VaultStats and GeneralPreferencesController Fixed possible missing error logging in VaultService --- .../main/java/org/cryptomator/common/vaults/VaultStats.java | 1 + .../main/java/org/cryptomator/ui/common/VaultService.java | 3 ++- .../ui/preferences/GeneralPreferencesController.java | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/VaultStats.java b/main/commons/src/main/java/org/cryptomator/common/vaults/VaultStats.java index 69564b876..2da8fa288 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/VaultStats.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/VaultStats.java @@ -36,6 +36,7 @@ public class VaultStats { this.updateService = new UpdateStatsService(); updateService.setExecutor(executor); updateService.setPeriod(Duration.seconds(1)); + updateService.setOnFailed(event -> LOG.error("Error in UpdateStateService.", event.getSource().getException())); state.addListener(this::vaultStateChanged); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java b/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java index 8aadd8c98..da9f58ecb 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java @@ -69,7 +69,6 @@ public class VaultService { public Task createLockTask(Vault vault, boolean forced) { Task task = new LockVaultTask(vault, forced); task.setOnSucceeded(evt -> LOG.info("Locked {}", vault.getDisplayName())); - task.setOnFailed(evt -> LOG.error("Failed to lock " + vault.getDisplayName(), evt.getSource().getException())); return task; } @@ -165,6 +164,8 @@ public class VaultService { public LockVaultTask(Vault vault, boolean forced) { this.vault = vault; this.forced = forced; + + setOnFailed(event -> LOG.error("Failed to lock " + vault.getDisplayName(), event.getSource().getException())); } @Override diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java index fdec00d62..926749dfa 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java @@ -109,7 +109,10 @@ public class GeneralPreferencesController implements FxController { autoStartStrategy.ifPresent(autoStart -> { boolean enableAutoStart = autoStartCheckbox.isSelected(); Task toggleTask = new ToggleAutoStartTask(autoStart, enableAutoStart); - toggleTask.setOnFailed(evt -> autoStartCheckbox.setSelected(!enableAutoStart)); // restore previous state + toggleTask.setOnFailed(event -> { + autoStartCheckbox.setSelected(!enableAutoStart); // restore previous state + LOG.error("Failed to toggle autostart.", event.getSource().getException()); + }); executor.execute(toggleTask); }); } From eb8f5f523d7762ee75ce3288ec027b40de4cc69f Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Mon, 26 Oct 2020 21:19:24 +0100 Subject: [PATCH 3/7] Added UI error messages Added UI error message to GeneralPreferencesController for ToggleAutoStartTask Added UI error message to RecoveryKeyCreationController --- .../preferences/GeneralPreferencesController.java | 15 ++++++++++++++- .../RecoveryKeyCreationController.java | 8 +++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java index 926749dfa..678a740c9 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java @@ -1,5 +1,6 @@ package org.cryptomator.ui.preferences; +import dagger.Lazy; import javafx.application.Application; import javafx.application.Platform; import javafx.beans.property.ObjectProperty; @@ -7,17 +8,22 @@ import javafx.beans.value.ObservableValue; import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.geometry.NodeOrientation; +import javafx.scene.Scene; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; import javafx.scene.control.RadioButton; import javafx.scene.control.Toggle; import javafx.scene.control.ToggleGroup; +import javafx.stage.Stage; import javafx.util.StringConverter; import org.cryptomator.common.Environment; import org.cryptomator.common.LicenseHolder; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.UiTheme; +import org.cryptomator.ui.common.ErrorComponent; import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,6 +38,7 @@ public class GeneralPreferencesController implements FxController { private static final Logger LOG = LoggerFactory.getLogger(GeneralPreferencesController.class); + private final Stage window; private final Settings settings; private final boolean trayMenuSupported; private final Optional autoStartStrategy; @@ -41,6 +48,8 @@ public class GeneralPreferencesController implements FxController { private final ResourceBundle resourceBundle; private final Application application; private final Environment environment; + private final Lazy preferencesScene; + private final ErrorComponent.Builder errorComponent; public ChoiceBox themeChoiceBox; public CheckBox startHiddenCheckbox; public CheckBox debugModeCheckbox; @@ -50,7 +59,8 @@ public class GeneralPreferencesController implements FxController { public RadioButton nodeOrientationRtl; @Inject - GeneralPreferencesController(Settings settings, @Named("trayMenuSupported") boolean trayMenuSupported, Optional autoStartStrategy, ObjectProperty selectedTabProperty, LicenseHolder licenseHolder, ExecutorService executor, ResourceBundle resourceBundle, Application application, Environment environment) { + GeneralPreferencesController(@PreferencesWindow Stage window, Settings settings, @Named("trayMenuSupported") boolean trayMenuSupported, Optional autoStartStrategy, ObjectProperty selectedTabProperty, LicenseHolder licenseHolder, ExecutorService executor, ResourceBundle resourceBundle, Application application, Environment environment, @FxmlScene(FxmlFile.PREFERENCES) Lazy preferencesScene, ErrorComponent.Builder errorComponent) { + this.window = window; this.settings = settings; this.trayMenuSupported = trayMenuSupported; this.autoStartStrategy = autoStartStrategy; @@ -60,6 +70,8 @@ public class GeneralPreferencesController implements FxController { this.resourceBundle = resourceBundle; this.application = application; this.environment = environment; + this.preferencesScene = preferencesScene; + this.errorComponent = errorComponent; } @FXML @@ -112,6 +124,7 @@ public class GeneralPreferencesController implements FxController { toggleTask.setOnFailed(event -> { autoStartCheckbox.setSelected(!enableAutoStart); // restore previous state LOG.error("Failed to toggle autostart.", event.getSource().getException()); + errorComponent.cause(event.getSource().getException()).window(window).returnToScene(preferencesScene.get()).build().showErrorScene(); }); executor.execute(toggleTask); }); diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java index 6bb6a9f80..b0d622efa 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java @@ -9,6 +9,7 @@ import javafx.stage.Stage; import org.cryptomator.common.vaults.Vault; import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.ui.common.Animations; +import org.cryptomator.ui.common.ErrorComponent; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; @@ -31,16 +32,20 @@ public class RecoveryKeyCreationController implements FxController { private final ExecutorService executor; private final RecoveryKeyFactory recoveryKeyFactory; private final StringProperty recoveryKeyProperty; + private final Lazy createScene; + private final ErrorComponent.Builder errorComponent; public NiceSecurePasswordField passwordField; @Inject - public RecoveryKeyCreationController(@RecoveryKeyWindow Stage window, @FxmlScene(FxmlFile.RECOVERYKEY_SUCCESS) Lazy successScene, @RecoveryKeyWindow Vault vault, RecoveryKeyFactory recoveryKeyFactory, ExecutorService executor, @RecoveryKeyWindow StringProperty recoveryKey) { + public RecoveryKeyCreationController(@RecoveryKeyWindow Stage window, @FxmlScene(FxmlFile.RECOVERYKEY_SUCCESS) Lazy successScene, @RecoveryKeyWindow Vault vault, RecoveryKeyFactory recoveryKeyFactory, ExecutorService executor, @RecoveryKeyWindow StringProperty recoveryKey, @FxmlScene(FxmlFile.RECOVERYKEY_CREATE) Lazy createScene, ErrorComponent.Builder errorComponent) { this.window = window; this.successScene = successScene; this.vault = vault; this.executor = executor; this.recoveryKeyFactory = recoveryKeyFactory; this.recoveryKeyProperty = recoveryKey; + this.createScene = createScene; + this.errorComponent = errorComponent; } @FXML @@ -59,6 +64,7 @@ public class RecoveryKeyCreationController implements FxController { Animations.createShakeWindowAnimation(window).play(); } else { LOG.error("Creation of recovery key failed.", task.getException()); + errorComponent.cause(task.getException()).window(window).returnToScene(createScene.get()).build().showErrorScene(); } }); executor.submit(task); From d331c3022489c7d0651a588e0c58f877064d55a8 Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Wed, 28 Oct 2020 15:21:59 +0100 Subject: [PATCH 4/7] Revert "Added UI error messages" This reverts commit eb8f5f523d7762ee75ce3288ec027b40de4cc69f. --- .../preferences/GeneralPreferencesController.java | 15 +-------------- .../RecoveryKeyCreationController.java | 8 +------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java index 678a740c9..926749dfa 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java @@ -1,6 +1,5 @@ package org.cryptomator.ui.preferences; -import dagger.Lazy; import javafx.application.Application; import javafx.application.Platform; import javafx.beans.property.ObjectProperty; @@ -8,22 +7,17 @@ import javafx.beans.value.ObservableValue; import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.geometry.NodeOrientation; -import javafx.scene.Scene; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; import javafx.scene.control.RadioButton; import javafx.scene.control.Toggle; import javafx.scene.control.ToggleGroup; -import javafx.stage.Stage; import javafx.util.StringConverter; import org.cryptomator.common.Environment; import org.cryptomator.common.LicenseHolder; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.UiTheme; -import org.cryptomator.ui.common.ErrorComponent; import org.cryptomator.ui.common.FxController; -import org.cryptomator.ui.common.FxmlFile; -import org.cryptomator.ui.common.FxmlScene; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +32,6 @@ public class GeneralPreferencesController implements FxController { private static final Logger LOG = LoggerFactory.getLogger(GeneralPreferencesController.class); - private final Stage window; private final Settings settings; private final boolean trayMenuSupported; private final Optional autoStartStrategy; @@ -48,8 +41,6 @@ public class GeneralPreferencesController implements FxController { private final ResourceBundle resourceBundle; private final Application application; private final Environment environment; - private final Lazy preferencesScene; - private final ErrorComponent.Builder errorComponent; public ChoiceBox themeChoiceBox; public CheckBox startHiddenCheckbox; public CheckBox debugModeCheckbox; @@ -59,8 +50,7 @@ public class GeneralPreferencesController implements FxController { public RadioButton nodeOrientationRtl; @Inject - GeneralPreferencesController(@PreferencesWindow Stage window, Settings settings, @Named("trayMenuSupported") boolean trayMenuSupported, Optional autoStartStrategy, ObjectProperty selectedTabProperty, LicenseHolder licenseHolder, ExecutorService executor, ResourceBundle resourceBundle, Application application, Environment environment, @FxmlScene(FxmlFile.PREFERENCES) Lazy preferencesScene, ErrorComponent.Builder errorComponent) { - this.window = window; + GeneralPreferencesController(Settings settings, @Named("trayMenuSupported") boolean trayMenuSupported, Optional autoStartStrategy, ObjectProperty selectedTabProperty, LicenseHolder licenseHolder, ExecutorService executor, ResourceBundle resourceBundle, Application application, Environment environment) { this.settings = settings; this.trayMenuSupported = trayMenuSupported; this.autoStartStrategy = autoStartStrategy; @@ -70,8 +60,6 @@ public class GeneralPreferencesController implements FxController { this.resourceBundle = resourceBundle; this.application = application; this.environment = environment; - this.preferencesScene = preferencesScene; - this.errorComponent = errorComponent; } @FXML @@ -124,7 +112,6 @@ public class GeneralPreferencesController implements FxController { toggleTask.setOnFailed(event -> { autoStartCheckbox.setSelected(!enableAutoStart); // restore previous state LOG.error("Failed to toggle autostart.", event.getSource().getException()); - errorComponent.cause(event.getSource().getException()).window(window).returnToScene(preferencesScene.get()).build().showErrorScene(); }); executor.execute(toggleTask); }); diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java index b0d622efa..6bb6a9f80 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java @@ -9,7 +9,6 @@ import javafx.stage.Stage; import org.cryptomator.common.vaults.Vault; import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.ui.common.Animations; -import org.cryptomator.ui.common.ErrorComponent; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; @@ -32,20 +31,16 @@ public class RecoveryKeyCreationController implements FxController { private final ExecutorService executor; private final RecoveryKeyFactory recoveryKeyFactory; private final StringProperty recoveryKeyProperty; - private final Lazy createScene; - private final ErrorComponent.Builder errorComponent; public NiceSecurePasswordField passwordField; @Inject - public RecoveryKeyCreationController(@RecoveryKeyWindow Stage window, @FxmlScene(FxmlFile.RECOVERYKEY_SUCCESS) Lazy successScene, @RecoveryKeyWindow Vault vault, RecoveryKeyFactory recoveryKeyFactory, ExecutorService executor, @RecoveryKeyWindow StringProperty recoveryKey, @FxmlScene(FxmlFile.RECOVERYKEY_CREATE) Lazy createScene, ErrorComponent.Builder errorComponent) { + public RecoveryKeyCreationController(@RecoveryKeyWindow Stage window, @FxmlScene(FxmlFile.RECOVERYKEY_SUCCESS) Lazy successScene, @RecoveryKeyWindow Vault vault, RecoveryKeyFactory recoveryKeyFactory, ExecutorService executor, @RecoveryKeyWindow StringProperty recoveryKey) { this.window = window; this.successScene = successScene; this.vault = vault; this.executor = executor; this.recoveryKeyFactory = recoveryKeyFactory; this.recoveryKeyProperty = recoveryKey; - this.createScene = createScene; - this.errorComponent = errorComponent; } @FXML @@ -64,7 +59,6 @@ public class RecoveryKeyCreationController implements FxController { Animations.createShakeWindowAnimation(window).play(); } else { LOG.error("Creation of recovery key failed.", task.getException()); - errorComponent.cause(task.getException()).window(window).returnToScene(createScene.get()).build().showErrorScene(); } }); executor.submit(task); From f0e1bcb899e9b488ee271f5e3c4419c87a3e5896 Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Wed, 28 Oct 2020 15:40:59 +0100 Subject: [PATCH 5/7] Moved call to #setOnFailed() to UpdateStatsService implementation --- .../main/java/org/cryptomator/common/vaults/VaultStats.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/VaultStats.java b/main/commons/src/main/java/org/cryptomator/common/vaults/VaultStats.java index 2da8fa288..c23682008 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/VaultStats.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/VaultStats.java @@ -36,7 +36,6 @@ public class VaultStats { this.updateService = new UpdateStatsService(); updateService.setExecutor(executor); updateService.setPeriod(Duration.seconds(1)); - updateService.setOnFailed(event -> LOG.error("Error in UpdateStateService.", event.getSource().getException())); state.addListener(this::vaultStateChanged); } @@ -60,6 +59,10 @@ public class VaultStats { private class UpdateStatsService extends ScheduledService> { + private UpdateStatsService() { + setOnFailed(event -> LOG.error("Error in UpdateStateService.", getException())); + } + @Override protected Task> createTask() { return new Task<>() { From 0acc8ddb0a667930a98caacac4ecac8426a83c53 Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Wed, 28 Oct 2020 15:48:20 +0100 Subject: [PATCH 6/7] Fixed UnlockWorkflow Partly reverted 253abd493036ef940ced24942f2c84fd64695972 --- .../cryptomator/ui/unlock/UnlockWorkflow.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index 4db0836a4..12633452a 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java @@ -74,12 +74,7 @@ public class UnlockWorkflow extends Task { this.invalidMountPointScene = invalidMountPointScene; this.errorComponent = errorComponent; - setOnScheduled(event -> vault.setState(VaultState.PROCESSING)); - setOnSucceeded(event -> vault.setState(VaultState.UNLOCKED)); - setOnCancelled(event -> vault.setState(VaultState.LOCKED)); - setOnFailed(event -> { - vault.setState(VaultState.LOCKED); Throwable throwable = event.getSource().getException(); if (throwable instanceof InvalidMountPointException) { handleInvalidMountPoint((InvalidMountPointException) throwable); @@ -224,4 +219,25 @@ public class UnlockWorkflow extends Task { Arrays.fill(pw, ' '); } } + + @Override + protected void scheduled() { + vault.setState(VaultState.PROCESSING); + } + + @Override + protected void succeeded() { + vault.setState(VaultState.UNLOCKED); + } + + @Override + protected void failed() { + vault.setState(VaultState.LOCKED); + } + + @Override + protected void cancelled() { + vault.setState(VaultState.LOCKED); + } + } From 551d9d1af1e01c81596fd240769179295a1e03c3 Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Wed, 28 Oct 2020 16:21:14 +0100 Subject: [PATCH 7/7] Added default Errorhandler to all Tasks and Services --- main/ui/src/main/java/org/cryptomator/ui/common/Tasks.java | 2 ++ .../main/java/org/cryptomator/ui/common/VaultService.java | 4 ++++ .../java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java | 5 +++++ .../java/org/cryptomator/ui/fxapp/UpdateCheckerTask.java | 6 ++++++ .../ui/preferences/GeneralPreferencesController.java | 2 ++ .../ui/recoverykey/RecoveryKeyCreationController.java | 4 ++++ .../ui/recoverykey/RecoveryKeyResetPasswordController.java | 4 ++++ 7 files changed, 27 insertions(+) diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/Tasks.java b/main/ui/src/main/java/org/cryptomator/ui/common/Tasks.java index ab0a80d47..164ee41e3 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/Tasks.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/Tasks.java @@ -174,6 +174,8 @@ public class Tasks { RestartingService(Supplier> taskFactory) { this.taskFactory = taskFactory; + + setOnFailed(event -> LOG.error("Failed to execute service", getException())); } @Override diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java b/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java index da9f58ecb..a6b7dc425 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java @@ -108,6 +108,8 @@ public class VaultService { */ public RevealVaultTask(Vault vault) { this.vault = vault; + + setOnFailed(evt -> LOG.error("Failed to reveal " + vault.getDisplayName(), getException())); } @Override @@ -126,6 +128,8 @@ public class VaultService { public WaitForTasksTask(Collection> tasks) { this.startedTasks = List.copyOf(tasks); + + setOnFailed(event -> LOG.error("Failed to lock multiple vaults", getException())); } @Override diff --git a/main/ui/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java b/main/ui/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java index 7784bd89e..a15b81044 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java @@ -11,6 +11,8 @@ import javafx.concurrent.Task; import javafx.util.Duration; import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.settings.Settings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Named; import java.net.URI; @@ -22,6 +24,8 @@ import java.util.concurrent.ExecutorService; @Module public abstract class UpdateCheckerModule { + private static final Logger LOG = LoggerFactory.getLogger(UpdateCheckerModule.class); + private static final URI LATEST_VERSION_URI = URI.create("https://api.cryptomator.org/updates/latestVersion.json"); private static final Duration UPDATE_CHECK_INTERVAL = Duration.hours(3); private static final Duration DISABLED_UPDATE_CHECK_INTERVAL = Duration.hours(100000); // Duration.INDEFINITE leads to overflows... @@ -69,6 +73,7 @@ public abstract class UpdateCheckerModule { return new UpdateCheckerTask(httpClient, checkForUpdatesRequest); } }; + service.setOnFailed(event -> LOG.error("Failed to execute update service", service.getException())); service.setExecutor(executor); service.periodProperty().bind(period); return service; diff --git a/main/ui/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerTask.java b/main/ui/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerTask.java index 4d077a24c..8fec56b64 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerTask.java +++ b/main/ui/src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerTask.java @@ -6,6 +6,8 @@ import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import javafx.concurrent.Task; import org.apache.commons.lang3.SystemUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; @@ -19,6 +21,8 @@ import java.util.Map; public class UpdateCheckerTask extends Task { + private static final Logger LOG = LoggerFactory.getLogger(UpdateCheckerTask.class); + private static final long MAX_RESPONSE_SIZE = 10 * 1024; // 10kb should be sufficient. protect against flooding private static final Gson GSON = new GsonBuilder().setLenient().create(); @@ -28,6 +32,8 @@ public class UpdateCheckerTask extends Task { UpdateCheckerTask(HttpClient httpClient, HttpRequest checkForUpdatesRequest) { this.httpClient = httpClient; this.checkForUpdatesRequest = checkForUpdatesRequest; + + setOnFailed(event -> LOG.error("Failed to check for updates", getException())); } @Override diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java index 926749dfa..3cf94d22e 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java @@ -161,6 +161,8 @@ public class GeneralPreferencesController implements FxController { public ToggleAutoStartTask(AutoStartStrategy autoStart, boolean enable) { this.autoStart = autoStart; this.enable = enable; + + setOnFailed(event -> LOG.error("Failed to toggle Autostart", getException())); } @Override diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java index 6bb6a9f80..f5b002cbf 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java @@ -71,6 +71,10 @@ public class RecoveryKeyCreationController implements FxController { private class RecoveryKeyCreationTask extends Task { + private RecoveryKeyCreationTask() { + setOnFailed(event -> LOG.error("Failed to create recovery key", getException())); + } + @Override protected String call() throws IOException { return recoveryKeyFactory.createRecoveryKey(vault.getPath(), passwordField.getCharacters()); diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java index 87d916492..8f626a652 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java @@ -77,6 +77,10 @@ public class RecoveryKeyResetPasswordController implements FxController { private class ResetPasswordTask extends Task { + private ResetPasswordTask() { + setOnFailed(event -> LOG.error("Failed to reset password", getException())); + } + @Override protected Void call() throws IOException, IllegalArgumentException { recoveryKeyFactory.resetPasswordWithRecoveryKey(vault.getPath(), recoveryKey.get(), newPassword.get());