mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-20 03:31:27 +00:00
switch scene in quitDialog to quitForcedDialog instead of init new window
This commit is contained in:
@@ -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<Scene> quitForcedScene();
|
||||
|
||||
QuitController quitController();
|
||||
QuitForcedController quitForcedController();
|
||||
@QuitWindow
|
||||
AtomicReference<QuitResponse> 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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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<Vault> unlockedVaults;
|
||||
private final ExecutorService executorService;
|
||||
private final VaultService vaultService;
|
||||
private final AtomicReference<QuitResponse> quitResponse = new AtomicReference<>();
|
||||
private final FxApplicationWindows appWindows;
|
||||
private final AtomicReference<QuitResponse> quitResponse;
|
||||
/* FXML */
|
||||
public Button lockAndQuitButton;
|
||||
|
||||
private final Lazy<Scene> quitForcedScene;
|
||||
|
||||
@Inject
|
||||
QuitController(@QuitWindow Stage window, ObservableList<Vault> vaults, ExecutorService executorService, VaultService vaultService, FxApplicationWindows appWindows) {
|
||||
QuitController(@QuitWindow Stage window, ObservableList<Vault> vaults, ExecutorService executorService, VaultService vaultService, @FxmlScene(FxmlFile.QUIT_FORCED) Lazy<Scene> quitForcedScene, @QuitWindow AtomicReference<QuitResponse> 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,17 +28,18 @@ public class QuitForcedController implements FxController {
|
||||
private final ObservableList<Vault> unlockedVaults;
|
||||
private final ExecutorService executorService;
|
||||
private final VaultService vaultService;
|
||||
private final AtomicReference<QuitResponse> quitResponse = new AtomicReference<>();
|
||||
private final AtomicReference<QuitResponse> quitResponse;
|
||||
|
||||
/* FXML */
|
||||
public Button forceLockAndQuitButton;
|
||||
|
||||
@Inject
|
||||
QuitForcedController(@QuitWindow Stage window, ObservableList<Vault> vaults, ExecutorService executorService, VaultService vaultService) {
|
||||
QuitForcedController(@QuitWindow Stage window, ObservableList<Vault> vaults, ExecutorService executorService, VaultService vaultService, @QuitWindow AtomicReference<QuitResponse> 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);
|
||||
}
|
||||
|
||||
@@ -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<QuitResponse> provideQuitResponse() {
|
||||
return new AtomicReference<QuitResponse>();
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@FxmlScene(FxmlFile.QUIT)
|
||||
@QuitScoped
|
||||
|
||||
Reference in New Issue
Block a user