|
1 | 1 | package app.revanced.extension.customfilters; |
2 | 2 |
|
| 3 | +import android.content.Context; |
| 4 | +import android.os.Handler; |
| 5 | +import android.os.Looper; |
| 6 | +import android.widget.Toast; |
| 7 | + |
3 | 8 | import java.lang.reflect.Constructor; |
4 | 9 | import java.lang.reflect.Method; |
5 | 10 |
|
6 | 11 | public class TintFieldHook { |
7 | 12 | public static void installTintField(Object table) { |
8 | 13 | try { |
| 14 | + // Try to show a toast first — to confirm the hook actually runs |
| 15 | + showToast("Custom filter hook triggered ✅"); |
| 16 | + |
9 | 17 | ClassLoader cl = table.getClass().getClassLoader(); |
10 | 18 |
|
11 | 19 | Class<?> appClass = Class.forName("org.fortheloss.sticknodes.App", false, cl); |
@@ -39,8 +47,38 @@ public static void installTintField(Object table) { |
39 | 47 | Method setValue = labelFieldClass.getMethod("setValue", colorClass); |
40 | 48 | setValue.invoke(field, whiteColor); |
41 | 49 |
|
| 50 | + System.out.println("[CustomFilters] Tint field added successfully!"); |
| 51 | + |
42 | 52 | } catch (Throwable t) { |
43 | 53 | 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; |
44 | 82 | } |
45 | 83 | } |
46 | 84 | } |
0 commit comments