diff --git a/src/main/java/io/bitsquare/BitsquareUI.java b/src/main/java/io/bitsquare/BitsquareUI.java index 4a546c79c4..c5071c1652 100644 --- a/src/main/java/io/bitsquare/BitsquareUI.java +++ b/src/main/java/io/bitsquare/BitsquareUI.java @@ -43,7 +43,6 @@ import javafx.stage.Stage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import akka.actor.ActorSystem; import lighthouse.files.AppDirectory; public class BitsquareUI extends Application { @@ -110,7 +109,7 @@ public class BitsquareUI extends Application { // configure the system tray - SystemTray systemTray = new SystemTray(primaryStage, injector.getInstance(ActorSystem.class), this); + SystemTray systemTray = new SystemTray(primaryStage, this); primaryStage.setOnCloseRequest(e -> systemTray.hideStage()); scene.setOnKeyReleased(keyEvent -> { if (new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN).match(keyEvent)) diff --git a/src/main/java/io/bitsquare/di/BitsquareModule.java b/src/main/java/io/bitsquare/di/BitsquareModule.java index 7a0a926eef..0014d01fdf 100644 --- a/src/main/java/io/bitsquare/di/BitsquareModule.java +++ b/src/main/java/io/bitsquare/di/BitsquareModule.java @@ -29,12 +29,20 @@ import io.bitsquare.trade.TradeModule; import io.bitsquare.user.User; import io.bitsquare.util.ConfigLoader; +import com.google.inject.Injector; + import java.util.Properties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import akka.actor.ActorSystem; +import scala.concurrent.duration.Duration; public class BitsquareModule extends AbstractBitsquareModule { + private static final Logger log = LoggerFactory.getLogger(BitsquareModule.class); + public BitsquareModule() { this(ConfigLoader.loadConfig()); } @@ -77,5 +85,16 @@ public class BitsquareModule extends AbstractBitsquareModule { protected GuiModule guiModule() { return new GuiModule(properties); } + + @Override + protected void doClose(Injector injector) { + ActorSystem actorSystem = injector.getInstance(ActorSystem.class); + actorSystem.shutdown(); + try { + actorSystem.awaitTermination(Duration.create(5L, "seconds")); + } catch (Exception ex) { + log.error("Actor system failed to shut down properly", ex); + } + } } diff --git a/src/main/java/io/bitsquare/gui/SystemTray.java b/src/main/java/io/bitsquare/gui/SystemTray.java index 9c61343f3f..5a5a8230e6 100644 --- a/src/main/java/io/bitsquare/gui/SystemTray.java +++ b/src/main/java/io/bitsquare/gui/SystemTray.java @@ -22,8 +22,6 @@ import io.bitsquare.gui.util.ImageUtil; import java.awt.*; -import java.util.concurrent.TimeoutException; - import javax.swing.*; import javafx.application.Platform; @@ -32,9 +30,6 @@ import javafx.stage.Stage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import akka.actor.ActorSystem; -import scala.concurrent.duration.Duration; - /** * There is no JavaFX support yet, so we need to use AWT. */ @@ -48,14 +43,12 @@ public class SystemTray { public static final String HIDE_WINDOW_LABEL = "Hide exchange window"; private final Stage stage; - private final ActorSystem actorSystem; private final BitsquareUI application; private final TrayIcon trayIcon = createTrayIcon(); private final MenuItem toggleShowHideItem = new MenuItem(HIDE_WINDOW_LABEL); - public SystemTray(Stage stage, ActorSystem actorSystem, BitsquareUI application) { + public SystemTray(Stage stage, BitsquareUI application) { this.stage = stage; - this.actorSystem = actorSystem; this.application = application; init(); } @@ -102,15 +95,6 @@ public class SystemTray { exitItem.addActionListener(e -> { self.remove(trayIcon); - actorSystem.shutdown(); - try { - actorSystem.awaitTermination(Duration.create(5L, "seconds")); - } catch (Exception ex) { - if (ex instanceof TimeoutException) - log.error("ActorSystem did not shutdown properly."); - else - log.error(ex.getMessage()); - } try { application.stop(); } catch (Exception ex) {