Launcher/LauncherClient/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java

40 lines
1.7 KiB
Java
Raw Normal View History

2021-06-05 02:30:56 +03:00
package pro.gravit.launcher;
import pro.gravit.launcher.api.DialogService;
2021-06-05 02:30:56 +03:00
import pro.gravit.launcher.events.ExtendedTokenRequestEvent;
import pro.gravit.launcher.events.NotificationEvent;
2021-06-05 02:30:56 +03:00
import pro.gravit.launcher.events.request.SecurityReportRequestEvent;
import pro.gravit.launcher.request.Request;
2021-11-16 14:32:52 +03:00
import pro.gravit.launcher.request.RequestService;
2021-06-05 02:30:56 +03:00
import pro.gravit.launcher.request.WebSocketEvent;
2021-06-21 10:14:25 +03:00
import pro.gravit.utils.helper.LogHelper;
2021-06-05 02:30:56 +03:00
2021-11-16 14:32:52 +03:00
public class BasicLauncherEventHandler implements RequestService.EventHandler {
2021-06-05 02:30:56 +03:00
@Override
public <T extends WebSocketEvent> boolean eventHandle(T event) {
if (event instanceof SecurityReportRequestEvent) {
SecurityReportRequestEvent event1 = (SecurityReportRequestEvent) event;
if (event1.action == SecurityReportRequestEvent.ReportAction.TOKEN_EXPIRED) {
2021-06-21 10:14:25 +03:00
try {
Request.restore();
} catch (Exception e) {
LogHelper.error(e);
}
}
} else if (event instanceof ExtendedTokenRequestEvent) {
2021-06-05 02:30:56 +03:00
ExtendedTokenRequestEvent event1 = (ExtendedTokenRequestEvent) event;
String token = event1.getExtendedToken();
if (token != null) {
Request.addExtendedToken(event1.getExtendedTokenName(), new Request.ExtendedToken(event1.getExtendedToken(), event1.getExtendedTokenExpire()));
2021-06-05 02:30:56 +03:00
}
} else if (event instanceof NotificationEvent) {
NotificationEvent n = (NotificationEvent) event;
if (DialogService.isNotificationsAvailable()) {
DialogService.createNotification(n.icon, n.head, n.message);
}
2021-06-05 02:30:56 +03:00
}
return false;
}
}