2021-06-05 02:30:56 +03:00
|
|
|
package pro.gravit.launcher;
|
|
|
|
|
2021-07-04 16:01:24 +03:00
|
|
|
import pro.gravit.launcher.api.DialogService;
|
2021-06-05 02:30:56 +03:00
|
|
|
import pro.gravit.launcher.events.ExtendedTokenRequestEvent;
|
2021-07-04 16:01:24 +03:00
|
|
|
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;
|
2023-07-27 16:03:49 +03:00
|
|
|
if (event1.action == SecurityReportRequestEvent.ReportAction.TOKEN_EXPIRED) {
|
2021-06-21 10:14:25 +03:00
|
|
|
try {
|
|
|
|
Request.restore();
|
|
|
|
} catch (Exception e) {
|
|
|
|
LogHelper.error(e);
|
|
|
|
}
|
|
|
|
}
|
2021-07-21 19:43:47 +03:00
|
|
|
} else if (event instanceof ExtendedTokenRequestEvent) {
|
2021-06-05 02:30:56 +03:00
|
|
|
ExtendedTokenRequestEvent event1 = (ExtendedTokenRequestEvent) event;
|
|
|
|
String token = event1.getExtendedToken();
|
|
|
|
if (token != null) {
|
2023-08-13 13:57:08 +03:00
|
|
|
Request.addExtendedToken(event1.getExtendedTokenName(), new Request.ExtendedToken(event1.getExtendedToken(), event1.getExtendedTokenExpire()));
|
2021-06-05 02:30:56 +03:00
|
|
|
}
|
2021-07-04 16:01:24 +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;
|
|
|
|
}
|
|
|
|
}
|