[FIX] Enable autoRefresh in default

This commit is contained in:
Gravita 2023-10-29 03:24:27 +07:00
parent a3bcfed793
commit 224649aa13
3 changed files with 17 additions and 12 deletions

View file

@ -234,6 +234,7 @@ public void start(String... args) throws Throwable {
}; };
} }
} }
Request.startAutoRefresh();
Request.getRequestService().registerEventHandler(new BasicLauncherEventHandler()); Request.getRequestService().registerEventHandler(new BasicLauncherEventHandler());
Objects.requireNonNull(args, "args"); Objects.requireNonNull(args, "args");
if (started.getAndSet(true)) if (started.getAndSet(true))

View file

@ -29,7 +29,7 @@ public class DebugMain {
public static String projectName = System.getProperty("launcherdebug.projectname", "Minecraft"); public static String projectName = System.getProperty("launcherdebug.projectname", "Minecraft");
public static String unlockSecret = System.getProperty("launcherdebug.unlocksecret", ""); public static String unlockSecret = System.getProperty("launcherdebug.unlocksecret", "");
public static boolean offlineMode = Boolean.getBoolean("launcherdebug.offlinemode"); public static boolean offlineMode = Boolean.getBoolean("launcherdebug.offlinemode");
public static boolean autoRefresh = Boolean.getBoolean("launcherdebug.autorefresh"); public static boolean disableAutoRefresh = Boolean.getBoolean("launcherdebug.disableautorefresh");
public static String[] moduleClasses = System.getProperty("launcherdebug.modules", "").split(","); public static String[] moduleClasses = System.getProperty("launcherdebug.modules", "").split(",");
public static String[] moduleFiles = System.getProperty("launcherdebug.modulefiles", "").split(","); public static String[] moduleFiles = System.getProperty("launcherdebug.modulefiles", "").split(",");
public static LauncherConfig.LauncherEnvironment environment = LauncherConfig.LauncherEnvironment.valueOf(System.getProperty("launcherdebug.env", "STD")); public static LauncherConfig.LauncherEnvironment environment = LauncherConfig.LauncherEnvironment.valueOf(System.getProperty("launcherdebug.env", "STD"));
@ -69,7 +69,7 @@ public static void main(String[] args) throws Throwable {
service = StdWebSocketService.initWebSockets(webSocketURL).get(); service = StdWebSocketService.initWebSockets(webSocketURL).get();
} }
Request.setRequestService(service); Request.setRequestService(service);
if(autoRefresh) { if(!disableAutoRefresh) {
Request.startAutoRefresh(); Request.startAutoRefresh();
} }
LogHelper.debug("Initialization LauncherEngine"); LogHelper.debug("Initialization LauncherEngine");

View file

@ -28,12 +28,14 @@ public abstract class Request<R extends WebSocketEvent> implements WebSocketRequ
private static volatile Map<String, ExtendedToken> extendedTokens; private static volatile Map<String, ExtendedToken> extendedTokens;
private static volatile String authId; private static volatile String authId;
private static volatile long tokenExpiredTime; private static volatile long tokenExpiredTime;
private static ScheduledExecutorService executorService; private static volatile ScheduledExecutorService executorService;
private static volatile boolean autoRefreshRunning;
@LauncherNetworkAPI @LauncherNetworkAPI
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 void startAutoRefresh() { public static synchronized void startAutoRefresh() {
if(!autoRefreshRunning) {
executorService = Executors.newSingleThreadScheduledExecutor(); executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(() -> { executorService.scheduleAtFixedRate(() -> {
try { try {
@ -42,6 +44,8 @@ public static void startAutoRefresh() {
LogHelper.error(e); LogHelper.error(e);
} }
}, 60, 60, TimeUnit.SECONDS); }, 60, 60, TimeUnit.SECONDS);
autoRefreshRunning = true;
}
} }
public static RequestService getRequestService() { public static RequestService getRequestService() {