46 lines
1.1 KiB
Java
46 lines
1.1 KiB
Java
package envoy.client.helper;
|
|
|
|
import dev.kske.eventbus.EventBus;
|
|
|
|
import envoy.client.data.*;
|
|
import envoy.client.event.EnvoyCloseEvent;
|
|
import envoy.client.ui.StatusTrayIcon;
|
|
|
|
/**
|
|
* Simplifies shutdown actions.
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
else {
|
|
EventBus.getInstance().dispatch(new EnvoyCloseEvent());
|
|
System.exit(0);
|
|
}
|
|
}
|
|
}
|