mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-08-01 11:08:23 -04:00
show dialog on VaultCreationEvent
Signed-off-by: Armin Schrenk <armin.schrenk@skymatic.de>
This commit is contained in:
@@ -69,16 +69,10 @@ class AppLaunchEventHandler {
|
||||
switch (event) {
|
||||
case RevealRunningEvent _ -> appWindows.showMainWindow();
|
||||
case OpenFileEvent openFileEvent -> openFileEvent.pathsToOpen().forEach(this::openPotentialVault);
|
||||
case VaultCreationEvent vaultCreationEvent -> handleVaultCreation(vaultCreationEvent);
|
||||
case VaultCreationEvent vaultCreationEvent -> appWindows.showImportTemplateWindow(vaultCreationEvent.name(), vaultCreationEvent.template());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleVaultCreation(VaultCreationEvent event) {
|
||||
// TODO (deeplink step 5): open the dedicated vault-creation dialog via appWindows
|
||||
LOG.warn("Received vault-creation deeplink for '{}', but handling is not yet implemented.", event.name());
|
||||
appWindows.showMainWindow();
|
||||
}
|
||||
|
||||
// TODO deduplicate MainWindowController...
|
||||
private void openPotentialVault(Path path) {
|
||||
Path potentialVaultPath = path.getFileName().toString().endsWith(CRYPTOMATOR_FILENAME_EXT) ? path.getParent() : path;
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.cryptomator.ui.dialogs.Dialogs;
|
||||
import org.cryptomator.ui.dialogs.SimpleDialog;
|
||||
import org.cryptomator.ui.error.ErrorComponent;
|
||||
import org.cryptomator.ui.eventview.EventViewComponent;
|
||||
import org.cryptomator.ui.importtemplate.ImportTemplateComponent;
|
||||
import org.cryptomator.ui.lock.LockComponent;
|
||||
import org.cryptomator.ui.mainwindow.MainWindowComponent;
|
||||
import org.cryptomator.ui.notification.NotificationComponent;
|
||||
@@ -60,6 +61,7 @@ public class FxApplicationWindows {
|
||||
private final ExecutorService executor;
|
||||
private final VaultOptionsComponent.Factory vaultOptionsWindow;
|
||||
private final ShareVaultComponent.Factory shareVaultWindow;
|
||||
private final ImportTemplateComponent.Factory importTemplateWindow;
|
||||
private final FilteredList<Window> visibleWindows;
|
||||
private final Dialogs dialogs;
|
||||
|
||||
@@ -75,6 +77,7 @@ public class FxApplicationWindows {
|
||||
ErrorComponent.Factory errorWindowFactory, //
|
||||
VaultOptionsComponent.Factory vaultOptionsWindow, //
|
||||
ShareVaultComponent.Factory shareVaultWindow, //
|
||||
ImportTemplateComponent.Factory importTemplateWindow, //
|
||||
EventViewComponent.Factory eventViewWindowFactory, //
|
||||
NotificationComponent.Factory notificationWindowFactory, //
|
||||
ExecutorService executor, //
|
||||
@@ -93,6 +96,7 @@ public class FxApplicationWindows {
|
||||
this.executor = executor;
|
||||
this.vaultOptionsWindow = vaultOptionsWindow;
|
||||
this.shareVaultWindow = shareVaultWindow;
|
||||
this.importTemplateWindow = importTemplateWindow;
|
||||
this.visibleWindows = Window.getWindows().filtered(Window::isShowing);
|
||||
this.dialogs = dialogs;
|
||||
}
|
||||
@@ -144,6 +148,14 @@ public class FxApplicationWindows {
|
||||
CompletableFuture.runAsync(() -> shareVaultWindow.create(vault).showShareVaultWindow(), Platform::runLater);
|
||||
}
|
||||
|
||||
public CompletionStage<Stage> showImportTemplateWindow(String name, byte[] template) {
|
||||
return showMainWindow().thenApplyAsync(_ -> {
|
||||
var component = importTemplateWindow.create(name, template);
|
||||
component.showImportTemplateWindow();
|
||||
return component.window();
|
||||
}, Platform::runLater).whenComplete(this::reportErrors);
|
||||
}
|
||||
|
||||
public CompletionStage<Stage> showVaultOptionsWindow(Vault vault, SelectedVaultOptionsTab tab) {
|
||||
return showMainWindow().thenApplyAsync(_ -> vaultOptionsWindow.create(vault).showVaultOptionsWindow(tab), Platform::runLater) //
|
||||
.whenComplete(this::reportErrors);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.cryptomator.ui.fxapp;
|
||||
|
||||
import org.cryptomator.common.vaults.VaultListManager;
|
||||
import org.cryptomator.launcher.AppLaunchEvent;
|
||||
import org.cryptomator.launcher.RevealRunningEvent;
|
||||
import org.cryptomator.launcher.VaultCreationEvent;
|
||||
import org.cryptomator.ui.common.VaultService;
|
||||
import org.cryptomator.ui.dialogs.Dialogs;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javafx.stage.Stage;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.timeout;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class AppLaunchEventHandlerTest {
|
||||
|
||||
private BlockingQueue<AppLaunchEvent> queue;
|
||||
private ExecutorService executor;
|
||||
private FxApplicationWindows appWindows;
|
||||
private AppLaunchEventHandler handler;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
queue = new LinkedBlockingQueue<>();
|
||||
executor = Executors.newSingleThreadExecutor();
|
||||
appWindows = mock(FxApplicationWindows.class);
|
||||
handler = new AppLaunchEventHandler(queue, executor, appWindows, mock(VaultListManager.class), mock(VaultService.class), mock(Stage.class), mock(Dialogs.class));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void teardown() {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("a VaultCreationEvent opens the import-template window with name and template")
|
||||
public void testVaultCreationEventOpensImportTemplateWindow() {
|
||||
var template = new byte[]{1, 2, 3};
|
||||
queue.add(new VaultCreationEvent("MyVault", template));
|
||||
|
||||
handler.startHandlingLaunchEvents();
|
||||
|
||||
verify(appWindows, timeout(2000)).showImportTemplateWindow("MyVault", template);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("a RevealRunningEvent reveals the main window")
|
||||
public void testRevealRunningEventShowsMainWindow() {
|
||||
queue.add(new RevealRunningEvent());
|
||||
|
||||
handler.startHandlingLaunchEvents();
|
||||
|
||||
verify(appWindows, timeout(2000)).showMainWindow();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user