From b791df01f70f89122e524745f06dd45f4fc0bef3 Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Thu, 30 Jun 2022 15:41:33 +0200 Subject: [PATCH] removed quitforced package, moved QuitForcedController into quit package and deleted not required files --- src/main/java/module-info.java | 1 - .../ui/fxapp/FxApplicationModule.java | 10 +--- .../ui/fxapp/FxApplicationTerminator.java | 4 +- .../ui/fxapp/FxApplicationWindows.java | 21 ++++--- .../cryptomator/ui/quit/QuitComponent.java | 24 +++++--- .../cryptomator/ui/quit/QuitController.java | 2 +- .../QuitForcedController.java | 5 +- .../org/cryptomator/ui/quit/QuitModule.java | 13 +++++ .../ui/quitforced/QuitForcedComponent.java | 44 -------------- .../ui/quitforced/QuitForcedModule.java | 58 ------------------- .../ui/quitforced/QuitForcedScoped.java | 13 ----- .../ui/quitforced/QuitForcedWindow.java | 14 ----- src/main/resources/fxml/quit_forced.fxml | 2 +- 13 files changed, 49 insertions(+), 162 deletions(-) rename src/main/java/org/cryptomator/ui/{quitforced => quit}/QuitForcedController.java (93%) delete mode 100644 src/main/java/org/cryptomator/ui/quitforced/QuitForcedComponent.java delete mode 100644 src/main/java/org/cryptomator/ui/quitforced/QuitForcedModule.java delete mode 100644 src/main/java/org/cryptomator/ui/quitforced/QuitForcedScoped.java delete mode 100644 src/main/java/org/cryptomator/ui/quitforced/QuitForcedWindow.java diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 0d2c141b7..dd3d7680b 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -51,7 +51,6 @@ module org.cryptomator.desktop { opens org.cryptomator.ui.migration to javafx.fxml; opens org.cryptomator.ui.preferences to javafx.fxml; opens org.cryptomator.ui.quit to javafx.fxml; - opens org.cryptomator.ui.quitforced to javafx.fxml; opens org.cryptomator.ui.recoverykey to javafx.fxml; opens org.cryptomator.ui.removevault to javafx.fxml; opens org.cryptomator.ui.stats to javafx.fxml; diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java index 007e62fd6..81429181a 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java @@ -14,7 +14,7 @@ import org.cryptomator.ui.lock.LockComponent; import org.cryptomator.ui.mainwindow.MainWindowComponent; import org.cryptomator.ui.preferences.PreferencesComponent; import org.cryptomator.ui.quit.QuitComponent; -import org.cryptomator.ui.quitforced.QuitForcedComponent; + import org.cryptomator.ui.traymenu.TrayMenuComponent; import org.cryptomator.ui.unlock.UnlockComponent; @@ -26,7 +26,7 @@ import java.io.UncheckedIOException; import java.util.Collections; import java.util.List; -@Module(includes = {UpdateCheckerModule.class}, subcomponents = {TrayMenuComponent.class, MainWindowComponent.class, PreferencesComponent.class, UnlockComponent.class, LockComponent.class, QuitComponent.class, QuitForcedComponent.class, ErrorComponent.class}) +@Module(includes = {UpdateCheckerModule.class}, subcomponents = {TrayMenuComponent.class, MainWindowComponent.class, PreferencesComponent.class, UnlockComponent.class, LockComponent.class, QuitComponent.class, ErrorComponent.class}) abstract class FxApplicationModule { private static Image createImageFromResource(String resourceName) throws IOException { @@ -59,9 +59,5 @@ abstract class FxApplicationModule { return builder.build(); } - @Provides - @FxApplicationScoped - static QuitForcedComponent provideQuitForcedComponent(QuitForcedComponent.Builder builder) { - return builder.build(); - } + } diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java index b38bd0d06..569a3674a 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationTerminator.java @@ -115,11 +115,11 @@ public class FxApplicationTerminator { }); lockAllTask.setOnFailed(event -> { LOG.warn("Unable to lock all vaults."); - appWindows.showQuitForcedWindow(exitingResponse); + appWindows.showQuitWindow(exitingResponse, true); }); lockAllTask.run(); } else { - appWindows.showQuitWindow(exitingResponse); + appWindows.showQuitWindow(exitingResponse, false); } } diff --git a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java index d80cb6c5b..fa4662ad5 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java +++ b/src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java @@ -11,7 +11,7 @@ import org.cryptomator.ui.mainwindow.MainWindowComponent; import org.cryptomator.ui.preferences.PreferencesComponent; import org.cryptomator.ui.preferences.SelectedPreferencesTab; import org.cryptomator.ui.quit.QuitComponent; -import org.cryptomator.ui.quitforced.QuitForcedComponent; + import org.cryptomator.ui.unlock.UnlockComponent; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -41,8 +41,10 @@ public class FxApplicationWindows { private final Optional trayIntegration; private final Lazy mainWindow; private final Lazy preferencesWindow; - private final Lazy quitWindow; - private final Lazy quitForcedWindow; + + + private final QuitComponent.Builder quitWindowBuilder; + private final UnlockComponent.Factory unlockWorkflowFactory; private final LockComponent.Factory lockWorkflowFactory; private final ErrorComponent.Factory errorWindowFactory; @@ -50,13 +52,13 @@ public class FxApplicationWindows { private final FilteredList visibleWindows; @Inject - public FxApplicationWindows(@PrimaryStage Stage primaryStage, Optional trayIntegration, Lazy mainWindow, Lazy preferencesWindow, Lazy quitWindow, Lazy quitForcedWindow, UnlockComponent.Factory unlockWorkflowFactory, LockComponent.Factory lockWorkflowFactory, ErrorComponent.Factory errorWindowFactory, ExecutorService executor) { + public FxApplicationWindows(@PrimaryStage Stage primaryStage, Optional trayIntegration, Lazy mainWindow, Lazy preferencesWindow, QuitComponent.Builder quitWindowBuilder, UnlockComponent.Factory unlockWorkflowFactory, LockComponent.Factory lockWorkflowFactory, ErrorComponent.Factory errorWindowFactory, ExecutorService executor) { this.primaryStage = primaryStage; this.trayIntegration = trayIntegration; this.mainWindow = mainWindow; this.preferencesWindow = preferencesWindow; - this.quitWindow = quitWindow; - this.quitForcedWindow = quitForcedWindow; + + this.quitWindowBuilder = quitWindowBuilder; this.unlockWorkflowFactory = unlockWorkflowFactory; this.lockWorkflowFactory = lockWorkflowFactory; this.errorWindowFactory = errorWindowFactory; @@ -107,13 +109,10 @@ public class FxApplicationWindows { return CompletableFuture.supplyAsync(() -> preferencesWindow.get().showPreferencesWindow(selectedTab), Platform::runLater).whenComplete(this::reportErrors); } - public CompletionStage showQuitWindow(QuitResponse response) { - return CompletableFuture.supplyAsync(() -> quitWindow.get().showQuitWindow(response), Platform::runLater).whenComplete(this::reportErrors); + public void showQuitWindow(QuitResponse response, boolean forced) { + CompletableFuture.runAsync(() -> quitWindowBuilder.build().showQuitWindow(response,forced), Platform::runLater); } - public CompletionStage showQuitForcedWindow(QuitResponse response) { - return CompletableFuture.supplyAsync(() -> quitForcedWindow.get().showQuitForcedWindow(response), Platform::runLater).whenComplete(this::reportErrors); - } public CompletionStage startUnlockWorkflow(Vault vault, @Nullable Stage owner) { return CompletableFuture.supplyAsync(() -> { diff --git a/src/main/java/org/cryptomator/ui/quit/QuitComponent.java b/src/main/java/org/cryptomator/ui/quit/QuitComponent.java index e100c52e9..be3d7123f 100644 --- a/src/main/java/org/cryptomator/ui/quit/QuitComponent.java +++ b/src/main/java/org/cryptomator/ui/quit/QuitComponent.java @@ -22,23 +22,33 @@ public interface QuitComponent { Stage window(); @FxmlScene(FxmlFile.QUIT) - Lazy scene(); + Lazy quitScene(); - QuitController controller(); + @FxmlScene(FxmlFile.QUIT_FORCED) + Lazy quitForcedScene(); - default Stage showQuitWindow(QuitResponse response) { - controller().updateQuitRequest(response); + QuitController quitController(); + QuitForcedController quitForcedController(); + + default void showQuitWindow(QuitResponse response, boolean forced) { Stage stage = window(); - stage.setScene(scene().get()); + if(forced){ + quitForcedController().updateQuitRequest(response); + stage.setScene(quitForcedScene().get()); + } else{ + quitController().updateQuitRequest(response); + stage.setScene(quitScene().get()); + } + stage.sizeToScene(); stage.show(); - stage.requestFocus(); - return stage; } @Subcomponent.Builder interface Builder { QuitComponent build(); + + } } diff --git a/src/main/java/org/cryptomator/ui/quit/QuitController.java b/src/main/java/org/cryptomator/ui/quit/QuitController.java index 22a9f0e70..e389f1645 100644 --- a/src/main/java/org/cryptomator/ui/quit/QuitController.java +++ b/src/main/java/org/cryptomator/ui/quit/QuitController.java @@ -83,7 +83,7 @@ public class QuitController implements FxController { LOG.warn("Locking failed", lockAllTask.getException()); lockAndQuitButton.setDisable(false); lockAndQuitButton.setContentDisplay(ContentDisplay.TEXT_ONLY); - appWindows.showQuitForcedWindow(quitResponse.get()); + appWindows.showQuitWindow(quitResponse.get(),true); window.close(); }); executorService.execute(lockAllTask); diff --git a/src/main/java/org/cryptomator/ui/quitforced/QuitForcedController.java b/src/main/java/org/cryptomator/ui/quit/QuitForcedController.java similarity index 93% rename from src/main/java/org/cryptomator/ui/quitforced/QuitForcedController.java rename to src/main/java/org/cryptomator/ui/quit/QuitForcedController.java index 60e758991..f1474c366 100644 --- a/src/main/java/org/cryptomator/ui/quitforced/QuitForcedController.java +++ b/src/main/java/org/cryptomator/ui/quit/QuitForcedController.java @@ -1,4 +1,4 @@ -package org.cryptomator.ui.quitforced; +package org.cryptomator.ui.quit; import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.FxController; @@ -20,7 +20,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.stream.Collectors; -@QuitForcedScoped public class QuitForcedController implements FxController { private static final Logger LOG = LoggerFactory.getLogger(QuitForcedController.class); @@ -35,7 +34,7 @@ public class QuitForcedController implements FxController { public Button forceLockAndQuitButton; @Inject - QuitForcedController(@QuitForcedWindow Stage window, ObservableList vaults, ExecutorService executorService, VaultService vaultService) { + QuitForcedController(@QuitWindow Stage window, ObservableList vaults, ExecutorService executorService, VaultService vaultService) { this.window = window; this.unlockedVaults = vaults.filtered(Vault::isUnlocked); this.executorService = executorService; diff --git a/src/main/java/org/cryptomator/ui/quit/QuitModule.java b/src/main/java/org/cryptomator/ui/quit/QuitModule.java index a1dc581ed..e737799c6 100644 --- a/src/main/java/org/cryptomator/ui/quit/QuitModule.java +++ b/src/main/java/org/cryptomator/ui/quit/QuitModule.java @@ -48,6 +48,14 @@ abstract class QuitModule { return fxmlLoaders.createScene(FxmlFile.QUIT); } + @Provides + @FxmlScene(FxmlFile.QUIT_FORCED) + @QuitScoped + static Scene provideQuitForcedScene(@QuitWindow FxmlLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene(FxmlFile.QUIT_FORCED); + } + + // ------------------ @Binds @@ -55,4 +63,9 @@ abstract class QuitModule { @FxControllerKey(QuitController.class) abstract FxController bindQuitController(QuitController controller); + @Binds + @IntoMap + @FxControllerKey(QuitForcedController.class) + abstract FxController bindQuitForcedController(QuitForcedController controller); + } diff --git a/src/main/java/org/cryptomator/ui/quitforced/QuitForcedComponent.java b/src/main/java/org/cryptomator/ui/quitforced/QuitForcedComponent.java deleted file mode 100644 index 0a6ba5fb2..000000000 --- a/src/main/java/org/cryptomator/ui/quitforced/QuitForcedComponent.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Skymatic UG (haftungsbeschränkt). - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the accompanying LICENSE file. - *******************************************************************************/ -package org.cryptomator.ui.quitforced; - -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; -import java.awt.desktop.QuitResponse; - -@QuitForcedScoped -@Subcomponent(modules = {QuitForcedModule.class}) -public interface QuitForcedComponent { - - @QuitForcedWindow - Stage window(); - - @FxmlScene(FxmlFile.QUIT_FORCED) - Lazy scene(); - - QuitForcedController controller(); - - default Stage showQuitForcedWindow(QuitResponse response) { - controller().updateQuitRequest(response); - Stage stage = window(); - stage.setScene(scene().get()); - stage.show(); - stage.requestFocus(); - return stage; - } - - @Subcomponent.Builder - interface Builder { - - QuitForcedComponent build(); - } - -} diff --git a/src/main/java/org/cryptomator/ui/quitforced/QuitForcedModule.java b/src/main/java/org/cryptomator/ui/quitforced/QuitForcedModule.java deleted file mode 100644 index dbc311339..000000000 --- a/src/main/java/org/cryptomator/ui/quitforced/QuitForcedModule.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.cryptomator.ui.quitforced; - -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 QuitForcedModule { - - @Provides - @QuitForcedWindow - @QuitForcedScoped - static FxmlLoaderFactory provideFxmlLoaderFactory(Map, Provider> factories, DefaultSceneFactory sceneFactory, ResourceBundle resourceBundle) { - return new FxmlLoaderFactory(factories, sceneFactory, resourceBundle); - } - - @Provides - @QuitForcedWindow - @QuitForcedScoped - static Stage provideStage(StageFactory factory, ResourceBundle resourceBundle) { - Stage stage = factory.create(); - stage.setMinWidth(300); - stage.setMinHeight(100); - stage.initModality(Modality.APPLICATION_MODAL); - stage.setTitle(resourceBundle.getString("quit.title")); - return stage; - } - - @Provides - @FxmlScene(FxmlFile.QUIT_FORCED) - @QuitForcedScoped - static Scene provideQuitScene(@QuitForcedWindow FxmlLoaderFactory fxmlLoaders) { - return fxmlLoaders.createScene(FxmlFile.QUIT_FORCED); - } - - // ------------------ - - @Binds - @IntoMap - @FxControllerKey(QuitForcedController.class) - abstract FxController bindQuitController(QuitForcedController controller); - -} diff --git a/src/main/java/org/cryptomator/ui/quitforced/QuitForcedScoped.java b/src/main/java/org/cryptomator/ui/quitforced/QuitForcedScoped.java deleted file mode 100644 index 53bbc2209..000000000 --- a/src/main/java/org/cryptomator/ui/quitforced/QuitForcedScoped.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.cryptomator.ui.quitforced; - -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 QuitForcedScoped { - -} diff --git a/src/main/java/org/cryptomator/ui/quitforced/QuitForcedWindow.java b/src/main/java/org/cryptomator/ui/quitforced/QuitForcedWindow.java deleted file mode 100644 index 5026a4a5a..000000000 --- a/src/main/java/org/cryptomator/ui/quitforced/QuitForcedWindow.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.cryptomator.ui.quitforced; - -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 QuitForcedWindow { - -} diff --git a/src/main/resources/fxml/quit_forced.fxml b/src/main/resources/fxml/quit_forced.fxml index dbc7bcc23..d2e831d4d 100644 --- a/src/main/resources/fxml/quit_forced.fxml +++ b/src/main/resources/fxml/quit_forced.fxml @@ -14,7 +14,7 @@