runelite-client: Start the ClientLoader running before injection starts

This saves about a second of startup time. It also removes the possibly incorrect ClientUpdateCheckMode from the RuneLiteModule
This commit is contained in:
Max Weber
2019-04-05 05:24:05 -06:00
parent fa99ba9cf8
commit 64643c136d
6 changed files with 55 additions and 58 deletions

View File

@@ -58,6 +58,7 @@ import net.runelite.client.menus.MenuManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginInstantiationException;
import net.runelite.client.plugins.PluginManager;
import net.runelite.client.rs.ClientLoader;
import net.runelite.client.rs.ClientUpdateCheckMode;
import net.runelite.client.ui.ClientUI;
import net.runelite.client.ui.DrawManager;
@@ -183,20 +184,6 @@ public class RuneLite
System.exit(0);
}
final boolean developerMode = options.has("developer-mode") && RuneLiteProperties.getLauncherVersion() == null;
if (developerMode)
{
boolean assertions = false;
assert assertions = true;
if (!assertions)
{
throw new RuntimeException("Developers should enable assertions; Add `-ea` to your JVM arguments`");
}
}
PROFILES_DIR.mkdirs();
if (options.has("debug"))
{
final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
@@ -212,10 +199,31 @@ public class RuneLite
}
});
final ClientLoader clientLoader = new ClientLoader(options.valueOf(updateMode));
new Thread(() ->
{
clientLoader.get();
}, "Preloader").start();
final boolean developerMode = options.has("developer-mode") && RuneLiteProperties.getLauncherVersion() == null;
if (developerMode)
{
boolean assertions = false;
assert assertions = true;
if (!assertions)
{
throw new RuntimeException("Developers should enable assertions; Add `-ea` to your JVM arguments`");
}
}
PROFILES_DIR.mkdirs();
final long start = System.currentTimeMillis();
injector = Guice.createInjector(new RuneLiteModule(
options.valueOf(updateMode),
clientLoader,
developerMode));
injector.getInstance(RuneLite.class).start();

View File

