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 2740a1cb10
commit 1d706c14f2
No known key found for this signature in database
GPG Key ID: 0A48559CA32CB48F
2 changed files with 14 additions and 5 deletions

View File

@ -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

View File

@ -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.<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();
}
}
}