~exprez135/cryptomator-libre

a2816277bf2ed6523edf206a3f47a1d4e5c6a207 — Martin Beyer 1 year, 6 months ago e37f1f9
Refactor unlock Window in preparation of #1203

M main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultSuccessController.java => main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultSuccessController.java +2 -1
@@ 9,6 9,7 @@ import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.fxapp.FxApplication;

import javax.inject.Inject;
import java.util.Optional;

@AddVaultWizardScoped
public class AddVaultSuccessController implements FxController {


@@ 27,7 28,7 @@ public class AddVaultSuccessController implements FxController {
	@FXML
	public void unlockAndClose() {
		close();
		fxApplication.startUnlockWorkflow(vault.get());
		fxApplication.startUnlockWorkflow(vault.get(), Optional.of(window));
	}

	@FXML

M main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java => main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java +2 -2
@@ 96,9 96,9 @@ public class FxApplication extends Application {
		});
	}

	public void startUnlockWorkflow(Vault vault) {
	public void startUnlockWorkflow(Vault vault, Optional<Stage> owner) {
		Platform.runLater(() -> {
			unlockWindowBuilderProvider.get().vault(vault).build().startUnlockWorkflow();
			unlockWindowBuilderProvider.get().vault(vault).owner(owner).build().startUnlockWorkflow();
			LOG.debug("Showing UnlockWindow for {}", vault.getDisplayableName());
		});
	}

M main/ui/src/main/java/org/cryptomator/ui/launcher/UiLauncher.java => main/ui/src/main/java/org/cryptomator/ui/launcher/UiLauncher.java +3 -3
@@ 65,15 65,15 @@ public class UiLauncher {
		Collection<Vault> vaultsToAutoUnlock = vaults.filtered(this::shouldAttemptAutoUnlock);
		if (!vaultsToAutoUnlock.isEmpty()) {
			fxApplicationStarter.get(hasTrayIcon).thenAccept(app -> {
				for (Vault vault : vaultsToAutoUnlock){
					app.startUnlockWorkflow(vault);
				for (Vault vault : vaultsToAutoUnlock) {
					app.startUnlockWorkflow(vault, Optional.empty());
				}
			});
		}

		launchEventHandler.startHandlingLaunchEvents(hasTrayIcon);
	}
	

	private boolean shouldAttemptAutoUnlock(Vault vault) {
		return vault.isLocked() && vault.getVaultSettings().unlockAfterStartup().get();
	}

M main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailLockedController.java => main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailLockedController.java +5 -2
@@ 5,6 5,7 @@ import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.fxml.FXML;
import javafx.stage.Stage;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.keychain.KeychainManager;
import org.cryptomator.ui.common.FxController;


@@ 22,14 23,16 @@ public class VaultDetailLockedController implements FxController {
	private final FxApplication application;
	private final VaultOptionsComponent.Builder vaultOptionsWindow;
	private final Optional<KeychainManager> keychainManagerOptional;
	private final Stage mainWindow;
	private final BooleanExpression passwordSaved;

	@Inject
	VaultDetailLockedController(ObjectProperty<Vault> vault, FxApplication application, VaultOptionsComponent.Builder vaultOptionsWindow, Optional<KeychainManager> keychainManagerOptional) {
	VaultDetailLockedController(ObjectProperty<Vault> vault, FxApplication application, VaultOptionsComponent.Builder vaultOptionsWindow, Optional<KeychainManager> keychainManagerOptional, @MainWindow Stage mainWindow) {
		this.vault = vault;
		this.application = application;
		this.vaultOptionsWindow = vaultOptionsWindow;
		this.keychainManagerOptional = keychainManagerOptional;
		this.mainWindow = mainWindow;
		if (keychainManagerOptional.isPresent()) {
			this.passwordSaved = BooleanExpression.booleanExpression(EasyBind.select(vault).selectObject(v -> keychainManagerOptional.get().getPassphraseStoredProperty(v.getId())));
		} else {


@@ 39,7 42,7 @@ public class VaultDetailLockedController implements FxController {

	@FXML
	public void unlock() {
		application.startUnlockWorkflow(vault.get());
		application.startUnlockWorkflow(vault.get(), Optional.of(mainWindow));
	}

	@FXML

M main/ui/src/main/java/org/cryptomator/ui/migration/MigrationSuccessController.java => main/ui/src/main/java/org/cryptomator/ui/migration/MigrationSuccessController.java +6 -2
@@ 5,8 5,10 @@ import javafx.stage.Stage;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.fxapp.FxApplication;
import org.cryptomator.ui.mainwindow.MainWindow;

import javax.inject.Inject;
import java.util.Optional;

@MigrationScoped
public class MigrationSuccessController implements FxController {


@@ 14,18 16,20 @@ public class MigrationSuccessController implements FxController {
	private final FxApplication fxApplication;
	private final Stage window;
	private final Vault vault;
	private final Stage mainWindow;

	@Inject
	MigrationSuccessController(FxApplication fxApplication, @MigrationWindow Stage window, @MigrationWindow Vault vault) {
	MigrationSuccessController(FxApplication fxApplication, @MigrationWindow Stage window, @MigrationWindow Vault vault, @MainWindow Stage mainWindow) {
		this.fxApplication = fxApplication;
		this.window = window;
		this.vault = vault;
		this.mainWindow = mainWindow;
	}

	@FXML
	public void unlockAndClose() {
		close();
		fxApplication.startUnlockWorkflow(vault);
		fxApplication.startUnlockWorkflow(vault, Optional.of(mainWindow));
	}

	@FXML

M main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java => main/ui/src/main/java/org/cryptomator/ui/traymenu/TrayMenuController.java +2 -1
@@ 15,6 15,7 @@ import java.awt.PopupMenu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.function.Consumer;



@@ 103,7 104,7 @@ class TrayMenuController {
	}

	private void unlockVault(Vault vault) {
		fxApplicationStarter.get(true).thenAccept(app -> app.startUnlockWorkflow(vault));
		fxApplicationStarter.get(true).thenAccept(app -> app.startUnlockWorkflow(vault, Optional.empty()));
	}

	private void lockVault(Vault vault) {

M main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockComponent.java => main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockComponent.java +7 -8
@@ 6,18 6,14 @@
package org.cryptomator.ui.unlock;

import dagger.BindsInstance;
import dagger.Lazy;
import dagger.Subcomponent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.cryptomator.ui.common.FxmlFile;
import org.cryptomator.ui.common.FxmlScene;
import org.cryptomator.common.vaults.Vault;

import java.util.concurrent.Executor;
import javax.inject.Named;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

@UnlockScoped
@Subcomponent(modules = {UnlockModule.class})


@@ 26,7 22,7 @@ public interface UnlockComponent {
	ExecutorService defaultExecutorService();

	UnlockWorkflow unlockWorkflow();
	

	default Future<Boolean> startUnlockWorkflow() {
		UnlockWorkflow workflow = unlockWorkflow();
		defaultExecutorService().submit(workflow);


@@ 35,10 31,13 @@ public interface UnlockComponent {

	@Subcomponent.Builder
	interface Builder {
		

		@BindsInstance
		Builder vault(@UnlockWindow Vault vault);

		@BindsInstance
		Builder owner(@Named("unlockWindowOwner") Optional<Stage> owner);

		UnlockComponent build();
	}


M main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java => main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java +8 -3
@@ 56,7 56,7 @@ abstract class UnlockModule {
			}
		});
	}
	

	@Provides
	@UnlockScoped
	static AtomicReference<char[]> providePassword(@Named("savedPassword") Optional<char[]> storedPassword) {


@@ 80,11 80,16 @@ abstract class UnlockModule {
	@Provides
	@UnlockWindow
	@UnlockScoped
	static Stage provideStage(StageFactory factory, @UnlockWindow Vault vault) {
	static Stage provideStage(StageFactory factory, @UnlockWindow Vault vault, @Named("unlockWindowOwner") Optional<Stage> owner) {
		Stage stage = factory.create();
		stage.setTitle(vault.getDisplayableName());
		stage.setResizable(false);
		stage.initModality(Modality.APPLICATION_MODAL);
		if (owner.isPresent()) {
			stage.initOwner(owner.get());
			stage.initModality(Modality.WINDOW_MODAL);
		} else {
			stage.initModality(Modality.APPLICATION_MODAL);
		}
		return stage;
	}