Add preference clearing
This commit is contained in:
@@ -87,6 +87,10 @@ public class PreferenceScreen {
|
||||
return new ArrayList<>(listPreferences);
|
||||
}
|
||||
|
||||
public void clearPreferences() {
|
||||
listPreferences.clear();
|
||||
}
|
||||
|
||||
public Preference findPreference(String key) {
|
||||
for (Preference preference : listPreferences) {
|
||||
if (preference.getKey() != null && preference.getKey().equals(key)) {
|
||||
|
||||
@@ -79,6 +79,7 @@ public class AniyomiBridge {
|
||||
classLoaders.put(packageName, response.getSecond());
|
||||
if (animeSource instanceof ConfigurableAnimeSource configurableAnimeSource) {
|
||||
PreferenceScreen screen = APP_INSTANCE.getPreferenceScreen(configurableAnimeSource.getId());
|
||||
screen.clearPreferences();
|
||||
configurableAnimeSource.setupPreferenceScreen(screen);
|
||||
}
|
||||
LOGGER.info("Loaded Anime extension: " + animeSource.getClass().getName());
|
||||
@@ -139,6 +140,7 @@ public class AniyomiBridge {
|
||||
classLoaders.put(packageName, response.getSecond());
|
||||
if (mangaSource instanceof ConfigurableSource configurableSource) {
|
||||
PreferenceScreen screen = APP_INSTANCE.getPreferenceScreen(configurableSource.getId());
|
||||
screen.clearPreferences();
|
||||
configurableSource.setupPreferenceScreen(screen);
|
||||
}
|
||||
LOGGER.info("Loaded Manga extension: " + mangaSource.getClass().getName());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.k3vinb5.unyo.core.loader;
|
||||
|
||||
import dev.k3vinb5.unyo.core.loader.interceptors.TorrentioAnimeInteceptor;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.agent.ByteBuddyAgent;
|
||||
import net.bytebuddy.dynamic.loading.ClassReloadingStrategy;
|
||||
@@ -18,18 +17,6 @@ public class ExtensionPatches {
|
||||
public static void applyExtensionPatchesToJVM(Class<?> clazz, URLClassLoader classLoader) {
|
||||
try {
|
||||
switch (clazz.getName()) {
|
||||
case "eu.kanade.tachiyomi.animeextension.all.torrentioanime.Torrentio":
|
||||
LOGGER.infof("Applying Torrentio.makeGraphQLRequest patch to JVM");
|
||||
BYTE_BUDDY
|
||||
.redefine(clazz)
|
||||
.method(ElementMatchers.nameStartsWith("makeGraphQLRequest")
|
||||
.and(ElementMatchers.not(ElementMatchers.isSynthetic())))
|
||||
.intercept(MethodDelegation.to(TorrentioAnimeInteceptor.GraphQLRequestInterceptor.class))
|
||||
.make()
|
||||
.load(classLoader,
|
||||
ClassReloadingStrategy.fromInstalledAgent());
|
||||
break;
|
||||
|
||||
default:
|
||||
LOGGER.warnf("No patches defined for class: %s", clazz.getName());
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package dev.k3vinb5.unyo.core.loader.interceptors;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import eu.kanade.tachiyomi.network.RequestsKt;
|
||||
import net.bytebuddy.implementation.bind.annotation.*;
|
||||
import okhttp3.FormBody;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class TorrentioAnimeInteceptor {
|
||||
|
||||
public static class GraphQLRequestInterceptor {
|
||||
|
||||
@RuntimeType
|
||||
public static Object intercept(@AllArguments Object[] args) throws Exception {
|
||||
String query = (String) args[0];
|
||||
String variables = (String) args[1];
|
||||
System.out.println("Intercepted makeGraphQLRequest");
|
||||
// Patch the variables JSON to set sort to POPULARITY_DESC
|
||||
Gson gson = new Gson();
|
||||
Map<String, Object> map =
|
||||
gson.fromJson(variables, Map.class);
|
||||
map.put("sort", "POPULARITY_DESC");
|
||||
String newVariables = gson.toJson(map);
|
||||
// Call original with modified args
|
||||
FormBody requestBody = new FormBody.Builder()
|
||||
.add("query", query)
|
||||
.add("variables", newVariables)
|
||||
.build();
|
||||
return RequestsKt.POST("https://graphql.anilist.co", RequestsKt.getDEFAULT_HEADERS(), requestBody, RequestsKt.getDEFAULT_CACHE_CONTROL());
|
||||
}
|
||||
}
|
||||
}
|
||||
6
test.sh
6
test.sh
@@ -1 +1,5 @@
|
||||
CP_FILE=$(mktemp) && mvn -pl aniyomi-bridge -q dependency:build-classpath -Dmdep.outputFile="$CP_FILE" && java -cp "aniyomi-bridge/target/classes:$(cat "$CP_FILE")" dev.k3vinb5.unyo.core.cli.Main; rm -f "$CP_FILE"
|
||||
CP_FILE=$(mktemp)
|
||||
mvn -pl androidcompat -q install -DskipTests
|
||||
mvn -pl aniyomi-bridge -am -q dependency:build-classpath -Dmdep.outputFile="$CP_FILE"
|
||||
java -cp "aniyomi-bridge/target/classes:$(cat "$CP_FILE")" dev.k3vinb5.unyo.core.cli.Main
|
||||
rm -f "$CP_FILE"
|
||||
|
||||
Reference in New Issue
Block a user