This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/client/src/main/java/envoy/client/helper/ShutdownHelper.java

46 lines
1.1 KiB
Java
Raw Normal View History

package envoy.client.helper;
2021-02-19 11:09:07 +01:00
import dev.kske.eventbus.core.EventBus;
import envoy.client.data.*;
import envoy.client.event.EnvoyCloseEvent;
import envoy.client.ui.StatusTrayIcon;
/**
2020-09-26 21:38:31 +02:00
* Simplifies shutdown actions.
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
2020-09-26 21:38:31 +02:00
public final class ShutdownHelper {
private ShutdownHelper() {}
/**
* Exits Envoy or minimizes it, depending on the current state of
* {@link Settings#isHideOnClose()} and {@link StatusTrayIcon#isSupported()}.
*
* @since Envoy Client v0.2-beta
*/
public static void exit() {
exit(false);
}
2020-10-08 22:07:37 +02:00
/**
* 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()}.
2020-10-08 22:07:37 +02:00
*
* @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);
else {
EventBus.getInstance().dispatch(new EnvoyCloseEvent());
System.exit(0);
}
}
}