diff --git a/ui/src/main/java/edu/wpi/grip/ui/Main.java b/ui/src/main/java/edu/wpi/grip/ui/Main.java index 158fc7afd0..fe86af554a 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/Main.java +++ b/ui/src/main/java/edu/wpi/grip/ui/Main.java @@ -133,8 +133,6 @@ public void start(Stage stage) throws IOException { } }); - // If this isn't here this can cause a deadlock on windows. See issue #297 - stage.setOnCloseRequest(event -> SafeShutdown.exit(0, Platform::exit)); stage.setTitle(MAIN_TITLE); stage.getIcons().add(new Image("/edu/wpi/grip/ui/icons/grip.png")); stage.setScene(new Scene(root)); diff --git a/ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java b/ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java index e6d67b1905..2405dae48f 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java +++ b/ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java @@ -99,6 +99,12 @@ protected void initialize() { .toString()); statusBar.setText(" Pipeline " + stateMessage); }), Platform::runLater); + Platform.runLater(() -> root.getScene().getWindow().setOnCloseRequest(e -> { + if (!quit()) { + // Asked to quit but cancelled, consume the event to avoid closing the window + e.consume(); + } + })); } /** @@ -248,11 +254,13 @@ protected void showProjectAboutDialog() throws IOException { } @FXML - protected void quit() { + protected boolean quit() { if (showConfirmationDialogAndWait()) { pipelineRunner.stopAsync(); SafeShutdown.exit(0); + return true; } + return false; } /**