mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
ugly PoC for new UI
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
<project.jdk.version>16</project.jdk.version>
|
||||
|
||||
<!-- cryptomator dependencies -->
|
||||
<cryptomator.cryptofs.version>2.1.0-beta2</cryptomator.cryptofs.version>
|
||||
<cryptomator.cryptofs.version>2.1.0-beta3</cryptomator.cryptofs.version>
|
||||
<cryptomator.integrations.version>1.0.0-beta2</cryptomator.integrations.version>
|
||||
<cryptomator.integrations.win.version>1.0.0-beta2</cryptomator.integrations.win.version>
|
||||
<cryptomator.integrations.mac.version>1.0.0-beta2</cryptomator.integrations.mac.version>
|
||||
|
||||
@@ -10,11 +10,14 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.ReadOnlyObjectProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.stage.Stage;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -22,40 +25,61 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
@HealthCheckScoped
|
||||
public class CheckController implements FxController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CheckController.class);
|
||||
|
||||
private final Vault vault;
|
||||
private final Stage window;
|
||||
private final Masterkey masterkey;
|
||||
private final VaultConfig vaultConfig;
|
||||
private final SecureRandom csprng;
|
||||
private final HealthCheckTaskFactory healthCheckTaskFactory;
|
||||
private final ExecutorService executor;
|
||||
private final ObjectProperty<HealthCheck> selectedCheck;
|
||||
private final ObservableList<HealthCheck> checks;
|
||||
private final ObservableList<DiagnosticResult> results;
|
||||
|
||||
public ListView<HealthCheck> checksListView;
|
||||
public ListView<DiagnosticResult> resultsListView;
|
||||
|
||||
@Inject
|
||||
public CheckController(@HealthCheckWindow Vault vault, @HealthCheckWindow Stage window, AtomicReference<Masterkey> masterkeyRef, AtomicReference<VaultConfig> vaultConfigRef, SecureRandom csprng, ExecutorService executor) {
|
||||
this.vault = vault;
|
||||
public CheckController(@HealthCheckWindow Stage window, AtomicReference<VaultConfig> vaultConfigRef, HealthCheckTaskFactory healthCheckTaskFactory, ExecutorService executor, ObjectProperty<HealthCheck> selectedCheck) {
|
||||
this.window = window;
|
||||
this.masterkey = Objects.requireNonNull(masterkeyRef.get());
|
||||
this.vaultConfig = Objects.requireNonNull(vaultConfigRef.get());
|
||||
this.csprng = csprng;
|
||||
this.healthCheckTaskFactory = healthCheckTaskFactory;
|
||||
this.executor = executor;
|
||||
this.selectedCheck = selectedCheck;
|
||||
this.checks = FXCollections.observableArrayList(HealthCheck.allChecks());
|
||||
this.results = FXCollections.observableArrayList();
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
checksListView.setItems(checks);
|
||||
checksListView.setCellFactory(this::createCheckListCell);
|
||||
resultsListView.setItems(results);
|
||||
resultsListView.setCellFactory(this::createResultListCell);
|
||||
selectedCheck.bind(checksListView.getSelectionModel().selectedItemProperty());
|
||||
}
|
||||
|
||||
private CheckListCell createCheckListCell(ListView<HealthCheck> list) {
|
||||
return new CheckListCell();
|
||||
}
|
||||
|
||||
private ResultListCell createResultListCell(ListView<DiagnosticResult> list) {
|
||||
return new ResultListCell();
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void runCheck() {
|
||||
try (var cryptor = vaultConfig.getCipherCombo().getCryptorProvider(csprng).withKey(masterkey)) {
|
||||
HealthCheck.allChecks().stream()
|
||||
.peek(check -> {
|
||||
LOG.info("Running check: {}", check.identifier());
|
||||
})
|
||||
.flatMap(check -> check.check(vault.getPath(), vaultConfig, masterkey, cryptor, executor))
|
||||
.forEach(result -> {
|
||||
LOG.info("Result: {}", result);
|
||||
});
|
||||
}
|
||||
executor.execute(healthCheckTaskFactory.newTask(selectedCheck.get(), results::add));
|
||||
}
|
||||
|
||||
/* Getter/Setter */
|
||||
|
||||
public VaultConfig getVaultConfig() {
|
||||
return vaultConfig;
|
||||
}
|
||||
|
||||
public HealthCheck getSelectedCheck() {
|
||||
return selectedCheck.get();
|
||||
}
|
||||
|
||||
public ReadOnlyObjectProperty<HealthCheck> selectedCheckProperty() {
|
||||
return selectedCheck;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.cryptomator.ui.health;
|
||||
|
||||
import org.cryptomator.cryptofs.health.api.HealthCheck;
|
||||
|
||||
import javafx.scene.control.ListCell;
|
||||
|
||||
class CheckListCell extends ListCell<HealthCheck> {
|
||||
|
||||
@Override
|
||||
protected void updateItem(HealthCheck item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null) {
|
||||
setText(item.identifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.cryptofs.VaultConfig;
|
||||
import org.cryptomator.cryptofs.health.api.HealthCheck;
|
||||
import org.cryptomator.cryptolib.api.Masterkey;
|
||||
import org.cryptomator.ui.common.DefaultSceneFactory;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
@@ -19,9 +20,9 @@ import org.cryptomator.ui.keyloading.KeyLoadingStrategy;
|
||||
import org.cryptomator.ui.mainwindow.MainWindow;
|
||||
|
||||
import javax.inject.Provider;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
@@ -33,6 +34,12 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
@Module(subcomponents = {KeyLoadingComponent.class})
|
||||
abstract class HealthCheckModule {
|
||||
|
||||
@Provides
|
||||
@HealthCheckScoped
|
||||
static ObjectProperty<HealthCheck> selectedHealthCheck() {
|
||||
return new SimpleObjectProperty<HealthCheck>();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@HealthCheckScoped
|
||||
static AtomicReference<Masterkey> provideMasterkeyRef() {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.cryptomator.ui.health;
|
||||
|
||||
import org.cryptomator.cryptofs.VaultConfig;
|
||||
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
|
||||
import org.cryptomator.cryptofs.health.api.HealthCheck;
|
||||
import org.cryptomator.cryptolib.api.Masterkey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.concurrent.Task;
|
||||
import java.nio.file.Path;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
class HealthCheckTask extends Task<Void> {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HealthCheckTask.class);
|
||||
|
||||
private final Path vaultPath;
|
||||
private final VaultConfig vaultConfig;
|
||||
private final Masterkey masterkey;
|
||||
private final SecureRandom csprng;
|
||||
private final HealthCheck check;
|
||||
private final Consumer<DiagnosticResult> resultConsumer;
|
||||
|
||||
public HealthCheckTask(Path vaultPath, VaultConfig vaultConfig, Masterkey masterkey, SecureRandom csprng, HealthCheck check, Consumer<DiagnosticResult> resultConsumer) {
|
||||
this.vaultPath = vaultPath;
|
||||
this.vaultConfig = vaultConfig;
|
||||
this.masterkey = masterkey;
|
||||
this.csprng = csprng;
|
||||
this.check = Objects.requireNonNull(check);
|
||||
this.resultConsumer = resultConsumer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void call() {
|
||||
try (var cryptor = vaultConfig.getCipherCombo().getCryptorProvider(csprng).withKey(masterkey)) {
|
||||
check.check(vaultPath, vaultConfig, masterkey, cryptor, result -> {
|
||||
if (isCancelled()) {
|
||||
throw new CancellationException();
|
||||
}
|
||||
Platform.runLater(() -> resultConsumer.accept(result));
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void scheduled() {
|
||||
LOG.info("starting {}", check.identifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
LOG.info("finished {}", check.identifier());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.cryptomator.ui.health;
|
||||
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.cryptofs.VaultConfig;
|
||||
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
|
||||
import org.cryptomator.cryptofs.health.api.HealthCheck;
|
||||
import org.cryptomator.cryptolib.api.Masterkey;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@HealthCheckScoped
|
||||
class HealthCheckTaskFactory {
|
||||
|
||||
private final Vault vault;
|
||||
private final Masterkey masterkey;
|
||||
private final VaultConfig vaultConfig;
|
||||
private final SecureRandom csprng;
|
||||
|
||||
@Inject
|
||||
public HealthCheckTaskFactory(@HealthCheckWindow Vault vault, AtomicReference<Masterkey> masterkeyRef, AtomicReference<VaultConfig> vaultConfigRef, SecureRandom csprng) {
|
||||
this.vault = vault;
|
||||
this.masterkey = Objects.requireNonNull(masterkeyRef.get());
|
||||
this.vaultConfig = Objects.requireNonNull(vaultConfigRef.get());
|
||||
this.csprng = csprng;
|
||||
}
|
||||
|
||||
public HealthCheckTask newTask(HealthCheck healthCheck, Consumer<DiagnosticResult> resultConsumer) {
|
||||
return new HealthCheckTask(vault.getPath(), vaultConfig, masterkey, csprng, healthCheck, resultConsumer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.cryptomator.ui.health;
|
||||
|
||||
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
|
||||
import org.cryptomator.cryptofs.health.api.HealthCheck;
|
||||
|
||||
import javafx.scene.control.ListCell;
|
||||
|
||||
class ResultListCell extends ListCell<DiagnosticResult> {
|
||||
|
||||
@Override
|
||||
protected void updateItem(DiagnosticResult item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null) {
|
||||
setText(item.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@
|
||||
<?import javafx.scene.control.ButtonBar?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml"
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<HBox xmlns:fx="http://javafx.com/fxml"
|
||||
xmlns="http://javafx.com/javafx"
|
||||
fx:controller="org.cryptomator.ui.health.CheckController"
|
||||
minWidth="400"
|
||||
@@ -16,12 +18,17 @@
|
||||
<Insets topRightBottomLeft="12"/>
|
||||
</padding>
|
||||
<children>
|
||||
<Label text="${controller.vaultConfig.cipherCombo}"/>
|
||||
<ListView fx:id="checksListView"/>
|
||||
<VBox>
|
||||
<Label text="${controller.vaultConfig.cipherCombo}"/>
|
||||
|
||||
<ButtonBar buttonMinWidth="120" buttonOrder="+X">
|
||||
<buttons>
|
||||
<Button text="TODO run check" ButtonBar.buttonData="NEXT_FORWARD" defaultButton="true" onAction="#runCheck"/>
|
||||
</buttons>
|
||||
</ButtonBar>
|
||||
<ListView fx:id="resultsListView"/>
|
||||
|
||||
<ButtonBar buttonMinWidth="120" buttonOrder="+X">
|
||||
<buttons>
|
||||
<Button text="TODO run check" ButtonBar.buttonData="NEXT_FORWARD" defaultButton="true" onAction="#runCheck" disable="${selectedCheck.isNull}"/>
|
||||
</buttons>
|
||||
</ButtonBar>
|
||||
</VBox>
|
||||
</children>
|
||||
</VBox>
|
||||
</HBox>
|
||||
|
||||
Reference in New Issue
Block a user