Remove cycle between SystemTray and BitsquareUI

This commit is contained in:
Chris Beams 2014-11-04 12:07:21 +01:00
parent b1a4641139
commit f278db01ac
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73
2 changed files with 5 additions and 10 deletions

View file

@ -109,7 +109,7 @@ public class BitsquareUI extends Application {
// configure the system tray // configure the system tray
SystemTray systemTray = new SystemTray(primaryStage, this); SystemTray systemTray = new SystemTray(primaryStage, this::stop);
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))

View file

@ -17,7 +17,6 @@
package io.bitsquare.gui; package io.bitsquare.gui;
import io.bitsquare.BitsquareUI;
import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.ImageUtil;
import java.awt.*; import java.awt.*;
@ -43,13 +42,13 @@ 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 BitsquareUI application; private final Runnable onExit;
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, BitsquareUI application) { public SystemTray(Stage stage, Runnable onExit) {
this.stage = stage; this.stage = stage;
this.application = application; this.onExit = onExit;
init(); init();
} }
@ -95,11 +94,7 @@ public class SystemTray {
exitItem.addActionListener(e -> { exitItem.addActionListener(e -> {
self.remove(trayIcon); self.remove(trayIcon);
try { onExit.run();
application.stop();
} catch (Exception ex) {
log.error("Application failed to shut down properly.", ex);
}
}); });
} }