diff --git a/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/src/main/java/org/cryptomator/ui/common/FxmlFile.java index f842a0798..0ab7375d7 100644 --- a/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -17,6 +17,7 @@ public enum FxmlFile { 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_REGISTER_FAILED("/fxml/hub_register_failed.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 f5516fcc9..587810021 100644 --- a/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java @@ -113,6 +113,13 @@ public abstract class HubKeyLoadingModule { return fxmlLoaders.createScene(FxmlFile.HUB_REGISTER_SUCCESS); } + @Provides + @FxmlScene(FxmlFile.HUB_REGISTER_FAILED) + @KeyLoadingScoped + static Scene provideHubRegisterFailedScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene(FxmlFile.HUB_REGISTER_FAILED); + } + @Provides @FxmlScene(FxmlFile.HUB_UNAUTHORIZED_DEVICE) @KeyLoadingScoped @@ -147,6 +154,11 @@ public abstract class HubKeyLoadingModule { @FxControllerKey(RegisterSuccessController.class) abstract FxController bindRegisterSuccessController(RegisterSuccessController controller); + @Binds + @IntoMap + @FxControllerKey(RegisterFailedController.class) + abstract FxController bindRegisterFailedController(RegisterFailedController 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 5719e6f23..a8cbe4148 100644 --- a/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java @@ -45,6 +45,7 @@ public class RegisterDeviceController implements FxController { private final HubConfig hubConfig; private final String bearerToken; private final Lazy registerSuccessScene; + private final Lazy registerFailedScene; private final String deviceId; private final P384KeyPair keyPair; private final CompletableFuture result; @@ -54,7 +55,7 @@ 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, @FxmlScene(FxmlFile.HUB_REGISTER_SUCCESS) Lazy registerSuccessScene) { + 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, @FxmlScene(FxmlFile.HUB_REGISTER_FAILED) Lazy registerFailedScene) { this.window = window; this.hubConfig = hubConfig; this.deviceId = deviceId; @@ -62,6 +63,7 @@ public class RegisterDeviceController implements FxController { this.result = result; this.bearerToken = Objects.requireNonNull(bearerToken.get()); this.registerSuccessScene = registerSuccessScene; + this.registerFailedScene = registerFailedScene; this.jwt = JWT.decode(this.bearerToken); this.window.addEventHandler(WindowEvent.WINDOW_HIDING, this::windowClosed); this.httpClient = HttpClient.newBuilder().executor(executor).build(); @@ -81,8 +83,14 @@ public class RegisterDeviceController implements FxController { .header("Content-Type", "application/json").PUT(HttpRequest.BodyPublishers.ofString(json, StandardCharsets.UTF_8)) // .build(); httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()) // - .thenAcceptAsync(this::registrationSucceeded, Platform::runLater) // - .exceptionally(this::registrationFailed); + .handleAsync((response, throwable) -> { + if( response != null) { + this.registrationSucceeded(response); + } else { + this.registrationFailed(throwable); + } + return null; + }, Platform::runLater); } private void registrationSucceeded(HttpResponse voidHttpResponse) { @@ -90,9 +98,10 @@ public class RegisterDeviceController implements FxController { window.setScene(registerSuccessScene.get()); } - private Void registrationFailed(Throwable cause) { + private void registrationFailed(Throwable cause) { + LOG.warn("Device registration failed.", cause); + window.setScene(registerFailedScene.get()); result.completeExceptionally(cause); - return null; } @FXML diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterFailedController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterFailedController.java new file mode 100644 index 000000000..8a4278d72 --- /dev/null +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/RegisterFailedController.java @@ -0,0 +1,29 @@ +package org.cryptomator.ui.keyloading.hub; + +import com.nimbusds.jose.JWEObject; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.keyloading.KeyLoading; + +import javax.inject.Inject; +import javafx.fxml.FXML; +import javafx.stage.Stage; +import java.util.concurrent.CompletableFuture; + +public class RegisterFailedController implements FxController { + + private final Stage window; + private final CompletableFuture result; + + @Inject + public RegisterFailedController(@KeyLoading Stage window, CompletableFuture result) { + this.window = window; + this.result = result; + } + + @FXML + public void close() { + window.close(); + } + + +} diff --git a/src/main/resources/fxml/hub_register_failed.fxml b/src/main/resources/fxml/hub_register_failed.fxml new file mode 100644 index 000000000..7ebf59279 --- /dev/null +++ b/src/main/resources/fxml/hub_register_failed.fxml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +