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

37 lines
1.5 KiB
Java
Raw Normal View History

2023-12-23 08:05:23 +03:00
package pro.gravit.launcher.client;
2021-06-05 02:30:56 +03:00
2023-12-23 08:05:23 +03:00
import pro.gravit.launcher.client.api.DialogService;
2023-12-23 13:58:09 +03:00
import pro.gravit.launcher.base.events.ExtendedTokenRequestEvent;
import pro.gravit.launcher.base.events.NotificationEvent;
import pro.gravit.launcher.base.events.request.SecurityReportRequestEvent;
import pro.gravit.launcher.base.request.Request;
import pro.gravit.launcher.base.request.RequestService;
import pro.gravit.launcher.base.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) {
2024-03-21 15:40:45 +03:00
if (event instanceof SecurityReportRequestEvent event1) {
if (event1.action == SecurityReportRequestEvent.ReportAction.TOKEN_EXPIRED) {
2021-06-21 10:14:25 +03:00
try {
Request.restore();
} catch (Exception e) {
LogHelper.error(e);
}
}
2024-03-21 15:40:45 +03:00
} else if (event instanceof ExtendedTokenRequestEvent event1) {
2021-06-05 02:30:56 +03:00
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
}
2023-12-23 08:25:11 +03:00
} else if (event instanceof NotificationEvent n) {
if (DialogService.isNotificationsAvailable()) {
DialogService.createNotification(n.icon, n.head, n.message);
}
2021-06-05 02:30:56 +03:00
}
return false;
}
}