Allow shutting down the app with window close/quit

This commit is contained in:
Manfred Karrer 2014-11-10 13:51:10 +01:00
parent 865fe73bfb
commit 7ccfd98fb9
2 changed files with 15 additions and 6 deletions

View file

@ -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();
});

View file

@ -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() {