From 7ccfd98fb938d0d32e7ded7819d98e8118462b40 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 10 Nov 2014 13:51:10 +0100 Subject: [PATCH] Allow shutting down the app with window close/quit --- src/main/java/io/bitsquare/app/gui/Main.java | 7 ++++++- src/main/java/io/bitsquare/gui/SystemTray.java | 14 +++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/bitsquare/app/gui/Main.java b/src/main/java/io/bitsquare/app/gui/Main.java index 7d11f36d06..e8754bf50e 100644 --- a/src/main/java/io/bitsquare/app/gui/Main.java +++ b/src/main/java/io/bitsquare/app/gui/Main.java @@ -136,8 +136,13 @@ public class Main extends Application { SystemTray systemTray = new SystemTray(primaryStage, this::stop); primaryStage.setOnCloseRequest(e -> systemTray.hideStage()); scene.setOnKeyReleased(keyEvent -> { + // For now we exit when closing/quit the app. + // Later we will only hide the window (systemTray.hideStage()) and use the exit item in the system tray for + // shut down. if (new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN).match(keyEvent)) - systemTray.hideStage(); + systemTray.exit(); + if (new KeyCodeCombination(KeyCode.Q, KeyCombination.SHORTCUT_DOWN).match(keyEvent)) + systemTray.exit(); }); diff --git a/src/main/java/io/bitsquare/gui/SystemTray.java b/src/main/java/io/bitsquare/gui/SystemTray.java index 063139a146..aadcd02d4f 100644 --- a/src/main/java/io/bitsquare/gui/SystemTray.java +++ b/src/main/java/io/bitsquare/gui/SystemTray.java @@ -59,7 +59,9 @@ public class SystemTray { } // prevent exiting the app when the last window gets closed - Platform.setImplicitExit(false); + // For now we allow to close the app by closing the window. + // Later we only let it close via the system trays exit. + Platform.setImplicitExit(true); MenuItem aboutItem = new MenuItem("Info about Bitsquare"); MenuItem exitItem = new MenuItem("Exit"); @@ -92,10 +94,12 @@ public class SystemTray { } }); - exitItem.addActionListener(e -> { - self.remove(trayIcon); - onExit.run(); - }); + exitItem.addActionListener(e -> exit()); + } + + public void exit() { + java.awt.SystemTray.getSystemTray().remove(trayIcon); + onExit.run(); } public void hideStage() {