2020-09-23 17:03:32 +02:00
|
|
|
package envoy.client.helper;
|
|
|
|
|
2020-09-24 18:00:59 +02:00
|
|
|
import java.util.logging.Level;
|
|
|
|
|
2020-09-23 17:03:32 +02:00
|
|
|
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-28 15:58:42 +02:00
|
|
|
import envoy.client.ui.StatusTrayIcon;
|
2020-09-24 18:00:59 +02:00
|
|
|
import envoy.util.EnvoyLog;
|
2020-09-23 17:03:32 +02:00
|
|
|
|
|
|
|
import dev.kske.eventbus.EventBus;
|
|
|
|
|
|
|
|
/**
|
2020-09-26 21:38:31 +02:00
|
|
|
* Simplifies shutdown actions.
|
2020-09-23 17:03:32 +02:00
|
|
|
*
|
|
|
|
* @author Leon Hofmeister
|
|
|
|
* @since Envoy Client v0.2-beta
|
|
|
|
*/
|
2020-09-26 21:38:31 +02:00
|
|
|
public final class ShutdownHelper {
|
2020-09-23 17:03:32 +02:00
|
|
|
|
|
|
|
private ShutdownHelper() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exits Envoy or minimizes it, depending on the current state of
|
2020-09-28 15:58:42 +02:00
|
|
|
* {@link Settings#isHideOnClose()} and {@link StatusTrayIcon#isSupported()}.
|
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 exit() {
|
2020-09-28 15:58:42 +02:00
|
|
|
if (Settings.getInstance().isHideOnClose() && StatusTrayIcon.isSupported()) Context.getInstance().getStage().setIconified(true);
|
2020-09-23 23:11:32 +02:00
|
|
|
else {
|
2020-09-25 22:00:34 +02:00
|
|
|
EventBus.getInstance().dispatch(new EnvoyCloseEvent());
|
|
|
|
System.exit(0);
|
2020-09-23 23:11:32 +02:00
|
|
|
}
|
|
|
|
}
|
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-24 18:00:59 +02:00
|
|
|
EnvoyLog.getLogger(ShutdownHelper.class).log(Level.INFO, "A logout was requested");
|
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
|
|
|
}
|
|
|
|
}
|