2020-09-23 17:03:32 +02:00
|
|
|
package envoy.client.helper;
|
|
|
|
|
|
|
|
import envoy.client.data.*;
|
2020-10-08 16:12:24 +02:00
|
|
|
import envoy.client.event.EnvoyCloseEvent;
|
2020-09-28 15:58:42 +02:00
|
|
|
import envoy.client.ui.StatusTrayIcon;
|
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-10-08 22:07:37 +02:00
|
|
|
public static void exit() { exit(false); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exits Envoy immediately if {@code force = true},
|
|
|
|
* else it can exit or minimize Envoy, depending on the current state of
|
|
|
|
* {@link Settings#isHideOnClose()} and {@link StatusTrayIcon#isSupported()}.
|
|
|
|
*
|
|
|
|
* @param force whether to close in any case.
|
|
|
|
* @since Envoy Client v0.2-beta
|
|
|
|
*/
|
|
|
|
public static void exit(boolean force) {
|
|
|
|
if (!force && 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
|
|
|
}
|