From 343794c1fee7a657a2b11c7c54ca5bfb93fd64f0 Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Thu, 5 Nov 2020 17:03:35 +0100 Subject: [PATCH] Redo "Added UI error messages" This reverts commit d331c302 --- .../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 208605f51..4e551afce 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,12 +1,16 @@ package org.cryptomator.ui.preferences; +import dagger.Lazy; import org.cryptomator.common.Environment; import org.cryptomator.common.LicenseHolder; import org.cryptomator.common.settings.KeychainBackend; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.UiTheme; import org.cryptomator.integrations.keychain.KeychainAccessProvider; +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; @@ -19,11 +23,13 @@ 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 java.util.Arrays; import java.util.Optional; @@ -37,6 +43,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; @@ -47,6 +54,8 @@ public class GeneralPreferencesController implements FxController { private final Application application; private final Environment environment; private final Set keychainAccessProviders; + private final Lazy preferencesScene; + private final ErrorComponent.Builder errorComponent; public ChoiceBox themeChoiceBox; public ChoiceBox keychainBackendChoiceBox; public CheckBox startHiddenCheckbox; @@ -57,7 +66,8 @@ public class GeneralPreferencesController implements FxController { public RadioButton nodeOrientationRtl; @Inject - GeneralPreferencesController(Settings settings, @Named("trayMenuSupported") boolean trayMenuSupported, Optional autoStartStrategy, Set keychainAccessProviders, ObjectProperty selectedTabProperty, LicenseHolder licenseHolder, ExecutorService executor, ResourceBundle resourceBundle, Application application, Environment environment) { + GeneralPreferencesController(@PreferencesWindow Stage window, Settings settings, @Named("trayMenuSupported") boolean trayMenuSupported, Optional autoStartStrategy, Set keychainAccessProviders, 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; @@ -68,6 +78,8 @@ public class GeneralPreferencesController implements FxController { this.resourceBundle = resourceBundle; this.application = application; this.environment = environment; + this.preferencesScene = preferencesScene; + this.errorComponent = errorComponent; } @FXML @@ -129,6 +141,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 de756d899..0e50c5e8a 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 @@ -4,6 +4,7 @@ import dagger.Lazy; 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);