From c8a6b7cf139fc585ff9983d8a9ab481a0e49b713 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 15 Jul 2026 16:34:38 +0200 Subject: [PATCH] show dialog on VaultCreationEvent Signed-off-by: Armin Schrenk --- .../ui/fxapp/AppLaunchEventHandler.java | 8 +-- .../ui/fxapp/FxApplicationWindows.java | 12 ++++ .../ui/fxapp/AppLaunchEventHandlerTest.java | 65 +++++++++++++++++++ 3 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 src/test/java/org/cryptomator/ui/fxapp/AppLaunchEventHandlerTest.java diff --git a/src/main/java/org/cryptomator/ui/fxapp/AppLaunchEventHandler.java b/src/main/java/org/cryptomator/ui/fxapp/AppLaunchEventHandler.java index 61f299cac..ea85e6c3e 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/AppLaunchEventHandler.java +++ b/src/main/java/org/cryptomator/ui/fxapp/AppLaunchEventHandler.java @@ -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; diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java index f80b6de0e..582bf27dd 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java @@ -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 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 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 showVaultOptionsWindow(Vault vault, SelectedVaultOptionsTab tab) { return showMainWindow().thenApplyAsync(_ -> vaultOptionsWindow.create(vault).showVaultOptionsWindow(tab), Platform::runLater) // .whenComplete(this::reportErrors); diff --git a/src/test/java/org/cryptomator/ui/fxapp/AppLaunchEventHandlerTest.java b/src/test/java/org/cryptomator/ui/fxapp/AppLaunchEventHandlerTest.java new file mode 100644 index 000000000..32a58107d --- /dev/null +++ b/src/test/java/org/cryptomator/ui/fxapp/AppLaunchEventHandlerTest.java @@ -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 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(); + } + +}