From 683276a6c609f940aec48246cd8c3b8f169f17bd Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Tue, 5 Jul 2022 14:22:05 +0200 Subject: [PATCH] switch scene in quitDialog to quitForcedDialog instead of init new window --- .../cryptomator/ui/quit/QuitComponent.java | 14 +++++-------- .../cryptomator/ui/quit/QuitController.java | 21 +++++++++++-------- .../ui/quit/QuitForcedController.java | 7 ++++--- .../org/cryptomator/ui/quit/QuitModule.java | 10 +++++++++ 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/quit/QuitComponent.java b/src/main/java/org/cryptomator/ui/quit/QuitComponent.java index be3d7123f..801aece51 100644 --- a/src/main/java/org/cryptomator/ui/quit/QuitComponent.java +++ b/src/main/java/org/cryptomator/ui/quit/QuitComponent.java @@ -13,6 +13,7 @@ import org.cryptomator.ui.common.FxmlScene; import javafx.scene.Scene; import javafx.stage.Stage; import java.awt.desktop.QuitResponse; +import java.util.concurrent.atomic.AtomicReference; @QuitScoped @Subcomponent(modules = {QuitModule.class}) @@ -27,16 +28,15 @@ public interface QuitComponent { @FxmlScene(FxmlFile.QUIT_FORCED) Lazy quitForcedScene(); - QuitController quitController(); - QuitForcedController quitForcedController(); + @QuitWindow + AtomicReference quitResponse(); default void showQuitWindow(QuitResponse response, boolean forced) { Stage stage = window(); + quitResponse().set(response); if(forced){ - quitForcedController().updateQuitRequest(response); stage.setScene(quitForcedScene().get()); } else{ - quitController().updateQuitRequest(response); stage.setScene(quitScene().get()); } stage.sizeToScene(); @@ -45,10 +45,6 @@ public interface QuitComponent { @Subcomponent.Builder interface Builder { - QuitComponent build(); - - } - -} +} \ No newline at end of file diff --git a/src/main/java/org/cryptomator/ui/quit/QuitController.java b/src/main/java/org/cryptomator/ui/quit/QuitController.java index e389f1645..5ae54f1f5 100644 --- a/src/main/java/org/cryptomator/ui/quit/QuitController.java +++ b/src/main/java/org/cryptomator/ui/quit/QuitController.java @@ -1,9 +1,11 @@ package org.cryptomator.ui.quit; +import dagger.Lazy; import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.common.VaultService; -import org.cryptomator.ui.fxapp.FxApplicationWindows; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,6 +13,7 @@ import javax.inject.Inject; import javafx.collections.ObservableList; import javafx.concurrent.Task; import javafx.fxml.FXML; +import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ContentDisplay; import javafx.stage.Stage; @@ -30,18 +33,20 @@ public class QuitController implements FxController { private final ObservableList unlockedVaults; private final ExecutorService executorService; private final VaultService vaultService; - private final AtomicReference quitResponse = new AtomicReference<>(); - private final FxApplicationWindows appWindows; + private final AtomicReference quitResponse; /* FXML */ public Button lockAndQuitButton; + private final Lazy quitForcedScene; + @Inject - QuitController(@QuitWindow Stage window, ObservableList vaults, ExecutorService executorService, VaultService vaultService, FxApplicationWindows appWindows) { + QuitController(@QuitWindow Stage window, ObservableList vaults, ExecutorService executorService, VaultService vaultService, @FxmlScene(FxmlFile.QUIT_FORCED) Lazy quitForcedScene, @QuitWindow AtomicReference quitResponse) { this.window = window; this.unlockedVaults = vaults.filtered(Vault::isUnlocked); this.executorService = executorService; this.vaultService = vaultService; - this.appWindows = appWindows; + this.quitForcedScene = quitForcedScene; + this.quitResponse = quitResponse; window.setOnCloseRequest(windowEvent -> cancel()); } @@ -83,10 +88,8 @@ public class QuitController implements FxController { LOG.warn("Locking failed", lockAllTask.getException()); lockAndQuitButton.setDisable(false); lockAndQuitButton.setContentDisplay(ContentDisplay.TEXT_ONLY); - appWindows.showQuitWindow(quitResponse.get(),true); - window.close(); + window.setScene(quitForcedScene.get()); }); executorService.execute(lockAllTask); } - -} +} \ No newline at end of file diff --git a/src/main/java/org/cryptomator/ui/quit/QuitForcedController.java b/src/main/java/org/cryptomator/ui/quit/QuitForcedController.java index f1474c366..8dd4140ac 100644 --- a/src/main/java/org/cryptomator/ui/quit/QuitForcedController.java +++ b/src/main/java/org/cryptomator/ui/quit/QuitForcedController.java @@ -28,17 +28,18 @@ public class QuitForcedController implements FxController { private final ObservableList unlockedVaults; private final ExecutorService executorService; private final VaultService vaultService; - private final AtomicReference quitResponse = new AtomicReference<>(); + private final AtomicReference quitResponse; /* FXML */ public Button forceLockAndQuitButton; @Inject - QuitForcedController(@QuitWindow Stage window, ObservableList vaults, ExecutorService executorService, VaultService vaultService) { + QuitForcedController(@QuitWindow Stage window, ObservableList vaults, ExecutorService executorService, VaultService vaultService, @QuitWindow AtomicReference quitResponse) { this.window = window; this.unlockedVaults = vaults.filtered(Vault::isUnlocked); this.executorService = executorService; this.vaultService = vaultService; + this.quitResponse = quitResponse; window.setOnCloseRequest(windowEvent -> cancel()); } @@ -58,7 +59,7 @@ public class QuitForcedController implements FxController { @FXML public void cancel() { - LOG.info("Quitting application canceled by user."); + LOG.info("Quitting application forced canceled by user."); window.close(); respondToQuitRequest(QuitResponse::cancelQuit); } diff --git a/src/main/java/org/cryptomator/ui/quit/QuitModule.java b/src/main/java/org/cryptomator/ui/quit/QuitModule.java index e737799c6..f6615b321 100644 --- a/src/main/java/org/cryptomator/ui/quit/QuitModule.java +++ b/src/main/java/org/cryptomator/ui/quit/QuitModule.java @@ -16,8 +16,10 @@ import javax.inject.Provider; import javafx.scene.Scene; import javafx.stage.Modality; import javafx.stage.Stage; +import java.awt.desktop.QuitResponse; import java.util.Map; import java.util.ResourceBundle; +import java.util.concurrent.atomic.AtomicReference; @Module abstract class QuitModule { @@ -41,6 +43,14 @@ abstract class QuitModule { return stage; } + @Provides + @QuitWindow + @QuitScoped + static AtomicReference provideQuitResponse() { + return new AtomicReference(); + } + + @Provides @FxmlScene(FxmlFile.QUIT) @QuitScoped