From a2d6db0415e548a82fbc5134378d5e7d5d6c4f27 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 5 Jul 2022 11:09:29 +0200 Subject: [PATCH] Add device registrations success screen --- .../org/cryptomator/ui/common/FxmlFile.java | 1 + .../keyloading/hub/HubKeyLoadingModule.java | 12 +++++ .../hub/RegisterDeviceController.java | 12 +++-- .../hub/RegisterSuccessController.java | 24 +++++++++ .../resources/fxml/hub_register_success.fxml | 52 +++++++++++++++++++ src/main/resources/i18n/strings.properties | 3 ++ 6 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/cryptomator/ui/keyloading/hub/RegisterSuccessController.java create mode 100644 src/main/resources/fxml/hub_register_success.fxml diff --git a/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/src/main/java/org/cryptomator/ui/common/FxmlFile.java index b9e6a990e..f842a0798 100644 --- a/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -16,6 +16,7 @@ public enum FxmlFile { HUB_AUTH_FLOW("/fxml/hub_auth_flow.fxml"), // HUB_RECEIVE_KEY("/fxml/hub_receive_key.fxml"), // HUB_REGISTER_DEVICE("/fxml/hub_register_device.fxml"), // + HUB_REGISTER_SUCCESS("/fxml/hub_register_success.fxml"), // HUB_UNAUTHORIZED_DEVICE("/fxml/hub_unauthorized_device.fxml"), // LOCK_FORCED("/fxml/lock_forced.fxml"), // LOCK_FAILED("/fxml/lock_failed.fxml"), // diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java b/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java index eacdfc10b..f5516fcc9 100644 --- a/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java @@ -106,6 +106,13 @@ public abstract class HubKeyLoadingModule { return fxmlLoaders.createScene(FxmlFile.HUB_REGISTER_DEVICE); } + @Provides + @FxmlScene(FxmlFile.HUB_REGISTER_SUCCESS) + @KeyLoadingScoped + static Scene provideHubRegisterSuccessScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene(FxmlFile.HUB_REGISTER_SUCCESS); + } + @Provides @FxmlScene(FxmlFile.HUB_UNAUTHORIZED_DEVICE) @KeyLoadingScoped @@ -135,6 +142,11 @@ public abstract class HubKeyLoadingModule { @FxControllerKey(RegisterDeviceController.class) abstract FxController bindRegisterDeviceController(RegisterDeviceController controller); + @Binds + @IntoMap + @FxControllerKey(RegisterSuccessController.class) + abstract FxController bindRegisterSuccessController(RegisterSuccessController controller); + @Binds @IntoMap @FxControllerKey(UnauthorizedDeviceController.class) diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java index 2c346d977..5719e6f23 100644 --- a/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java @@ -6,9 +6,12 @@ import com.google.common.io.BaseEncoding; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.nimbusds.jose.JWEObject; +import dagger.Lazy; import org.cryptomator.common.settings.DeviceKey; import org.cryptomator.cryptolib.common.P384KeyPair; import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.keyloading.KeyLoading; import org.cryptomator.ui.keyloading.KeyLoadingScoped; import org.slf4j.Logger; @@ -18,6 +21,7 @@ import javax.inject.Inject; import javax.inject.Named; import javafx.application.Platform; import javafx.fxml.FXML; +import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.stage.Stage; import javafx.stage.WindowEvent; @@ -40,6 +44,7 @@ public class RegisterDeviceController implements FxController { private final Stage window; private final HubConfig hubConfig; private final String bearerToken; + private final Lazy registerSuccessScene; private final String deviceId; private final P384KeyPair keyPair; private final CompletableFuture result; @@ -49,13 +54,14 @@ public class RegisterDeviceController implements FxController { public TextField deviceNameField; @Inject - public RegisterDeviceController(@KeyLoading Stage window, ExecutorService executor, HubConfig hubConfig, @Named("deviceId") String deviceId, DeviceKey deviceKey, CompletableFuture result, @Named("bearerToken") AtomicReference bearerToken) { + public RegisterDeviceController(@KeyLoading Stage window, ExecutorService executor, HubConfig hubConfig, @Named("deviceId") String deviceId, DeviceKey deviceKey, CompletableFuture result, @Named("bearerToken") AtomicReference bearerToken, @FxmlScene(FxmlFile.HUB_REGISTER_SUCCESS) Lazy registerSuccessScene) { this.window = window; this.hubConfig = hubConfig; this.deviceId = deviceId; this.keyPair = Objects.requireNonNull(deviceKey.get()); this.result = result; this.bearerToken = Objects.requireNonNull(bearerToken.get()); + this.registerSuccessScene = registerSuccessScene; this.jwt = JWT.decode(this.bearerToken); this.window.addEventHandler(WindowEvent.WINDOW_HIDING, this::windowClosed); this.httpClient = HttpClient.newBuilder().executor(executor).build(); @@ -80,8 +86,8 @@ public class RegisterDeviceController implements FxController { } private void registrationSucceeded(HttpResponse voidHttpResponse) { - LOG.info("Registered!"); - window.close(); // TODO: show visual feedback "please wait for device authorization" + LOG.debug("Device registration for hub instance {} successful.", hubConfig.authSuccessUrl); + window.setScene(registerSuccessScene.get()); } private Void registrationFailed(Throwable cause) { diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterSuccessController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterSuccessController.java new file mode 100644 index 000000000..bba13516c --- /dev/null +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterSuccessController.java @@ -0,0 +1,24 @@ +package org.cryptomator.ui.keyloading.hub; + +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.keyloading.KeyLoading; + +import javax.inject.Inject; +import javafx.fxml.FXML; +import javafx.stage.Stage; + +public class RegisterSuccessController implements FxController { + + private final Stage window; + + @Inject + public RegisterSuccessController(@KeyLoading Stage window) { + this.window = window; + } + + @FXML + public void close() { + window.close(); + } + +} diff --git a/src/main/resources/fxml/hub_register_success.fxml b/src/main/resources/fxml/hub_register_success.fxml new file mode 100644 index 000000000..822a4489e --- /dev/null +++ b/src/main/resources/fxml/hub_register_success.fxml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +