Explorar o código

Don't bother FxApplication with stuff that is meant to be dealt with internally within QuitComponent

Sebastian Stenzel %!s(int64=4) %!d(string=hai) anos
pai
achega
4779bbf415

+ 2 - 6
main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java

@@ -31,7 +31,6 @@ import javafx.collections.ObservableSet;
 import javafx.stage.Stage;
 import java.awt.desktop.QuitResponse;
 import java.util.Optional;
-import java.util.concurrent.atomic.AtomicReference;
 
 @FxApplicationScoped
 public class FxApplication extends Application {
@@ -49,10 +48,9 @@ public class FxApplication extends Application {
 	private final LicenseHolder licenseHolder;
 	private final BooleanBinding hasVisibleStages;
 	private final UiAppearanceListener systemInterfaceThemeListener = this::systemInterfaceThemeChanged;
-	private final AtomicReference<QuitResponse> quitResponse;
 
 	@Inject
-	FxApplication(Settings settings, Lazy<MainWindowComponent> mainWindow, Lazy<PreferencesComponent> preferencesWindow, Provider<UnlockComponent.Builder> unlockWindowBuilderProvider, Lazy<QuitComponent> quitWindow, Optional<TrayIntegrationProvider> trayIntegration, Optional<UiAppearanceProvider> appearanceProvider, VaultService vaultService, LicenseHolder licenseHolder, ObservableSet<Stage> visibleStages, AtomicReference<QuitResponse> quitResponse) {
+	FxApplication(Settings settings, Lazy<MainWindowComponent> mainWindow, Lazy<PreferencesComponent> preferencesWindow, Provider<UnlockComponent.Builder> unlockWindowBuilderProvider, Lazy<QuitComponent> quitWindow, Optional<TrayIntegrationProvider> trayIntegration, Optional<UiAppearanceProvider> appearanceProvider, VaultService vaultService, LicenseHolder licenseHolder, ObservableSet<Stage> visibleStages) {
 		this.settings = settings;
 		this.mainWindow = mainWindow;
 		this.preferencesWindow = preferencesWindow;
@@ -63,7 +61,6 @@ public class FxApplication extends Application {
 		this.vaultService = vaultService;
 		this.licenseHolder = licenseHolder;
 		this.hasVisibleStages = Bindings.isNotEmpty(visibleStages);
-		this.quitResponse = quitResponse;
 	}
 
 	public void start() {
@@ -111,9 +108,8 @@ public class FxApplication extends Application {
 	}
 
 	public void showQuitWindow(QuitResponse response) {
-		quitResponse.set(response);
 		Platform.runLater(() -> {
-			quitWindow.get().showQuitWindow();
+			quitWindow.get().showQuitWindow(response);
 			LOG.debug("Showing QuitWindow");
 		});
 	}

+ 0 - 8
main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplicationModule.java

@@ -22,23 +22,15 @@ import javafx.collections.FXCollections;
 import javafx.collections.ObservableSet;
 import javafx.scene.image.Image;
 import javafx.stage.Stage;
-import java.awt.desktop.QuitResponse;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UncheckedIOException;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.atomic.AtomicReference;
 
 @Module(includes = {UpdateCheckerModule.class}, subcomponents = {MainWindowComponent.class, PreferencesComponent.class, UnlockComponent.class, QuitComponent.class, ErrorComponent.class})
 abstract class FxApplicationModule {
 
-	@Provides
-	@FxApplicationScoped
-	static AtomicReference<QuitResponse> provideQuitResponse() {
-		return new AtomicReference<>();
-	}
-
 	@Provides
 	@FxApplicationScoped
 	static ObservableSet<Stage> provideVisibleStages() {

+ 7 - 13
main/ui/src/main/java/org/cryptomator/ui/quit/QuitComponent.java

@@ -10,9 +10,9 @@ import dagger.Subcomponent;
 import org.cryptomator.ui.common.FxmlFile;
 import org.cryptomator.ui.common.FxmlScene;
 
-import javafx.beans.property.ObjectProperty;
 import javafx.scene.Scene;
 import javafx.stage.Stage;
+import java.awt.desktop.QuitResponse;
 
 @QuitScoped
 @Subcomponent(modules = {QuitModule.class})
@@ -24,18 +24,12 @@ public interface QuitComponent {
 	@FxmlScene(FxmlFile.QUIT)
 	Lazy<Scene> scene();
 
-	ObjectProperty<Stage> provideStageProperty();
-
-	default Stage showQuitWindow() {
-		var stageProperty = provideStageProperty();
-		Stage stage;
-		if (stageProperty.isNull().get()) {
-			stage = window();
-			stage.setScene(scene().get());
-			stageProperty.set(stage);
-		} else {
-			stage = stageProperty.get();
-		}
+	QuitController controller();
+
+	default Stage showQuitWindow(QuitResponse response) {
+		controller().updateQuitRequest(response);
+		Stage stage = window();
+		stage.setScene(scene().get());
 		stage.show();
 		stage.requestFocus();
 		return stage;

+ 20 - 7
main/ui/src/main/java/org/cryptomator/ui/quit/QuitController.java

@@ -17,6 +17,7 @@ import java.awt.desktop.QuitResponse;
 import java.util.Collection;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
 import java.util.stream.Collectors;
 
 @QuitScoped
@@ -28,25 +29,37 @@ public class QuitController implements FxController {
 	private final ObservableList<Vault> unlockedVaults;
 	private final ExecutorService executorService;
 	private final VaultService vaultService;
-	private final AtomicReference<QuitResponse> quitResponse;
+	private final AtomicReference<QuitResponse> quitResponse = new AtomicReference<>();
 	public Button lockAndQuitButton;
 
 	@Inject
-	QuitController(@QuitWindow Stage window, ObservableList<Vault> vaults, ExecutorService executorService, VaultService vaultService, AtomicReference<QuitResponse> quitResponse) {
+	QuitController(@QuitWindow Stage window, ObservableList<Vault> vaults, ExecutorService executorService, VaultService vaultService) {
 		this.window = window;
 		this.unlockedVaults = vaults.filtered(Vault::isUnlocked);
 		this.executorService = executorService;
 		this.vaultService = vaultService;
-		this.quitResponse = quitResponse;
 		window.setOnCloseRequest(windowEvent -> cancel());
 	}
 
+	public void updateQuitRequest(QuitResponse newResponse) {
+		var oldResponse = quitResponse.getAndSet(newResponse);
+		if (oldResponse != null) {
+			oldResponse.cancelQuit();
+		}
+	}
+
+	private void respondToQuitRequest(Consumer<QuitResponse> action) {
+		var response = quitResponse.getAndSet(null);
+		if (response != null) {
+			action.accept(response);
+		}
+	}
+
 	@FXML
 	public void cancel() {
 		LOG.info("Quitting application canceled by user.");
 		window.close();
-		quitResponse.get().cancelQuit();
-		quitResponse.set(null);
+		respondToQuitRequest(QuitResponse::cancelQuit);
 	}
 
 	@FXML
@@ -59,7 +72,7 @@ public class QuitController implements FxController {
 			LOG.info("Locked {}", lockAllTask.getValue().stream().map(Vault::getDisplayName).collect(Collectors.joining(", ")));
 			if (unlockedVaults.isEmpty()) {
 				window.close();
-				quitResponse.getAndSet(null).performQuit();
+				respondToQuitRequest(QuitResponse::performQuit);
 			}
 		});
 		lockAllTask.setOnFailed(evt -> {
@@ -68,7 +81,7 @@ public class QuitController implements FxController {
 			lockAndQuitButton.setContentDisplay(ContentDisplay.TEXT_ONLY);
 			// TODO: show force lock or force quit scene (and DO NOT cancelQuit() here!) (see https://github.com/cryptomator/cryptomator/pull/1416)
 			window.close();
-			quitResponse.getAndSet(null).cancelQuit();
+			respondToQuitRequest(QuitResponse::cancelQuit);
 		});
 		executorService.execute(lockAllTask);
 	}

+ 0 - 6
main/ui/src/main/java/org/cryptomator/ui/quit/QuitModule.java

@@ -24,12 +24,6 @@ import java.util.ResourceBundle;
 @Module
 abstract class QuitModule {
 
-	@Provides
-	@QuitScoped
-	static ObjectProperty<Stage> provideStageProperty() {
-		return new SimpleObjectProperty<>();
-	}
-
 	@Provides
 	@QuitWindow
 	@QuitScoped