mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-02 03:36:24 -04:00
Allow shutting down the app with window close/quit
This commit is contained in:
parent
865fe73bfb
commit
7ccfd98fb9
2 changed files with 15 additions and 6 deletions
|
@ -136,8 +136,13 @@ public class Main extends Application {
|
||||||
SystemTray systemTray = new SystemTray(primaryStage, this::stop);
|
SystemTray systemTray = new SystemTray(primaryStage, this::stop);
|
||||||
primaryStage.setOnCloseRequest(e -> systemTray.hideStage());
|
primaryStage.setOnCloseRequest(e -> systemTray.hideStage());
|
||||||
scene.setOnKeyReleased(keyEvent -> {
|
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))
|
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();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,9 @@ public class SystemTray {
|
||||||
}
|
}
|
||||||
|
|
||||||
// prevent exiting the app when the last window gets closed
|
// 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 aboutItem = new MenuItem("Info about Bitsquare");
|
||||||
MenuItem exitItem = new MenuItem("Exit");
|
MenuItem exitItem = new MenuItem("Exit");
|
||||||
|
@ -92,10 +94,12 @@ public class SystemTray {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
exitItem.addActionListener(e -> {
|
exitItem.addActionListener(e -> exit());
|
||||||
self.remove(trayIcon);
|
}
|
||||||
|
|
||||||
|
public void exit() {
|
||||||
|
java.awt.SystemTray.getSystemTray().remove(trayIcon);
|
||||||
onExit.run();
|
onExit.run();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideStage() {
|
public void hideStage() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue