Skip to content

Commit 821cfd8

Browse files
committed
feat: added logger
1 parent a878b20 commit 821cfd8

1 file changed

Lines changed: 22 additions & 38 deletions

File tree

extensions/extension/src/main/java/app/revanced/extension/customfilters/TintFieldHook.java

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.os.Handler;
55
import android.os.Looper;
6+
import android.util.Log;
67
import android.widget.Toast;
78

89
import java.lang.reflect.Constructor;
@@ -11,27 +12,37 @@
1112
public class TintFieldHook {
1213
public static void installTintField(Object table) {
1314
try {
14-
// Try to show a toast first — to confirm the hook actually runs
15-
showToast("Custom filter hook triggered ✅");
15+
Log.d("ReVancedCustomFilter", "installTintField called!");
1616

1717
ClassLoader cl = table.getClass().getClassLoader();
1818

19+
// Get FigureFiltersToolTable module + context
20+
Class<?> figureFiltersClass = Class.forName(
21+
"org.fortheloss.sticknodes.animationscreen.modules.tooltables.FigureFiltersToolTable",
22+
false,
23+
cl
24+
);
25+
Method getModule = figureFiltersClass.getMethod("getModule");
26+
Object module = getModule.invoke(table);
27+
Method getContext = module.getClass().getMethod("getContext");
28+
Context context = (Context) getContext.invoke(module);
29+
30+
// ✅ Show a Toast to confirm the hook actually ran
31+
new Handler(Looper.getMainLooper()).post(() ->
32+
Toast.makeText(context, "ReVanced filter patch active!", Toast.LENGTH_LONG).show()
33+
);
34+
35+
// Continue with your original code
1936
Class<?> appClass = Class.forName("org.fortheloss.sticknodes.App", false, cl);
2037
Class<?> colorClass = Class.forName("com.badlogic.gdx.graphics.Color", false, cl);
2138
Class<?> labelFieldClass = Class.forName("org.fortheloss.framework.LabelColorInputIncrementField", false, cl);
22-
Class<?> figureFiltersClass = Class.forName("org.fortheloss.sticknodes.animationscreen.modules.tooltables.FigureFiltersToolTable", false, cl);
2339

2440
Constructor<?> ctor = labelFieldClass.getConstructor(
25-
android.content.Context.class,
41+
Context.class,
2642
String.class, String.class, int.class,
2743
float.class, float.class, boolean.class
2844
);
2945

30-
Method getModule = figureFiltersClass.getMethod("getModule");
31-
Object module = getModule.invoke(table);
32-
Method getContext = module.getClass().getMethod("getContext");
33-
Object context = getContext.invoke(module);
34-
3546
Method localize = appClass.getMethod("localize", String.class);
3647
String tintLabel = (String) localize.invoke(null, "tint");
3748

@@ -47,38 +58,11 @@ public static void installTintField(Object table) {
4758
Method setValue = labelFieldClass.getMethod("setValue", colorClass);
4859
setValue.invoke(field, whiteColor);
4960

50-
System.out.println("[CustomFilters] Tint field added successfully!");
61+
Log.d("ReVancedCustomFilter", "installTintField completed successfully!");
5162

5263
} catch (Throwable t) {
64+
Log.e("ReVancedCustomFilter", "Error in installTintField", t);
5365
t.printStackTrace();
54-
showToast("❌ Custom filter hook failed: " + t.getClass().getSimpleName());
55-
}
56-
}
57-
58-
// Show Toast using main thread
59-
private static void showToast(String message) {
60-
try {
61-
Context context = getAppContext();
62-
if (context == null) {
63-
System.out.println("[CustomFilters] No context available for Toast");
64-
return;
65-
}
66-
67-
new Handler(Looper.getMainLooper()).post(() ->
68-
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
69-
);
70-
} catch (Throwable ignored) {
71-
}
72-
}
73-
74-
// Universal app context getter
75-
private static Context getAppContext() {
76-
try {
77-
Class<?> activityThread = Class.forName("android.app.ActivityThread");
78-
Object currentActivityThread = activityThread.getMethod("currentActivityThread").invoke(null);
79-
return (Context) activityThread.getMethod("getApplication").invoke(currentActivityThread);
80-
} catch (Throwable ignored) {
81-
return null;
8266
}
8367
}
8468
}

0 commit comments

Comments
 (0)