Merge pull request #690 from jellemdekker/feature/230-graceful-quit

Implemented graceful shutdown confirmation dialog, fixes #230.
This commit is contained in:
Sebastian Stenzel
2018-08-21 18:15:02 +02:00
committed by GitHub
3 changed files with 25 additions and 1 deletions

View File

@@ -217,7 +217,22 @@ public class MainController implements ViewController {
private void gracefulShutdown() {
vaults.filtered(Vault.NOT_LOCKED).forEach(Vault::prepareForShutdown);
Platform.runLater(Platform::exit);
if (!vaults.filtered(Vault.NOT_LOCKED).isEmpty()) {
ButtonType tryAgainButtonType = new ButtonType(localization.getString("main.gracefulShutdown.button.tryAgain"));
ButtonType forceShutdownButtonType = new ButtonType(localization.getString("main.gracefulShutdown.button.forceShutdown"));
Alert gracefulShutdownDialog = DialogBuilderUtil.buildGracefulShutdownDialog(
localization.getString("main.gracefulShutdown.dialog.title"), localization.getString("main.gracefulShutdown.dialog.header"), localization.getString("main.gracefulShutdown.dialog.content"),
forceShutdownButtonType, forceShutdownButtonType, tryAgainButtonType);
Optional<ButtonType> choice = gracefulShutdownDialog.showAndWait();
choice.ifPresent(btnType -> {
if (tryAgainButtonType.equals(btnType)) {
gracefulShutdown();
} else if (forceShutdownButtonType.equals(btnType)) {
Platform.runLater(Platform::exit);
}
});
}
}
private void loadFont(String resourcePath) {

View File

@@ -38,6 +38,10 @@ public class DialogBuilderUtil {
return buildDialog(title, header, content, Alert.AlertType.CONFIRMATION, defaultButton, ButtonType.YES, ButtonType.NO);
}
public static Alert buildGracefulShutdownDialog(String title, String header, String content, ButtonType defaultButton, ButtonType... buttons) {
return buildDialog(title, header, content, Alert.AlertType.WARNING, defaultButton, buttons);
}
private static Alert buildDialog(String title, String header, String content, Alert.AlertType type, ButtonType defaultButton, ButtonType... buttons) {
Text contentText = new Text(content);
contentText.setWrappingWidth(360.0);

View File

@@ -19,6 +19,11 @@ main.directoryList.remove.confirmation.content=The vault will only be removed fr
main.createVault.nonEmptyDir.title=Creating vault failed
main.createVault.nonEmptyDir.header=Chosen directory is not empty
main.createVault.nonEmptyDir.content=The selected directory already contains files (possibly hidden). A vault can only be created in an empty directory.
main.gracefulShutdown.dialog.title=Locking vault(s) failed
main.gracefulShutdown.dialog.header=Vault(s) in use
main.gracefulShutdown.dialog.content=One or more vaults are still in use by other programs. Please close them to allow Cryptomator to shut down properly, then try again.\n\nIf this doesn't work, Cryptomator can shut down forcefully, but this can incur data loss and is not recommended.
main.gracefulShutdown.button.tryAgain=Try again
main.gracefulShutdown.button.forceShutdown=Force shutdown
# welcome.fxml
welcome.checkForUpdates.label.currentlyChecking=Checking for Updates...