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