From 92bf73297a53d017c9191673dccdbc95927e87c9 Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Tue, 11 Jun 2024 14:43:56 +0200 Subject: [PATCH 1/8] add dokany info dialog --- .../org/cryptomator/ui/common/FxmlFile.java | 1 + .../DokanyInfoDialogComponent.java | 34 +++++++++++ .../DokanyInfoDialogController.java | 33 +++++++++++ .../DokanyInfoDialogModule.java | 57 +++++++++++++++++++ .../DokanyInfoDialogScoped.java | 13 +++++ .../DokanyInfoDialogWindow.java | 14 +++++ .../cryptomator/ui/fxapp/FxApplication.java | 18 ++++++ .../ui/fxapp/FxApplicationModule.java | 2 + .../ui/fxapp/FxApplicationWindows.java | 11 +++- src/main/resources/fxml/dokany_info.fxml | 53 +++++++++++++++++ src/main/resources/i18n/strings.properties | 5 ++ 11 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogComponent.java create mode 100644 src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogController.java create mode 100644 src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogModule.java create mode 100644 src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogScoped.java create mode 100644 src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogWindow.java create mode 100644 src/main/resources/fxml/dokany_info.fxml diff --git a/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/src/main/java/org/cryptomator/ui/common/FxmlFile.java index 1a2374f85..c8529a8b6 100644 --- a/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -12,6 +12,7 @@ public enum FxmlFile { CONVERTVAULT_HUBTOPASSWORD_START("/fxml/convertvault_hubtopassword_start.fxml"), // CONVERTVAULT_HUBTOPASSWORD_CONVERT("/fxml/convertvault_hubtopassword_convert.fxml"), // CONVERTVAULT_HUBTOPASSWORD_SUCCESS("/fxml/convertvault_hubtopassword_success.fxml"), // + DOKANY_INFO_DIALOG("/fxml/dokany_info.fxml"), // ERROR("/fxml/error.fxml"), // FORGET_PASSWORD("/fxml/forget_password.fxml"), // HEALTH_START("/fxml/health_start.fxml"), // diff --git a/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogComponent.java b/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogComponent.java new file mode 100644 index 000000000..4c4f3b552 --- /dev/null +++ b/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogComponent.java @@ -0,0 +1,34 @@ +package org.cryptomator.ui.dokanyinfodialog; + +import dagger.Lazy; +import dagger.Subcomponent; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; + +import javafx.scene.Scene; +import javafx.stage.Stage; + +@DokanyInfoDialogScoped +@Subcomponent(modules = {DokanyInfoDialogModule.class}) +public interface DokanyInfoDialogComponent { + + @DokanyInfoDialogWindow + Stage window(); + + @FxmlScene(FxmlFile.DOKANY_INFO_DIALOG) + Lazy dokanyInfoScene(); + + + default void showDokanyInfoWindow() { + Stage stage = window(); + stage.setScene(dokanyInfoScene().get()); + stage.sizeToScene(); + stage.show(); + } + + @Subcomponent.Factory + interface Factory { + + DokanyInfoDialogComponent create(); + } +} \ No newline at end of file diff --git a/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogController.java b/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogController.java new file mode 100644 index 000000000..06f4f34d6 --- /dev/null +++ b/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogController.java @@ -0,0 +1,33 @@ +package org.cryptomator.ui.dokanyinfodialog; + +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.fxapp.FxApplicationWindows; +import org.cryptomator.ui.preferences.SelectedPreferencesTab; + +import javax.inject.Inject; +import javafx.fxml.FXML; +import javafx.stage.Stage; + + +@DokanyInfoDialogScoped +public class DokanyInfoDialogController implements FxController { + + private final Stage window; + private final FxApplicationWindows applicationWindows; + + @Inject + DokanyInfoDialogController(@DokanyInfoDialogWindow Stage window, FxApplicationWindows applicationWindows) { + this.window = window; + this.applicationWindows = applicationWindows; + } + + @FXML + public void close() { + window.close(); + } + + public void openVolumePreferences() { + applicationWindows.showPreferencesWindow(SelectedPreferencesTab.VOLUME); + } + +} \ No newline at end of file diff --git a/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogModule.java b/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogModule.java new file mode 100644 index 000000000..ec6817a2f --- /dev/null +++ b/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogModule.java @@ -0,0 +1,57 @@ +package org.cryptomator.ui.dokanyinfodialog; + +import dagger.Binds; +import dagger.Module; +import dagger.Provides; +import dagger.multibindings.IntoMap; +import org.cryptomator.ui.common.DefaultSceneFactory; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxControllerKey; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlLoaderFactory; +import org.cryptomator.ui.common.FxmlScene; +import org.cryptomator.ui.common.StageFactory; + +import javax.inject.Provider; +import javafx.scene.Scene; +import javafx.stage.Modality; +import javafx.stage.Stage; +import java.util.Map; +import java.util.ResourceBundle; + +@Module +abstract class DokanyInfoDialogModule { + + @Provides + @DokanyInfoDialogWindow + @DokanyInfoDialogScoped + static FxmlLoaderFactory provideFxmlLoaderFactory(Map, Provider> factories, DefaultSceneFactory sceneFactory, ResourceBundle resourceBundle) { + return new FxmlLoaderFactory(factories, sceneFactory, resourceBundle); + } + + @Provides + @DokanyInfoDialogWindow + @DokanyInfoDialogScoped + static Stage provideStage(StageFactory factory, ResourceBundle resourceBundle) { + Stage stage = factory.create(); + stage.setTitle(resourceBundle.getString("dokanyInfo.title")); + stage.setMinWidth(500); + stage.setMinHeight(100); + stage.initModality(Modality.APPLICATION_MODAL); + return stage; + } + + @Provides + @FxmlScene(FxmlFile.DOKANY_INFO_DIALOG) + @DokanyInfoDialogScoped + static Scene provideDokanyInfoDialogScene(@DokanyInfoDialogWindow FxmlLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene(FxmlFile.DOKANY_INFO_DIALOG); + } + + + @Binds + @IntoMap + @FxControllerKey(DokanyInfoDialogController.class) + abstract FxController bindDokanyInfoDialogController(DokanyInfoDialogController controller); + +} diff --git a/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogScoped.java b/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogScoped.java new file mode 100644 index 000000000..adb721cac --- /dev/null +++ b/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogScoped.java @@ -0,0 +1,13 @@ +package org.cryptomator.ui.dokanyinfodialog; + +import javax.inject.Scope; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Scope +@Documented +@Retention(RetentionPolicy.RUNTIME) +@interface DokanyInfoDialogScoped { + +} diff --git a/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogWindow.java b/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogWindow.java new file mode 100644 index 000000000..ac3b9544e --- /dev/null +++ b/src/main/java/org/cryptomator/ui/dokanyinfodialog/DokanyInfoDialogWindow.java @@ -0,0 +1,14 @@ +package org.cryptomator.ui.dokanyinfodialog; + +import javax.inject.Qualifier; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Qualifier +@Documented +@Retention(RUNTIME) +@interface DokanyInfoDialogWindow { + +} diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java index 711a0fa44..605411748 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java @@ -3,6 +3,7 @@ package org.cryptomator.ui.fxapp; import dagger.Lazy; import org.cryptomator.common.Environment; import org.cryptomator.common.settings.Settings; +import org.cryptomator.common.settings.VaultSettings; import org.cryptomator.ui.traymenu.TrayMenuComponent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,6 +76,23 @@ public class FxApplication { appWindows.checkAndShowUpdateReminderWindow(); } + var dokany = "org.cryptomator.frontend.dokany.mount.DokanyMountProvider"; + boolean dokanyInfoWindowShown = false; + if (settings.mountService.getValueSafe().equals(dokany)) { + appWindows.showDokanyInfoWindow(); + dokanyInfoWindowShown = true; + settings.mountService.set(null); + } + for (VaultSettings vaultSettings : settings.directories) { + if (vaultSettings.mountService.getValueSafe().equals(dokany)) { + if (!dokanyInfoWindowShown) { + appWindows.showDokanyInfoWindow(); + dokanyInfoWindowShown = true; + } + vaultSettings.mountService.set(null); + } + } + launchEventHandler.startHandlingLaunchEvents(); autoUnlocker.tryUnlockForTimespan(2, TimeUnit.MINUTES); } diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java index af98e284c..d6734a3a3 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java @@ -7,6 +7,7 @@ package org.cryptomator.ui.fxapp; import dagger.Module; import dagger.Provides; +import org.cryptomator.ui.dokanyinfodialog.DokanyInfoDialogComponent; import org.cryptomator.ui.error.ErrorComponent; import org.cryptomator.ui.health.HealthCheckComponent; import org.cryptomator.ui.lock.LockComponent; @@ -33,6 +34,7 @@ import java.io.InputStream; ErrorComponent.class, // HealthCheckComponent.class, // UpdateReminderComponent.class, // + DokanyInfoDialogComponent.class, // ShareVaultComponent.class}) abstract class FxApplicationModule { diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java index 41a7ca785..9e0f11abf 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java @@ -5,6 +5,7 @@ import dagger.Lazy; import org.cryptomator.common.vaults.Vault; import org.cryptomator.common.vaults.VaultState; import org.cryptomator.integrations.tray.TrayIntegrationProvider; +import org.cryptomator.ui.dokanyinfodialog.DokanyInfoDialogComponent; import org.cryptomator.ui.error.ErrorComponent; import org.cryptomator.ui.lock.LockComponent; import org.cryptomator.ui.mainwindow.MainWindowComponent; @@ -48,6 +49,7 @@ public class FxApplicationWindows { private final QuitComponent.Builder quitWindowBuilder; private final UnlockComponent.Factory unlockWorkflowFactory; private final UpdateReminderComponent.Factory updateReminderWindowBuilder; + private final DokanyInfoDialogComponent.Factory dokanyInfoWindowBuilder; private final LockComponent.Factory lockWorkflowFactory; private final ErrorComponent.Factory errorWindowFactory; private final ExecutorService executor; @@ -56,13 +58,14 @@ public class FxApplicationWindows { private final FilteredList visibleWindows; @Inject - public FxApplicationWindows(@PrimaryStage Stage primaryStage, + public FxApplicationWindows(@PrimaryStage Stage primaryStage, // Optional trayIntegration, // Lazy mainWindow, // Lazy preferencesWindow, // QuitComponent.Builder quitWindowBuilder, // UnlockComponent.Factory unlockWorkflowFactory, // UpdateReminderComponent.Factory updateReminderWindowBuilder, // + DokanyInfoDialogComponent.Factory dokanyInfoWindowBuilder, // LockComponent.Factory lockWorkflowFactory, // ErrorComponent.Factory errorWindowFactory, // VaultOptionsComponent.Factory vaultOptionsWindow, // @@ -75,6 +78,7 @@ public class FxApplicationWindows { this.quitWindowBuilder = quitWindowBuilder; this.unlockWorkflowFactory = unlockWorkflowFactory; this.updateReminderWindowBuilder = updateReminderWindowBuilder; + this.dokanyInfoWindowBuilder = dokanyInfoWindowBuilder; this.lockWorkflowFactory = lockWorkflowFactory; this.errorWindowFactory = errorWindowFactory; this.executor = executor; @@ -142,6 +146,11 @@ public class FxApplicationWindows { CompletableFuture.runAsync(() -> updateReminderWindowBuilder.create().checkAndShowUpdateReminderWindow(), Platform::runLater); } + public void showDokanyInfoWindow() { + CompletableFuture.runAsync(() -> dokanyInfoWindowBuilder.create().showDokanyInfoWindow(), Platform::runLater); + } + + public CompletionStage startUnlockWorkflow(Vault vault, @Nullable Stage owner) { return CompletableFuture.supplyAsync(() -> { Preconditions.checkState(vault.stateProperty().transition(VaultState.Value.LOCKED, VaultState.Value.PROCESSING), "Vault not locked."); diff --git a/src/main/resources/fxml/dokany_info.fxml b/src/main/resources/fxml/dokany_info.fxml new file mode 100644 index 000000000..abf44a074 --- /dev/null +++ b/src/main/resources/fxml/dokany_info.fxml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +