idea cleanup launcherapi

This commit is contained in:
dima_dencep 2022-09-24 00:29:22 +07:00
parent 045ed67f12
commit 7c36f341e4
12 changed files with 50 additions and 61 deletions

View file

@ -1,8 +1,5 @@
package pro.gravit.launcher; package pro.gravit.launcher;
import pro.gravit.launcher.serialize.HInput;
import java.io.IOException;
import java.util.*; import java.util.*;
public class ClientPermissions { public class ClientPermissions {

View file

@ -1,7 +1,6 @@
package pro.gravit.launcher.profiles; package pro.gravit.launcher.profiles;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.VerifyHelper;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View file

@ -5,6 +5,7 @@
public class ArchTrigger extends OptionalTrigger { public class ArchTrigger extends OptionalTrigger {
public JVMHelper.ARCH arch; public JVMHelper.ARCH arch;
@Override @Override
protected boolean isTriggered(OptionalFile optional, OptionalTriggerContext context) { protected boolean isTriggered(OptionalFile optional, OptionalTriggerContext context) {
return context.getJavaVersion().arch == arch; return context.getJavaVersion().arch == arch;

View file

@ -28,6 +28,10 @@ public abstract class Request<R extends WebSocketEvent> implements WebSocketRequ
public final UUID requestUUID = UUID.randomUUID(); public final UUID requestUUID = UUID.randomUUID();
private transient final AtomicBoolean started = new AtomicBoolean(false); private transient final AtomicBoolean started = new AtomicBoolean(false);
public static RequestService getRequestService() {
return requestService;
}
public static void setRequestService(RequestService service) { public static void setRequestService(RequestService service) {
requestService = service; requestService = service;
if (service instanceof StdWebSocketService) { if (service instanceof StdWebSocketService) {
@ -35,10 +39,6 @@ public static void setRequestService(RequestService service) {
} }
} }
public static RequestService getRequestService() {
return requestService;
}
public static boolean isAvailable() { public static boolean isAvailable() {
return requestService != null; return requestService != null;
} }
@ -121,18 +121,6 @@ public static RequestRestoreReport reconnect() throws Exception {
return restore(); return restore();
} }
public static class RequestRestoreReport {
public final boolean legacySession;
public final boolean refreshed;
public final List<String> invalidExtendedTokens;
public RequestRestoreReport(boolean legacySession, boolean refreshed, List<String> invalidExtendedTokens) {
this.legacySession = legacySession;
this.refreshed = refreshed;
this.invalidExtendedTokens = invalidExtendedTokens;
}
}
public static RequestRestoreReport restore() throws Exception { public static RequestRestoreReport restore() throws Exception {
boolean refreshed = false; boolean refreshed = false;
RestoreRequest request; RestoreRequest request;
@ -224,4 +212,16 @@ public interface ExtendedTokenCallback {
String tryGetNewToken(String name); String tryGetNewToken(String name);
} }
public static class RequestRestoreReport {
public final boolean legacySession;
public final boolean refreshed;
public final List<String> invalidExtendedTokens;
public RequestRestoreReport(boolean legacySession, boolean refreshed, List<String> invalidExtendedTokens) {
this.legacySession = legacySession;
this.refreshed = refreshed;
this.invalidExtendedTokens = invalidExtendedTokens;
}
}
} }

View file

@ -6,8 +6,11 @@
public interface RequestService { public interface RequestService {
<T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException; <T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException;
void registerEventHandler(EventHandler handler); void registerEventHandler(EventHandler handler);
void unregisterEventHandler(EventHandler handler); void unregisterEventHandler(EventHandler handler);
default <T extends WebSocketEvent> T requestSync(Request<T> request) throws IOException { default <T extends WebSocketEvent> T requestSync(Request<T> request) throws IOException {
try { try {
return request(request).get(); return request(request).get();

View file

@ -5,21 +5,13 @@
import pro.gravit.launcher.events.request.LauncherRequestEvent; import pro.gravit.launcher.events.request.LauncherRequestEvent;
import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.RequestService; import pro.gravit.launcher.request.RequestService;
import pro.gravit.launcher.request.websockets.StdWebSocketService;
import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.launcher.request.websockets.WebSocketRequest;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
public final class LauncherRequest extends Request<LauncherRequestEvent> implements WebSocketRequest { public final class LauncherRequest extends Request<LauncherRequestEvent> implements WebSocketRequest {
public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class); public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class);

View file

@ -5,7 +5,6 @@
import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.launcher.request.websockets.WebSocketRequest;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.VerifyHelper;
import java.io.IOException; import java.io.IOException;

View file

@ -4,7 +4,6 @@
import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent; import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.launcher.request.websockets.WebSocketRequest;
import pro.gravit.utils.helper.VerifyHelper;
public final class ProfileByUsernameRequest extends Request<ProfileByUsernameRequestEvent> implements WebSocketRequest { public final class ProfileByUsernameRequest extends Request<ProfileByUsernameRequestEvent> implements WebSocketRequest {
@LauncherNetworkAPI @LauncherNetworkAPI

View file

@ -24,7 +24,6 @@
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer; import java.util.function.Consumer;

View file

@ -16,6 +16,7 @@
public class OfflineRequestService implements RequestService { public class OfflineRequestService implements RequestService {
private final HashSet<EventHandler> eventHandlers = new HashSet<>(); private final HashSet<EventHandler> eventHandlers = new HashSet<>();
private final Map<Class<?>, RequestProcessor<?, ?>> processors = new ConcurrentHashMap<>(); private final Map<Class<?>, RequestProcessor<?, ?>> processors = new ConcurrentHashMap<>();
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException { public <T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException {

View file

@ -55,7 +55,6 @@ public static CompletableFuture<StdWebSocketService> initWebSockets(String addre
} }
@Deprecated @Deprecated
public void registerEventHandler(ClientWebSocketService.EventHandler handler) { public void registerEventHandler(ClientWebSocketService.EventHandler handler) {
legacyEventHandlers.add(handler); legacyEventHandlers.add(handler);