Refactor reveal() methods:

* new class HostServiceRevealer implemeting the Volume.Revealer-Interface
* this class is injected in vault service and always used for revealing
* removed Revealer parameter from several reveal methods
This commit is contained in:
Armin Schrenk
2021-01-21 17:25:23 +01:00
parent 95cef34234
commit 7cd5c66836
6 changed files with 37 additions and 19 deletions

View File

@@ -0,0 +1,24 @@
package org.cryptomator.ui.common;
import org.cryptomator.common.vaults.Volume;
import org.cryptomator.ui.launcher.FxApplicationStarter;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.nio.file.Path;
@Singleton
public class HostServiceRevealer implements Volume.Revealer {
private final FxApplicationStarter fxApplicationStarter;
@Inject
public HostServiceRevealer(FxApplicationStarter fxApplicationStarter) {
this.fxApplicationStarter = fxApplicationStarter;
}
@Override
public void reveal(Path p) throws Volume.VolumeException {
fxApplicationStarter.get().thenAccept(app -> app.getHostServices().showDocument(p.toUri().toString()));
}
}

View File

@@ -23,14 +23,16 @@ public class VaultService {
private static final Logger LOG = LoggerFactory.getLogger(VaultService.class);
private final ExecutorService executorService;
private final HostServiceRevealer vaultRevealer;
@Inject
public VaultService(ExecutorService executorService) {
public VaultService(ExecutorService executorService, HostServiceRevealer vaultRevealer) {
this.executorService = executorService;
this.vaultRevealer = vaultRevealer;
}
public void reveal(Vault vault, Volume.Revealer vaultRevealCmd) {
executorService.execute(createRevealTask(vault, vaultRevealCmd));
public void reveal(Vault vault) {
executorService.execute(createRevealTask(vault));
}
/**
@@ -38,8 +40,8 @@ public class VaultService {
*
* @param vault The vault to reveal
*/
public Task<Vault> createRevealTask(Vault vault, Volume.Revealer vaultRevealCmd) {
Task<Vault> task = new RevealVaultTask(vault, vaultRevealCmd);
public Task<Vault> createRevealTask(Vault vault) {
Task<Vault> task = new RevealVaultTask(vault, vaultRevealer);
task.setOnSucceeded(evt -> LOG.info("Revealed {}", vault.getDisplayName()));
task.setOnFailed(evt -> LOG.error("Failed to reveal " + vault.getDisplayName(), evt.getSource().getException()));
return task;

View File

@@ -42,7 +42,7 @@ public class VaultDetailUnlockedController implements FxController {
@FXML
public void revealAccessLocation() {
vaultService.reveal(vault.get(), p -> application.getHostServices().showDocument(p.toUri().toString()));
vaultService.reveal(vault.get());
}
@FXML

View File

@@ -121,9 +121,7 @@ class TrayMenuController {
}
private void revealVault(Vault vault) {
showMainAppAndThen(app -> //
app.getVaultService().reveal(vault, p -> app.getHostServices().showDocument(p.toUri().toString())) //
);
showMainAppAndThen(app -> app.getVaultService().reveal(vault));
}
void showMainWindow(@SuppressWarnings("unused") ActionEvent actionEvent) {

View File

@@ -4,7 +4,6 @@ import org.cryptomator.common.settings.WhenUnlocked;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.common.VaultService;
import org.cryptomator.ui.fxapp.FxApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,19 +29,17 @@ public class UnlockSuccessController implements FxController {
private final Vault vault;
private final ExecutorService executor;
private final VaultService vaultService;
private final FxApplication application;
private final ObjectProperty<ContentDisplay> revealButtonState;
private final BooleanProperty revealButtonDisabled;
public CheckBox rememberChoiceCheckbox;
@Inject
public UnlockSuccessController(@UnlockWindow Stage window, @UnlockWindow Vault vault, ExecutorService executor, VaultService vaultService, FxApplication application) {
public UnlockSuccessController(@UnlockWindow Stage window, @UnlockWindow Vault vault, ExecutorService executor, VaultService vaultService) {
this.window = window;
this.vault = vault;
this.executor = executor;
this.vaultService = vaultService;
this.application = application;
this.revealButtonState = new SimpleObjectProperty<>(ContentDisplay.TEXT_ONLY);
this.revealButtonDisabled = new SimpleBooleanProperty();
}
@@ -62,7 +59,7 @@ public class UnlockSuccessController implements FxController {
revealButtonState.set(ContentDisplay.LEFT);
revealButtonDisabled.set(true);
Task<Vault> revealTask = vaultService.createRevealTask(vault, p -> application.getHostServices().showDocument(p.toUri().toString()));
Task<Vault> revealTask = vaultService.createRevealTask(vault);
revealTask.setOnSucceeded(evt -> {
revealButtonState.set(ContentDisplay.TEXT_ONLY);
revealButtonDisabled.set(false);

View File

@@ -15,7 +15,6 @@ import org.cryptomator.ui.common.FxmlFile;
import org.cryptomator.ui.common.FxmlScene;
import org.cryptomator.ui.common.UserInteractionLock;
import org.cryptomator.ui.common.VaultService;
import org.cryptomator.ui.fxapp.FxApplication;
import org.cryptomator.ui.unlock.UnlockModule.PasswordEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,10 +58,9 @@ public class UnlockWorkflow extends Task<Boolean> {
private final Lazy<Scene> successScene;
private final Lazy<Scene> invalidMountPointScene;
private final ErrorComponent.Builder errorComponent;
private final FxApplication application;
@Inject
UnlockWorkflow(@UnlockWindow Stage window, @UnlockWindow Vault vault, VaultService vaultService, AtomicReference<char[]> password, @Named("savePassword") AtomicBoolean savePassword, @Named("savedPassword") Optional<char[]> savedPassword, UserInteractionLock<PasswordEntry> passwordEntryLock, KeychainManager keychain, @FxmlScene(FxmlFile.UNLOCK) Lazy<Scene> unlockScene, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy<Scene> successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy<Scene> invalidMountPointScene, ErrorComponent.Builder errorComponent, FxApplication application) {
UnlockWorkflow(@UnlockWindow Stage window, @UnlockWindow Vault vault, VaultService vaultService, AtomicReference<char[]> password, @Named("savePassword") AtomicBoolean savePassword, @Named("savedPassword") Optional<char[]> savedPassword, UserInteractionLock<PasswordEntry> passwordEntryLock, KeychainManager keychain, @FxmlScene(FxmlFile.UNLOCK) Lazy<Scene> unlockScene, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy<Scene> successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy<Scene> invalidMountPointScene, ErrorComponent.Builder errorComponent) {
this.window = window;
this.vault = vault;
this.vaultService = vaultService;
@@ -75,7 +73,6 @@ public class UnlockWorkflow extends Task<Boolean> {
this.successScene = successScene;
this.invalidMountPointScene = invalidMountPointScene;
this.errorComponent = errorComponent;
this.application = application;
setOnFailed(event -> {
Throwable throwable = event.getSource().getException();
@@ -146,7 +143,7 @@ public class UnlockWorkflow extends Task<Boolean> {
});
case REVEAL -> {
Platform.runLater(window::close);
vaultService.reveal(vault, p -> application.getHostServices().showDocument(p.toUri().toString()));
vaultService.reveal(vault);
}
case IGNORE -> Platform.runLater(window::close);
}