Browse Source

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

Armin Schrenk 4 years ago
parent
commit
d5eb84a000

+ 4 - 11
main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java

@@ -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;

+ 0 - 2
main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java

@@ -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() {

+ 1 - 1
main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java

@@ -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

+ 1 - 2
main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuComponent.java

@@ -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();

+ 5 - 2
main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java

@@ -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) {

+ 27 - 0
main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuModule.java

@@ -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.");
+			}
+		};
+	}
+}

+ 5 - 2
main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockSuccessController.java

@@ -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);

File diff suppressed because it is too large
+ 5 - 2
main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java