From 2ed30c56cdb24e7d08a67752e920302ffcffcf72 Mon Sep 17 00:00:00 2001 From: kske Date: Thu, 23 Jul 2020 18:53:36 +0200 Subject: [PATCH] Iconify stage on close, reopen it with the tray icon --- .../main/java/envoy/client/ui/StatusTrayIcon.java | 4 ++-- .../envoy/client/ui/controller/LoginScene.java | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/StatusTrayIcon.java b/client/src/main/java/envoy/client/ui/StatusTrayIcon.java index ec22b68..f60645a 100644 --- a/client/src/main/java/envoy/client/ui/StatusTrayIcon.java +++ b/client/src/main/java/envoy/client/ui/StatusTrayIcon.java @@ -54,7 +54,7 @@ public class StatusTrayIcon { final PopupMenu popup = new PopupMenu(); final MenuItem exitMenuItem = new MenuItem("Exit"); - exitMenuItem.addActionListener(evt -> System.exit(0)); + exitMenuItem.addActionListener(evt -> { Platform.exit(); System.exit(0); }); popup.add(exitMenuItem); trayIcon.setPopupMenu(popup); @@ -63,7 +63,7 @@ public class StatusTrayIcon { stage.focusedProperty().addListener((ov, onHidden, onShown) -> displayMessages = ov.getValue()); // Show the window if the user clicks on the icon - trayIcon.addActionListener(evt -> Platform.runLater(() -> { stage.show(); stage.requestFocus(); })); + trayIcon.addActionListener(evt -> Platform.runLater(() -> { stage.setIconified(false); stage.toFront(); stage.requestFocus(); })); // Start processing message events // TODO: Handle other message types diff --git a/client/src/main/java/envoy/client/ui/controller/LoginScene.java b/client/src/main/java/envoy/client/ui/controller/LoginScene.java index 93978e8..7d058cd 100644 --- a/client/src/main/java/envoy/client/ui/controller/LoginScene.java +++ b/client/src/main/java/envoy/client/ui/controller/LoginScene.java @@ -15,9 +15,7 @@ import javafx.scene.control.Alert.AlertType; import envoy.client.data.*; import envoy.client.net.Client; import envoy.client.net.WriteProxy; -import envoy.client.ui.ClearableTextField; -import envoy.client.ui.SceneContext; -import envoy.client.ui.Startup; +import envoy.client.ui.*; import envoy.data.LoginCredentials; import envoy.data.User; import envoy.data.User.UserStatus; @@ -210,5 +208,16 @@ public final class LoginScene { sceneContext.getStage().setMinWidth(350); sceneContext.load(SceneContext.SceneInfo.CHAT_SCENE); sceneContext.getController().initializeData(sceneContext, localDB, client, writeProxy); + + try { + new StatusTrayIcon(sceneContext.getStage()).show(); + sceneContext.getStage().setOnCloseRequest(e -> { + sceneContext.getStage().setIconified(true); + e.consume(); + }); + } catch (EnvoyException e) { + e.printStackTrace(); + } + } }