2020-09-23 17:03:32 +02:00
|
|
|
package envoy.client.helper;
|
|
|
|
|
|
|
|
import javafx.scene.control.Alert;
|
|
|
|
import javafx.scene.control.Alert.AlertType;
|
|
|
|
|
|
|
|
import envoy.client.data.*;
|
2020-09-23 23:11:32 +02:00
|
|
|
import envoy.client.event.*;
|
|
|
|
import envoy.client.ui.SceneContext.SceneInfo;
|
2020-09-23 17:03:32 +02:00
|
|
|
|
|
|
|
import dev.kske.eventbus.EventBus;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains methods that have a direct impact on the user.
|
|
|
|
*
|
|
|
|
* @author Leon Hofmeister
|
|
|
|
* @since Envoy Client v0.2-beta
|
|
|
|
*/
|
|
|
|
public class ShutdownHelper {
|
|
|
|
|
|
|
|
private ShutdownHelper() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exits Envoy or minimizes it, depending on the current state of
|
|
|
|
* {@link Settings#isHideOnClose()}.
|
|
|
|
*
|
|
|
|
* @since Envoy Client v0.2-beta
|
|
|
|
*/
|
2020-09-23 23:11:32 +02:00
|
|
|
public static void exit() {
|
|
|
|
if (Settings.getInstance().isHideOnClose()) Context.getInstance().getStage().setIconified(true);
|
|
|
|
else {
|
|
|
|
final var alert = new Alert(AlertType.CONFIRMATION);
|
|
|
|
alert.setTitle("Exit?");
|
|
|
|
alert.setContentText("Are you sure you want to exit Envoy?");
|
|
|
|
AlertHelper.confirmAction(alert, () -> { EventBus.getInstance().dispatch(new EnvoyCloseEvent()); System.exit(0); });
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 17:03:32 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-23 23:11:32 +02:00
|
|
|
* Logs the current user out and reopens
|
|
|
|
* {@link envoy.client.ui.controller.LoginScene}.
|
2020-09-23 17:03:32 +02:00
|
|
|
*
|
|
|
|
* @since Envoy Client v0.2-beta
|
|
|
|
*/
|
2020-09-23 23:11:32 +02:00
|
|
|
public static void logout() {
|
|
|
|
final var alert = new Alert(AlertType.CONFIRMATION);
|
|
|
|
alert.setTitle("Logout?");
|
|
|
|
alert.setContentText("Are you sure you want to log out?");
|
|
|
|
|
|
|
|
AlertHelper.confirmAction(alert, () -> {
|
2020-09-23 17:03:32 +02:00
|
|
|
EventBus.getInstance().dispatch(new EnvoyCloseEvent());
|
2020-09-23 23:11:32 +02:00
|
|
|
EventBus.getInstance().dispatch(new Logout());
|
|
|
|
Context.getInstance().getSceneContext().load(SceneInfo.LOGIN_SCENE);
|
|
|
|
});
|
2020-09-23 17:03:32 +02:00
|
|
|
}
|
|
|
|
}
|