Shutdown correctly

This commit is contained in:
Manfred Karrer 2014-10-27 02:01:01 +01:00
parent 008ae0ef52
commit 8160397361
2 changed files with 12 additions and 4 deletions

View file

@ -84,7 +84,7 @@ public class BitSquareUI extends Application {
final Injector injector = Guice.createInjector(new BitSquareModule());
// currently there is not SystemTray support for java fx (planned for version 3) so we use the old AWT
AWTSystemTray.createSystemTray(primaryStage, injector.getInstance(ActorSystem.class));
AWTSystemTray.createSystemTray(primaryStage, injector.getInstance(ActorSystem.class), this);
walletFacade = injector.getInstance(WalletFacade.class);
messageFacade = injector.getInstance(MessageFacade.class);
@ -146,7 +146,8 @@ public class BitSquareUI extends Application {
KeyCodeCombination keyCodeCombination = new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN);
scene.setOnKeyReleased(keyEvent -> {
if (keyCodeCombination.match(keyEvent)) AWTSystemTray.setStageHidden();
if (keyCodeCombination.match(keyEvent))
AWTSystemTray.setStageHidden();
});
}

View file

@ -19,6 +19,7 @@ package io.bitsquare.gui;
import io.bitsquare.BitSquare;
import io.bitsquare.BitSquareUI;
import io.bitsquare.gui.util.ImageUtil;
import java.awt.*;
@ -46,11 +47,13 @@ public class AWTSystemTray {
private static MenuItem showGuiItem;
private static Stage stage;
private static ActorSystem actorSystem;
private static BitSquareUI application;
private static TrayIcon trayIcon;
public static void createSystemTray(Stage stage, ActorSystem actorSystem) {
public static void createSystemTray(Stage stage, ActorSystem actorSystem, BitSquareUI application) {
AWTSystemTray.stage = stage;
AWTSystemTray.actorSystem = actorSystem;
AWTSystemTray.application = application;
if (SystemTray.isSupported()) {
// prevent exiting the app when the last window get closed
@ -99,7 +102,11 @@ public class AWTSystemTray {
else
log.error(ex.getMessage());
}
System.exit(0);
try {
application.stop();
} catch (Exception e1) {
e1.printStackTrace();
}
});