diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index d57dc46d..04c94de4 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -234,6 +234,7 @@ public void start(String... args) throws Throwable { }; } } + Request.startAutoRefresh(); Request.getRequestService().registerEventHandler(new BasicLauncherEventHandler()); Objects.requireNonNull(args, "args"); if (started.getAndSet(true)) diff --git a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java b/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java index d0649372..e3529e76 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java +++ b/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java @@ -29,7 +29,7 @@ public class DebugMain { public static String projectName = System.getProperty("launcherdebug.projectname", "Minecraft"); public static String unlockSecret = System.getProperty("launcherdebug.unlocksecret", ""); 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[] moduleFiles = System.getProperty("launcherdebug.modulefiles", "").split(","); 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(); } Request.setRequestService(service); - if(autoRefresh) { + if(!disableAutoRefresh) { Request.startAutoRefresh(); } LogHelper.debug("Initialization LauncherEngine"); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index e5c9ec97..a4cd20b0 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -28,20 +28,24 @@ public abstract class Request implements WebSocketRequ private static volatile Map extendedTokens; private static volatile String authId; private static volatile long tokenExpiredTime; - private static ScheduledExecutorService executorService; + private static volatile ScheduledExecutorService executorService; + private static volatile boolean autoRefreshRunning; @LauncherNetworkAPI public final UUID requestUUID = UUID.randomUUID(); private transient final AtomicBoolean started = new AtomicBoolean(false); - public static void startAutoRefresh() { - executorService = Executors.newSingleThreadScheduledExecutor(); - executorService.scheduleAtFixedRate(() -> { - try { - restore(false, true); - } catch (Exception e) { - LogHelper.error(e); - } - }, 60, 60, TimeUnit.SECONDS); + public static synchronized void startAutoRefresh() { + if(!autoRefreshRunning) { + executorService = Executors.newSingleThreadScheduledExecutor(); + executorService.scheduleAtFixedRate(() -> { + try { + restore(false, true); + } catch (Exception e) { + LogHelper.error(e); + } + }, 60, 60, TimeUnit.SECONDS); + autoRefreshRunning = true; + } } public static RequestService getRequestService() {