diff --git a/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/src/main/java/org/cryptomator/ui/common/FxmlFile.java index 144b8bbb6..46542ccb9 100644 --- a/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -25,6 +25,7 @@ public enum FxmlFile { HUB_REGISTER_FAILED("/fxml/hub_register_failed.fxml"), // HUB_SETUP_DEVICE("/fxml/hub_setup_device.fxml"), // HUB_UNAUTHORIZED_DEVICE("/fxml/hub_unauthorized_device.fxml"), // + HUB_REQUIRE_ACCOUNT_INIT("/fxml/hub_require_account_init.fxml"), // LOCK_FORCED("/fxml/lock_forced.fxml"), // LOCK_FAILED("/fxml/lock_failed.fxml"), // MAIN_WINDOW("/fxml/main_window.fxml"), // diff --git a/src/main/java/org/cryptomator/ui/controls/FontAwesome5Icon.java b/src/main/java/org/cryptomator/ui/controls/FontAwesome5Icon.java index 33a674b11..c5ec19929 100644 --- a/src/main/java/org/cryptomator/ui/controls/FontAwesome5Icon.java +++ b/src/main/java/org/cryptomator/ui/controls/FontAwesome5Icon.java @@ -53,6 +53,7 @@ public enum FontAwesome5Icon { TIMES("\uF00D"), // TRASH("\uF1F8"), // UNLINK("\uf127"), // + USER_COG("\uf4fe"), // WRENCH("\uF0AD"), // WINDOW_MINIMIZE("\uF2D1"), // ; diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/HubConfig.java b/src/main/java/org/cryptomator/ui/keyloading/hub/HubConfig.java index ef1fe30df..f8ec7b854 100644 --- a/src/main/java/org/cryptomator/ui/keyloading/hub/HubConfig.java +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/HubConfig.java @@ -21,11 +21,16 @@ public class HubConfig { public URI getApiBaseUrl() { if (apiBaseUrl != null) { - return URI.create(apiBaseUrl); - } else { - // legacy approach + // make sure to end on "/": + return URI.create(apiBaseUrl + "/").normalize(); + } else { // legacy approach assert devicesResourceUrl != null; + // make sure to end on "/": return URI.create(devicesResourceUrl + "/..").normalize(); } } + + public URI getWebappBaseUrl() { + return getApiBaseUrl().resolve("../app/"); + } } 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 c8d308e8e..235fbf639 100644 --- a/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java @@ -119,6 +119,7 @@ public abstract class HubKeyLoadingModule { return fxmlLoaders.createScene(FxmlFile.HUB_LEGACY_REGISTER_DEVICE); } + @Provides @FxmlScene(FxmlFile.HUB_REGISTER_SUCCESS) @KeyLoadingScoped @@ -147,6 +148,13 @@ public abstract class HubKeyLoadingModule { return fxmlLoaders.createScene(FxmlFile.HUB_UNAUTHORIZED_DEVICE); } + @Provides + @FxmlScene(FxmlFile.HUB_REQUIRE_ACCOUNT_INIT) + @KeyLoadingScoped + static Scene provideRequireAccountInitScene(@KeyLoading FxmlLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene(FxmlFile.HUB_REQUIRE_ACCOUNT_INIT); + } + @Binds @IntoMap @FxControllerKey(NoKeychainController.class) @@ -191,4 +199,9 @@ public abstract class HubKeyLoadingModule { @IntoMap @FxControllerKey(UnauthorizedDeviceController.class) abstract FxController bindUnauthorizedDeviceController(UnauthorizedDeviceController controller); + + @Binds + @IntoMap + @FxControllerKey(RequireAccountInitController.class) + abstract FxController bindRequireAccountInitController(RequireAccountInitController controller); } diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java index 66566a98a..c0681d4bb 100644 --- a/src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java @@ -54,12 +54,13 @@ public class ReceiveKeyController implements FxController { private final Lazy setupDeviceScene; private final Lazy legacyRegisterDeviceScene; private final Lazy unauthorizedScene; + private final Lazy accountInitializationScene; private final URI vaultBaseUri; private final Lazy invalidLicenseScene; private final HttpClient httpClient; @Inject - public ReceiveKeyController(@KeyLoading Vault vault, ExecutorService executor, @KeyLoading Stage window, HubConfig hubConfig, @Named("deviceId") String deviceId, @Named("bearerToken") AtomicReference tokenRef, CompletableFuture result, @FxmlScene(FxmlFile.HUB_SETUP_DEVICE) Lazy setupDeviceScene, @FxmlScene(FxmlFile.HUB_LEGACY_REGISTER_DEVICE) Lazy legacyRegisterDeviceScene, @FxmlScene(FxmlFile.HUB_UNAUTHORIZED_DEVICE) Lazy unauthorizedScene, @FxmlScene(FxmlFile.HUB_INVALID_LICENSE) Lazy invalidLicenseScene) { + public ReceiveKeyController(@KeyLoading Vault vault, ExecutorService executor, @KeyLoading Stage window, HubConfig hubConfig, @Named("deviceId") String deviceId, @Named("bearerToken") AtomicReference tokenRef, CompletableFuture result, @FxmlScene(FxmlFile.HUB_SETUP_DEVICE) Lazy setupDeviceScene, @FxmlScene(FxmlFile.HUB_LEGACY_REGISTER_DEVICE) Lazy legacyRegisterDeviceScene, @FxmlScene(FxmlFile.HUB_UNAUTHORIZED_DEVICE) Lazy unauthorizedScene, @FxmlScene(FxmlFile.HUB_REQUIRE_ACCOUNT_INIT) Lazy accountInitializationScene, @FxmlScene(FxmlFile.HUB_INVALID_LICENSE) Lazy invalidLicenseScene) { this.window = window; this.hubConfig = hubConfig; this.deviceId = deviceId; @@ -68,6 +69,7 @@ public class ReceiveKeyController implements FxController { this.setupDeviceScene = setupDeviceScene; this.legacyRegisterDeviceScene = legacyRegisterDeviceScene; this.unauthorizedScene = unauthorizedScene; + this.accountInitializationScene = accountInitializationScene; this.vaultBaseUri = getVaultBaseUri(vault); this.invalidLicenseScene = invalidLicenseScene; this.window.addEventHandler(WindowEvent.WINDOW_HIDING, this::windowClosed); @@ -105,6 +107,7 @@ public class ReceiveKeyController implements FxController { case 200 -> requestUserKey(response.body()); case 402 -> licenseExceeded(); case 403, 410 -> accessNotGranted(); // or vault has been archived, effectively disallowing access - TODO: add specific dialog? + case 449 -> accountInitializationRequired(); case 404 -> requestLegacyAccessToken(); default -> throw new IllegalStateException("Unexpected response " + response.statusCode()); } @@ -221,6 +224,10 @@ public class ReceiveKeyController implements FxController { window.setScene(unauthorizedScene.get()); } + private void accountInitializationRequired() { + window.setScene(accountInitializationScene.get()); + } + private Void retrievalFailed(Throwable cause) { result.completeExceptionally(cause); return null; diff --git a/src/main/java/org/cryptomator/ui/keyloading/hub/RequireAccountInitController.java b/src/main/java/org/cryptomator/ui/keyloading/hub/RequireAccountInitController.java new file mode 100644 index 000000000..892d00de0 --- /dev/null +++ b/src/main/java/org/cryptomator/ui/keyloading/hub/RequireAccountInitController.java @@ -0,0 +1,46 @@ +package org.cryptomator.ui.keyloading.hub; + +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.keyloading.KeyLoading; +import org.cryptomator.ui.keyloading.KeyLoadingScoped; + +import javax.inject.Inject; +import javafx.application.Application; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.stage.Stage; +import javafx.stage.WindowEvent; +import java.util.concurrent.CompletableFuture; + +@KeyLoadingScoped +public class RequireAccountInitController implements FxController { + + private final Application application; + private final HubConfig hubConfig; + private final Stage window; + private final CompletableFuture result; + + @Inject + public RequireAccountInitController(Application application, HubConfig hubConfig, @KeyLoading Stage window, CompletableFuture result) { + this.application = application; + this.hubConfig = hubConfig; + this.window = window; + this.result = result; + this.window.addEventHandler(WindowEvent.WINDOW_HIDING, this::windowClosed); + } + + @FXML + public void completeSetup() { + application.getHostServices().showDocument(hubConfig.getWebappBaseUrl().resolve("profile").toString()); + close(); + } + + @FXML + public void close() { + window.close(); + } + + private void windowClosed(WindowEvent windowEvent) { + result.cancel(true); + } +} diff --git a/src/main/resources/fxml/hub_require_account_init.fxml b/src/main/resources/fxml/hub_require_account_init.fxml new file mode 100644 index 000000000..b3ca1fb40 --- /dev/null +++ b/src/main/resources/fxml/hub_require_account_init.fxml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +