dedup by setting title when setting the scene

This commit is contained in:
Sebastian Stenzel
2022-01-19 19:08:54 +01:00
parent 9440fb186f
commit d52e59d7a4
3 changed files with 11 additions and 24 deletions
@@ -2,16 +2,13 @@ package org.cryptomator.ui.keyloading.masterkeyfile;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.ui.common.DefaultSceneFactory; import org.cryptomator.ui.common.DefaultSceneFactory;
import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlFile;
import org.cryptomator.ui.common.FxmlLoaderFactory; import org.cryptomator.ui.common.FxmlLoaderFactory;
import org.cryptomator.ui.keyloading.KeyLoading;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.nio.file.Path; import java.nio.file.Path;
@@ -29,21 +26,15 @@ interface ChooseMasterkeyFileModule {
@Provides @Provides
@ChooseMasterkeyFileScoped @ChooseMasterkeyFileScoped
static Scene provideChooseMasterkeyScene(ChooseMasterkeyFileController controller, DefaultSceneFactory sceneFactory, ResourceBundle resourceBundle, @KeyLoading Stage window, @KeyLoading Vault v) { static Scene provideChooseMasterkeyScene(ChooseMasterkeyFileController controller, DefaultSceneFactory sceneFactory, ResourceBundle resourceBundle) {
// TODO: simplify FxmlLoaderFactory // TODO: simplify FxmlLoaderFactory
try { try {
var url = FxmlLoaderFactory.class.getResource(FxmlFile.UNLOCK_SELECT_MASTERKEYFILE.getRessourcePathString()); var url = FxmlLoaderFactory.class.getResource(FxmlFile.UNLOCK_SELECT_MASTERKEYFILE.getRessourcePathString());
var loader = new FXMLLoader(url, resourceBundle, null, clazz -> controller); var loader = new FXMLLoader(url, resourceBundle, null, clazz -> controller);
Parent root = loader.load(); Parent root = loader.load();
var scene = sceneFactory.apply(root); return sceneFactory.apply(root);
scene.windowProperty().addListener((prop, oldVal, newVal) -> {
if (window.equals(newVal)) {
window.setTitle(String.format(resourceBundle.getString("unlock.chooseMasterkey.title"), v.getDisplayName()));
}
});
return scene;
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException("Failed to load UnlockScene", e); throw new UncheckedIOException("Failed to load ChooseMasterkeyScene", e);
} }
} }
@@ -25,6 +25,7 @@ import java.net.URI;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Optional; import java.util.Optional;
import java.util.ResourceBundle;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@@ -39,19 +40,21 @@ public class MasterkeyFileLoadingStrategy implements KeyLoadingStrategy {
private final PassphraseEntryComponent.Builder passphraseEntry; private final PassphraseEntryComponent.Builder passphraseEntry;
private final ChooseMasterkeyFileComponent.Builder masterkeyFileChoice; private final ChooseMasterkeyFileComponent.Builder masterkeyFileChoice;
private final KeychainManager keychain; private final KeychainManager keychain;
private final ResourceBundle resourceBundle;
private Passphrase passphrase; private Passphrase passphrase;
private boolean savePassphrase; private boolean savePassphrase;
private boolean wrongPassphrase; private boolean wrongPassphrase;
@Inject @Inject
public MasterkeyFileLoadingStrategy(@KeyLoading Vault vault, MasterkeyFileAccess masterkeyFileAccess, @KeyLoading Stage window, @Named("savedPassword") Optional<char[]> savedPassphrase, PassphraseEntryComponent.Builder passphraseEntry, ChooseMasterkeyFileComponent.Builder masterkeyFileChoice, KeychainManager keychain) { public MasterkeyFileLoadingStrategy(@KeyLoading Vault vault, MasterkeyFileAccess masterkeyFileAccess, @KeyLoading Stage window, @Named("savedPassword") Optional<char[]> savedPassphrase, PassphraseEntryComponent.Builder passphraseEntry, ChooseMasterkeyFileComponent.Builder masterkeyFileChoice, KeychainManager keychain, ResourceBundle resourceBundle) {
this.vault = vault; this.vault = vault;
this.masterkeyFileAccess = masterkeyFileAccess; this.masterkeyFileAccess = masterkeyFileAccess;
this.window = window; this.window = window;
this.passphraseEntry = passphraseEntry; this.passphraseEntry = passphraseEntry;
this.masterkeyFileChoice = masterkeyFileChoice; this.masterkeyFileChoice = masterkeyFileChoice;
this.keychain = keychain; this.keychain = keychain;
this.resourceBundle = resourceBundle;
this.passphrase = savedPassphrase.map(Passphrase::new).orElse(null); this.passphrase = savedPassphrase.map(Passphrase::new).orElse(null);
this.savePassphrase = savedPassphrase.isPresent(); this.savePassphrase = savedPassphrase.isPresent();
} }
@@ -121,6 +124,7 @@ public class MasterkeyFileLoadingStrategy implements KeyLoadingStrategy {
var comp = masterkeyFileChoice.build(); var comp = masterkeyFileChoice.build();
Platform.runLater(() -> { Platform.runLater(() -> {
window.setScene(comp.chooseMasterkeyScene()); window.setScene(comp.chooseMasterkeyScene());
window.setTitle(resourceBundle.getString("unlock.chooseMasterkey.title").formatted(vault.getDisplayName()));
window.show(); window.show();
Window owner = window.getOwner(); Window owner = window.getOwner();
if (owner != null) { if (owner != null) {
@@ -143,6 +147,7 @@ public class MasterkeyFileLoadingStrategy implements KeyLoadingStrategy {
var comp = passphraseEntry.savedPassword(passphrase).build(); var comp = passphraseEntry.savedPassword(passphrase).build();
Platform.runLater(() -> { Platform.runLater(() -> {
window.setScene(comp.passphraseEntryScene()); window.setScene(comp.passphraseEntryScene());
window.setTitle(resourceBundle.getString("unlock.title").formatted(vault.getDisplayName()));
window.show(); window.show();
Window owner = window.getOwner(); Window owner = window.getOwner();
if (owner != null) { if (owner != null) {
@@ -2,16 +2,13 @@ package org.cryptomator.ui.keyloading.masterkeyfile;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.ui.common.DefaultSceneFactory; import org.cryptomator.ui.common.DefaultSceneFactory;
import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlFile;
import org.cryptomator.ui.common.FxmlLoaderFactory; import org.cryptomator.ui.common.FxmlLoaderFactory;
import org.cryptomator.ui.keyloading.KeyLoading;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@@ -28,19 +25,13 @@ interface PassphraseEntryModule {
@Provides @Provides
@PassphraseEntryScoped @PassphraseEntryScoped
static Scene provideUnlockScene(PassphraseEntryController controller, DefaultSceneFactory sceneFactory, ResourceBundle resourceBundle, @KeyLoading Stage window, @KeyLoading Vault v) { static Scene provideUnlockScene(PassphraseEntryController controller, DefaultSceneFactory sceneFactory, ResourceBundle resourceBundle) {
// TODO: simplify FxmlLoaderFactory // TODO: simplify FxmlLoaderFactory
try { try {
var url = FxmlLoaderFactory.class.getResource(FxmlFile.UNLOCK_ENTER_PASSWORD.getRessourcePathString()); var url = FxmlLoaderFactory.class.getResource(FxmlFile.UNLOCK_ENTER_PASSWORD.getRessourcePathString());
var loader = new FXMLLoader(url, resourceBundle, null, clazz -> controller); var loader = new FXMLLoader(url, resourceBundle, null, clazz -> controller);
Parent root = loader.load(); Parent root = loader.load();
var scene = sceneFactory.apply(root); return sceneFactory.apply(root);
scene.windowProperty().addListener((prop, oldVal, newVal) -> {
if (window.equals(newVal)) {
window.setTitle(String.format(resourceBundle.getString("unlock.title"), v.getDisplayName()));
}
});
return scene;
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException("Failed to load UnlockScene", e); throw new UncheckedIOException("Failed to load UnlockScene", e);
} }