change reveal method in vault service:

* revealer is no member anymore
* reveal() takes as second argument revealer object
* several other classes hand over a revealer object
* added awt-revealer if application is not yet started
This commit is contained in:
Armin Schrenk
2021-01-21 15:26:35 +01:00
parent 81fb6b8794
commit d5eb84a000
8 changed files with 48 additions and 22 deletions
@@ -25,20 +25,13 @@ public class VaultService {
private final ExecutorService executorService;
private AtomicReference<Volume.RevealerFacade> vaultRevealer;
@Inject
public VaultService(ExecutorService executorService) {
this.executorService = executorService;
this.vaultRevealer = new AtomicReference<>(p -> {}); //the inital revealer does nuthin
}
public void reveal(Vault vault) {
executorService.execute(createRevealTask(vault));
}
public void setVaultRevealer(Volume.RevealerFacade revealer) {
this.vaultRevealer.set(revealer);
public void reveal(Vault vault, Volume.RevealerFacade vaultRevealCmd) {
executorService.execute(createRevealTask(vault, vaultRevealCmd));
}
/**
@@ -46,8 +39,8 @@ public class VaultService {
*
* @param vault The vault to reveal
*/
public Task<Vault> createRevealTask(Vault vault) {
Task<Vault> task = new RevealVaultTask(vault, vaultRevealer.get());
public Task<Vault> createRevealTask(Vault vault, Volume.RevealerFacade vaultRevealCmd) {
Task<Vault> task = new RevealVaultTask(vault, vaultRevealCmd);
task.setOnSucceeded(evt -> LOG.info("Revealed {}", vault.getDisplayName()));
task.setOnFailed(evt -> LOG.error("Failed to reveal " + vault.getDisplayName(), evt.getSource().getException()));
return task;
@@ -68,8 +68,6 @@ public class FxApplication extends Application {
this.licenseHolder = licenseHolder;
this.visibleWindows = Stage.getWindows().filtered(Window::isShowing);
this.hasVisibleWindows = Bindings.isNotEmpty(visibleWindows);
vaultService.setVaultRevealer(p -> this.getHostServices().showDocument(p.toUri().toString()));
}
public void start() {
@@ -42,7 +42,7 @@ public class VaultDetailUnlockedController implements FxController {
@FXML
public void revealAccessLocation() {
vaultService.reveal(vault.get());
vaultService.reveal(vault.get(), p -> application.getHostServices().showDocument(p.toUri().toString()));
}
@FXML
@@ -7,11 +7,10 @@ package org.cryptomator.ui.traymenu;
import dagger.Lazy;
import dagger.Subcomponent;
import java.awt.SystemTray;
@TrayMenuScoped
@Subcomponent
@Subcomponent(modules = TrayMenuModule.class)
public interface TrayMenuComponent {
Lazy<TrayIconController> trayIconController();
@@ -1,6 +1,7 @@
package org.cryptomator.ui.traymenu;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.Volume;
import org.cryptomator.ui.fxapp.FxApplication;
import org.cryptomator.ui.launcher.AppLifecycleListener;
import org.cryptomator.ui.launcher.FxApplicationStarter;
@@ -27,14 +28,16 @@ class TrayMenuController {
private final AppLifecycleListener appLifecycle;
private final FxApplicationStarter fxApplicationStarter;
private final ObservableList<Vault> vaults;
private final Volume.RevealerFacade revealer;
private final PopupMenu menu;
@Inject
TrayMenuController(ResourceBundle resourceBundle, AppLifecycleListener appLifecycle, FxApplicationStarter fxApplicationStarter, ObservableList<Vault> vaults) {
TrayMenuController(ResourceBundle resourceBundle, AppLifecycleListener appLifecycle, FxApplicationStarter fxApplicationStarter, ObservableList<Vault> vaults, Volume.RevealerFacade revealer) {
this.resourceBundle = resourceBundle;
this.appLifecycle = appLifecycle;
this.fxApplicationStarter = fxApplicationStarter;
this.vaults = vaults;
this.revealer = revealer;
this.menu = new PopupMenu();
}
@@ -121,7 +124,7 @@ class TrayMenuController {
}
private void revealVault(Vault vault) {
showMainAppAndThen(app -> app.getVaultService().reveal(vault));
showMainAppAndThen(app -> app.getVaultService().reveal(vault, revealer));
}
void showMainWindow(@SuppressWarnings("unused") ActionEvent actionEvent) {
@@ -0,0 +1,27 @@
package org.cryptomator.ui.traymenu;
import dagger.Module;
import dagger.Provides;
import org.cryptomator.common.vaults.Volume;
import java.awt.Desktop;
import java.io.IOException;
@Module
abstract class TrayMenuModule {
@Provides
static Volume.RevealerFacade provideAwtRevealer(){
return p -> {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
try {
Desktop.getDesktop().open(p.toFile());
} catch (IOException e) {
throw new Volume.VolumeException(e);
}
} else {
throw new Volume.VolumeException("API to browse files not supported. Please try again from inside the application.");
}
};
}
}
@@ -4,6 +4,7 @@ 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;
@@ -29,17 +30,19 @@ 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) {
public UnlockSuccessController(@UnlockWindow Stage window, @UnlockWindow Vault vault, ExecutorService executor, VaultService vaultService, FxApplication application) {
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();
}
@@ -59,7 +62,7 @@ public class UnlockSuccessController implements FxController {
revealButtonState.set(ContentDisplay.LEFT);
revealButtonDisabled.set(true);
Task<Vault> revealTask = vaultService.createRevealTask(vault);
Task<Vault> revealTask = vaultService.createRevealTask(vault, p -> application.getHostServices().showDocument(p.toUri().toString()));
revealTask.setOnSucceeded(evt -> {
revealButtonState.set(ContentDisplay.TEXT_ONLY);
revealButtonDisabled.set(false);
@@ -15,6 +15,7 @@ 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;
@@ -58,9 +59,10 @@ 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) {
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) {
this.window = window;
this.vault = vault;
this.vaultService = vaultService;
@@ -73,6 +75,7 @@ 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();
@@ -143,7 +146,7 @@ public class UnlockWorkflow extends Task<Boolean> {
});
case REVEAL -> {
Platform.runLater(window::close);
vaultService.reveal(vault);
vaultService.reveal(vault, p -> application.getHostServices().showDocument(p.toUri().toString()));
}
case IGNORE -> Platform.runLater(window::close);
}