|
@@ -1,7 +1,7 @@
|
|
|
package org.cryptomator.ui.health;
|
|
|
|
|
|
+import com.google.common.base.Preconditions;
|
|
|
import dagger.Lazy;
|
|
|
-import org.cryptomator.common.vaults.Vault;
|
|
|
import org.cryptomator.cryptofs.VaultConfig;
|
|
|
import org.cryptomator.cryptofs.VaultConfigLoadException;
|
|
|
import org.cryptomator.cryptofs.VaultKeyInvalidException;
|
|
@@ -18,14 +18,11 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
import javafx.application.Platform;
|
|
|
-import javafx.beans.binding.BooleanBinding;
|
|
|
import javafx.beans.property.ObjectProperty;
|
|
|
import javafx.beans.property.SimpleObjectProperty;
|
|
|
import javafx.fxml.FXML;
|
|
|
import javafx.scene.Scene;
|
|
|
import javafx.stage.Stage;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.UncheckedIOException;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.CompletionException;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
@@ -36,40 +33,26 @@ public class StartController implements FxController {
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(StartController.class);
|
|
|
|
|
|
- private final Vault vault;
|
|
|
private final Stage window;
|
|
|
- private final CompletableFuture<VaultConfig.UnverifiedVaultConfig> unverifiedVaultConfig;
|
|
|
+ private final ObjectProperty<VaultConfig.UnverifiedVaultConfig> unverifiedVaultConfig;
|
|
|
private final KeyLoadingStrategy keyLoadingStrategy;
|
|
|
private final ExecutorService executor;
|
|
|
private final AtomicReference<Masterkey> masterkeyRef;
|
|
|
private final AtomicReference<VaultConfig> vaultConfigRef;
|
|
|
private final Lazy<Scene> checkScene;
|
|
|
private final Lazy<ErrorComponent.Builder> errorComponent;
|
|
|
- private final ObjectProperty<State> state = new SimpleObjectProperty<>(State.LOADING);
|
|
|
- private final BooleanBinding loading = state.isEqualTo(State.LOADING);
|
|
|
- private final BooleanBinding failed = state.isEqualTo(State.FAILED);
|
|
|
- private final BooleanBinding loaded = state.isEqualTo(State.LOADED);
|
|
|
-
|
|
|
- public enum State {
|
|
|
- LOADING,
|
|
|
- FAILED,
|
|
|
- LOADED
|
|
|
- }
|
|
|
-
|
|
|
- /* FXML */
|
|
|
|
|
|
@Inject
|
|
|
- public StartController(@HealthCheckWindow Vault vault, @HealthCheckWindow Stage window, @HealthCheckWindow KeyLoadingStrategy keyLoadingStrategy, ExecutorService executor, AtomicReference<Masterkey> masterkeyRef, AtomicReference<VaultConfig> vaultConfigRef, @FxmlScene(FxmlFile.HEALTH_CHECK_LIST) Lazy<Scene> checkScene, Lazy<ErrorComponent.Builder> errorComponent) {
|
|
|
- this.vault = vault;
|
|
|
+ public StartController(@HealthCheckWindow Stage window, HealthCheckComponent.LoadUnverifiedConfigResult configLoadResult, @HealthCheckWindow KeyLoadingStrategy keyLoadingStrategy, ExecutorService executor, AtomicReference<Masterkey> masterkeyRef, AtomicReference<VaultConfig> vaultConfigRef, @FxmlScene(FxmlFile.HEALTH_CHECK_LIST) Lazy<Scene> checkScene, Lazy<ErrorComponent.Builder> errorComponent) {
|
|
|
+ Preconditions.checkNotNull(configLoadResult.config());
|
|
|
this.window = window;
|
|
|
- this.unverifiedVaultConfig = CompletableFuture.supplyAsync(this::loadConfig, executor);
|
|
|
+ this.unverifiedVaultConfig = new SimpleObjectProperty<>(configLoadResult.config());
|
|
|
this.keyLoadingStrategy = keyLoadingStrategy;
|
|
|
this.executor = executor;
|
|
|
this.masterkeyRef = masterkeyRef;
|
|
|
this.vaultConfigRef = vaultConfigRef;
|
|
|
this.checkScene = checkScene;
|
|
|
this.errorComponent = errorComponent;
|
|
|
- this.unverifiedVaultConfig.whenCompleteAsync(this::loadedConfig, Platform::runLater);
|
|
|
}
|
|
|
|
|
|
@FXML
|
|
@@ -84,29 +67,10 @@ public class StartController implements FxController {
|
|
|
CompletableFuture.runAsync(this::loadKey, executor).whenCompleteAsync(this::loadedKey, Platform::runLater);
|
|
|
}
|
|
|
|
|
|
- private VaultConfig.UnverifiedVaultConfig loadConfig() {
|
|
|
- assert !Platform.isFxApplicationThread();
|
|
|
- try {
|
|
|
- return this.vault.getUnverifiedVaultConfig();
|
|
|
- } catch (IOException e) {
|
|
|
- throw new UncheckedIOException(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void loadedConfig(VaultConfig.UnverifiedVaultConfig cfg, Throwable exception) {
|
|
|
- assert Platform.isFxApplicationThread();
|
|
|
- if (exception != null) {
|
|
|
- state.set(State.FAILED);
|
|
|
- } else {
|
|
|
- assert cfg != null;
|
|
|
- state.set(State.LOADED);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void loadKey() {
|
|
|
assert !Platform.isFxApplicationThread();
|
|
|
- assert unverifiedVaultConfig.isDone();
|
|
|
- var unverifiedCfg = unverifiedVaultConfig.join();
|
|
|
+ assert unverifiedVaultConfig.get() != null;
|
|
|
+ var unverifiedCfg = unverifiedVaultConfig.get();
|
|
|
try (var masterkey = keyLoadingStrategy.loadKey(unverifiedCfg.getKeyId())) {
|
|
|
var verifiedCfg = unverifiedCfg.verify(masterkey.getEncoded(), unverifiedCfg.allegedVaultVersion());
|
|
|
vaultConfigRef.set(verifiedCfg);
|
|
@@ -150,35 +114,10 @@ public class StartController implements FxController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /* Getter */
|
|
|
-
|
|
|
- public BooleanBinding loadingProperty() {
|
|
|
- return loading;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isLoading() {
|
|
|
- return loading.get();
|
|
|
- }
|
|
|
-
|
|
|
- public BooleanBinding failedProperty() {
|
|
|
- return failed;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isFailed() {
|
|
|
- return failed.get();
|
|
|
- }
|
|
|
-
|
|
|
- public BooleanBinding loadedProperty() {
|
|
|
- return loaded;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isLoaded() {
|
|
|
- return loaded.get();
|
|
|
- }
|
|
|
-
|
|
|
/* internal types */
|
|
|
|
|
|
private static class LoadingFailedException extends CompletionException {
|
|
|
+
|
|
|
LoadingFailedException(Throwable cause) {
|
|
|
super(cause);
|
|
|
}
|