Iconify stage on close, reopen it with the tray icon

This commit is contained in:
Kai S. K. Engelbart 2020-07-23 18:53:36 +02:00
parent 5d03d0f0eb
commit 2ed30c56cd
2 changed files with 14 additions and 5 deletions

View File

@ -54,7 +54,7 @@ public class StatusTrayIcon {
final PopupMenu popup = new PopupMenu(); final PopupMenu popup = new PopupMenu();
final MenuItem exitMenuItem = new MenuItem("Exit"); final MenuItem exitMenuItem = new MenuItem("Exit");
exitMenuItem.addActionListener(evt -> System.exit(0)); exitMenuItem.addActionListener(evt -> { Platform.exit(); System.exit(0); });
popup.add(exitMenuItem); popup.add(exitMenuItem);
trayIcon.setPopupMenu(popup); trayIcon.setPopupMenu(popup);
@ -63,7 +63,7 @@ public class StatusTrayIcon {
stage.focusedProperty().addListener((ov, onHidden, onShown) -> displayMessages = ov.getValue()); stage.focusedProperty().addListener((ov, onHidden, onShown) -> displayMessages = ov.getValue());
// Show the window if the user clicks on the icon // 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 // Start processing message events
// TODO: Handle other message types // TODO: Handle other message types

View File

@ -15,9 +15,7 @@ import javafx.scene.control.Alert.AlertType;
import envoy.client.data.*; import envoy.client.data.*;
import envoy.client.net.Client; import envoy.client.net.Client;
import envoy.client.net.WriteProxy; import envoy.client.net.WriteProxy;
import envoy.client.ui.ClearableTextField; import envoy.client.ui.*;
import envoy.client.ui.SceneContext;
import envoy.client.ui.Startup;
import envoy.data.LoginCredentials; import envoy.data.LoginCredentials;
import envoy.data.User; import envoy.data.User;
import envoy.data.User.UserStatus; import envoy.data.User.UserStatus;
@ -210,5 +208,16 @@ public final class LoginScene {
sceneContext.getStage().setMinWidth(350); sceneContext.getStage().setMinWidth(350);
sceneContext.load(SceneContext.SceneInfo.CHAT_SCENE); sceneContext.load(SceneContext.SceneInfo.CHAT_SCENE);
sceneContext.<ChatScene>getController().initializeData(sceneContext, localDB, client, writeProxy); sceneContext.<ChatScene>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();
}
} }
} }