Add pluginhub user count tracking
This commit is contained in:
@@ -39,23 +39,28 @@ import java.security.cert.CertificateFactory;
|
||||
import java.util.List;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Inject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.RuneLiteProperties;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import net.runelite.client.util.VerificationException;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okio.BufferedSource;
|
||||
|
||||
@Slf4j
|
||||
public class ExternalPluginClient
|
||||
{
|
||||
private final OkHttpClient cachingClient;
|
||||
private final OkHttpClient okHttpClient;
|
||||
|
||||
@Inject
|
||||
public ExternalPluginClient(OkHttpClient cachingClient)
|
||||
private ExternalPluginClient(OkHttpClient okHttpClient)
|
||||
{
|
||||
this.cachingClient = cachingClient;
|
||||
this.okHttpClient = okHttpClient;
|
||||
}
|
||||
|
||||
public List<ExternalPluginManifest> downloadManifest() throws IOException, VerificationException
|
||||
@@ -64,7 +69,7 @@ public class ExternalPluginClient
|
||||
.newBuilder()
|
||||
.addPathSegments("manifest.js")
|
||||
.build();
|
||||
try (Response res = cachingClient.newCall(new Request.Builder().url(manifest).build()).execute())
|
||||
try (Response res = okHttpClient.newCall(new Request.Builder().url(manifest).build()).execute())
|
||||
{
|
||||
if (res.code() != 200)
|
||||
{
|
||||
@@ -110,7 +115,7 @@ public class ExternalPluginClient
|
||||
.addPathSegment(plugin.getCommit() + ".png")
|
||||
.build();
|
||||
|
||||
try (Response res = cachingClient.newCall(new Request.Builder().url(url).build()).execute())
|
||||
try (Response res = okHttpClient.newCall(new Request.Builder().url(url).build()).execute())
|
||||
{
|
||||
byte[] bytes = res.body().bytes();
|
||||
// We don't stream so the lock doesn't block the edt trying to load something at the same time
|
||||
@@ -134,4 +139,37 @@ public class ExternalPluginClient
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
void submitPlugins(List<String> plugins)
|
||||
{
|
||||
if (plugins.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||
.addPathSegment("pluginhub")
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(RequestBody.create(RuneLiteAPI.JSON, RuneLiteAPI.GSON.toJson(plugins)))
|
||||
.build();
|
||||
|
||||
okHttpClient.newCall(request).enqueue(new Callback()
|
||||
{
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e)
|
||||
{
|
||||
log.debug("Error submitting plugins", e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response)
|
||||
{
|
||||
log.debug("Submitted plugin list");
|
||||
response.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,10 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@@ -80,23 +82,33 @@ public class ExternalPluginManager
|
||||
@Named("safeMode")
|
||||
private boolean safeMode;
|
||||
|
||||
@Inject
|
||||
private ConfigManager configManager;
|
||||
private final ConfigManager configManager;
|
||||
private final ExternalPluginClient externalPluginClient;
|
||||
private final ScheduledExecutorService executor;
|
||||
private final PluginManager pluginManager;
|
||||
private final EventBus eventBus;
|
||||
private final OkHttpClient okHttpClient;
|
||||
|
||||
@Inject
|
||||
private ExternalPluginClient externalPluginClient;
|
||||
private ExternalPluginManager(
|
||||
ConfigManager configManager,
|
||||
ExternalPluginClient externalPluginClient,
|
||||
ScheduledExecutorService executor,
|
||||
PluginManager pluginManager,
|
||||
EventBus eventBus,
|
||||
OkHttpClient okHttpClient
|
||||
)
|
||||
{
|
||||
this.configManager = configManager;
|
||||
this.externalPluginClient = externalPluginClient;
|
||||
this.executor = executor;
|
||||
this.pluginManager = pluginManager;
|
||||
this.eventBus = eventBus;
|
||||
this.okHttpClient = okHttpClient;
|
||||
|
||||
@Inject
|
||||
private PluginManager pluginManager;
|
||||
|
||||
@Inject
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
@Inject
|
||||
private EventBus eventBus;
|
||||
|
||||
@Inject
|
||||
private OkHttpClient okHttpClient;
|
||||
executor.scheduleWithFixedDelay(() -> externalPluginClient.submitPlugins(getInstalledExternalPlugins()),
|
||||
new Random().nextInt(60), 180, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
public void loadExternalPlugins() throws PluginInstantiationException
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user