@@ -30,6 +30,7 @@ import com.google.inject.name.Names;
import java.applet.Applet;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import javax.inject.Singleton;
import net.runelite.api.Client;
@@ -44,8 +45,6 @@ import net.runelite.client.eventbus.EventBus;
import net.runelite.client.game.ItemManager;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.plugins.PluginManager;
import net.runelite.client.rs.ClientLoader;
import net.runelite.client.rs.ClientUpdateCheckMode;
import net.runelite.client.task.Scheduler;
import net.runelite.client.util.DeferredEventBus;
import net.runelite.client.util.ExecutorServiceExceptionLogger;
@@ -56,19 +55,18 @@ import org.slf4j.LoggerFactory;
public class RuneLiteModule extends AbstractModule
{
private final ClientUpdateCheckMode updateCheckMode;
private final Supplier<Applet> clientLoader;
private final boolean developerMode;
public RuneLiteModule(final ClientUpdateCheckMode updateCheckMode, final boolean developerMode)
public RuneLiteModule(Supplier<Applet> clientLoader, boolean developerMode)
{
this.updateCheckMode = updateCheckMode;
this.clientLoader = clientLoader;
this.developerMode = developerMode;
}
@Override
protected void configure()
{
bindConstant().annotatedWith(Names.named("updateCheckMode")).to(updateCheckMode);
bindConstant().annotatedWith(Names.named("developerMode")).to(developerMode);
bind(ScheduledExecutorService.class).toInstance(new ExecutorServiceExceptionLogger(Executors.newSingleThreadScheduledExecutor()));
bind(OkHttpClient.class).toInstance(RuneLiteAPI.CLIENT);
@@ -96,9 +94,9 @@ public class RuneLiteModule extends AbstractModule
@Provides
@Singleton
Applet provideApplet(ClientLoader clientLoader)
Applet provideApplet()
{
return clientLoader.load();
return clientLoader.get();
}
@Provides

View File

@@ -25,30 +25,22 @@
*/
package net.runelite.client.rs;
import com.google.common.annotations.VisibleForTesting;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.inject.Inject;
import javax.inject.Singleton;
import okhttp3.OkHttpClient;
import net.runelite.http.api.RuneLiteAPI;
import okhttp3.Request;
import okhttp3.Response;
@Singleton
class ClientConfigLoader
{
private static final String CONFIG_URL = "http://oldschool.runescape.com/jav_config.ws";
private final OkHttpClient httpClient;
@Inject
@VisibleForTesting
ClientConfigLoader(final OkHttpClient httpClient)
private ClientConfigLoader()
{
this.httpClient = httpClient;
}
RSConfig fetch() throws IOException
private static final String CONFIG_URL = "http://oldschool.runescape.com/jav_config.ws";
static RSConfig fetch() throws IOException
{
final Request request = new Request.Builder()
.url(CONFIG_URL)
@@ -56,8 +48,8 @@ class ClientConfigLoader
final RSConfig config = new RSConfig();
try (final Response response = httpClient.newCall(request).execute(); final BufferedReader in = new BufferedReader(
new InputStreamReader(response.body().byteStream())))
try (final Response response = RuneLiteAPI.CLIENT.newCall(request).execute();
final BufferedReader in = new BufferedReader(new InputStreamReader(response.body().byteStream())))
{
String str;

View File

@@ -45,11 +45,9 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import static net.runelite.client.rs.ClientUpdateCheckMode.AUTO;
@@ -61,22 +59,27 @@ import okhttp3.Response;
import org.apache.commons.compress.compressors.CompressorException;
@Slf4j
@Singleton
public class ClientLoader
public class ClientLoader implements Supplier<Applet>
{
private final ClientConfigLoader clientConfigLoader;
private ClientUpdateCheckMode updateCheckMode;
private Applet client = null;
@Inject
private ClientLoader(
@Named("updateCheckMode") final ClientUpdateCheckMode updateCheckMode,
final ClientConfigLoader clientConfigLoader)
public ClientLoader(ClientUpdateCheckMode updateCheckMode)
{
this.updateCheckMode = updateCheckMode;
this.clientConfigLoader = clientConfigLoader;
}
public Applet load()
@Override
public synchronized Applet get()
{
if (client == null)
{
client = doLoad();
}
return client;
}
private Applet doLoad()
{
if (updateCheckMode == NONE)
{
@@ -85,7 +88,7 @@ public class ClientLoader
try
{
RSConfig config = clientConfigLoader.fetch();
RSConfig config = ClientConfigLoader.fetch();
Map<String, byte[]> zipFile = new HashMap<>();
{

View File

@@ -51,7 +51,6 @@ import net.runelite.client.RuneLiteModule;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.rs.ClientUpdateCheckMode;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Rule;
@@ -84,7 +83,7 @@ public class PluginManagerTest
public void before() throws IOException
{
Injector injector = Guice.createInjector(Modules
.override(new RuneLiteModule(ClientUpdateCheckMode.AUTO, true))
.override(new RuneLiteModule(() -> null, true))
.with(BoundFieldModule.of(this)));
RuneLite.setInjector(injector);
@@ -108,7 +107,6 @@ public class PluginManagerTest
configClasses.add(clazz);
}
}
}
@Test
@@ -146,7 +144,7 @@ public class PluginManagerTest
{
List<Module> modules = new ArrayList<>();
modules.add(new GraphvizModule());
modules.add(new RuneLiteModule(ClientUpdateCheckMode.AUTO, true));
modules.add(new RuneLiteModule(() -> null, true));
PluginManager pluginManager = new PluginManager(true, null, null, null, null, null);
pluginManager.loadCorePlugins();

View File

@@ -26,7 +26,6 @@
package net.runelite.client.rs;
import java.io.IOException;
import okhttp3.OkHttpClient;
import org.junit.Test;
/**
@@ -38,8 +37,7 @@ public class ClientConfigLoaderTest
@Test
public void test() throws IOException
{
final ClientConfigLoader loader = new ClientConfigLoader(new OkHttpClient());
final RSConfig config = loader.fetch();
final RSConfig config = ClientConfigLoader.fetch();
for (String key : config.getClassLoaderProperties().keySet())
{