mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-30 09:37:28 -04:00
Move ActorSystem shutdown logic out of SystemTray
This commit is contained in:
parent
fa7d7a08a5
commit
b9e9882865
3 changed files with 21 additions and 19 deletions
|
@ -43,7 +43,6 @@ import javafx.stage.Stage;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import akka.actor.ActorSystem;
|
|
||||||
import lighthouse.files.AppDirectory;
|
import lighthouse.files.AppDirectory;
|
||||||
|
|
||||||
public class BitsquareUI extends Application {
|
public class BitsquareUI extends Application {
|
||||||
|
@ -110,7 +109,7 @@ public class BitsquareUI extends Application {
|
||||||
|
|
||||||
// configure the system tray
|
// 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());
|
primaryStage.setOnCloseRequest(e -> systemTray.hideStage());
|
||||||
scene.setOnKeyReleased(keyEvent -> {
|
scene.setOnKeyReleased(keyEvent -> {
|
||||||
if (new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN).match(keyEvent))
|
if (new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN).match(keyEvent))
|
||||||
|
|
|
@ -29,12 +29,20 @@ import io.bitsquare.trade.TradeModule;
|
||||||
import io.bitsquare.user.User;
|
import io.bitsquare.user.User;
|
||||||
import io.bitsquare.util.ConfigLoader;
|
import io.bitsquare.util.ConfigLoader;
|
||||||
|
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import akka.actor.ActorSystem;
|
import akka.actor.ActorSystem;
|
||||||
|
import scala.concurrent.duration.Duration;
|
||||||
|
|
||||||
public class BitsquareModule extends AbstractBitsquareModule {
|
public class BitsquareModule extends AbstractBitsquareModule {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(BitsquareModule.class);
|
||||||
|
|
||||||
public BitsquareModule() {
|
public BitsquareModule() {
|
||||||
this(ConfigLoader.loadConfig());
|
this(ConfigLoader.loadConfig());
|
||||||
}
|
}
|
||||||
|
@ -77,5 +85,16 @@ public class BitsquareModule extends AbstractBitsquareModule {
|
||||||
protected GuiModule guiModule() {
|
protected GuiModule guiModule() {
|
||||||
return new GuiModule(properties);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@ import io.bitsquare.gui.util.ImageUtil;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
@ -32,9 +30,6 @@ import javafx.stage.Stage;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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.
|
* 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";
|
public static final String HIDE_WINDOW_LABEL = "Hide exchange window";
|
||||||
|
|
||||||
private final Stage stage;
|
private final Stage stage;
|
||||||
private final ActorSystem actorSystem;
|
|
||||||
private final BitsquareUI application;
|
private final BitsquareUI application;
|
||||||
private final TrayIcon trayIcon = createTrayIcon();
|
private final TrayIcon trayIcon = createTrayIcon();
|
||||||
private final MenuItem toggleShowHideItem = new MenuItem(HIDE_WINDOW_LABEL);
|
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.stage = stage;
|
||||||
this.actorSystem = actorSystem;
|
|
||||||
this.application = application;
|
this.application = application;
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
@ -102,15 +95,6 @@ public class SystemTray {
|
||||||
|
|
||||||
exitItem.addActionListener(e -> {
|
exitItem.addActionListener(e -> {
|
||||||
self.remove(trayIcon);
|
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 {
|
try {
|
||||||
application.stop();
|
application.stop();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue