From 88709e1222d1f4e76d8ca4a59b2b944affb1d14c Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 7 Nov 2024 08:20:39 -0400 Subject: [PATCH] refactor(YouTube - Theme): Use more robust gradient theme insert index --- .../extension/youtube/patches/theme/ThemePatch.java | 8 +++++++- .../revanced/extension/youtube/settings/Settings.java | 2 +- .../patches/youtube/layout/theme/ThemePatch.kt | 11 +++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/theme/ThemePatch.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/theme/ThemePatch.java index 77372e400..bb189bc67 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/theme/ThemePatch.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/theme/ThemePatch.java @@ -21,6 +21,8 @@ public class ThemePatch { -98492127 // video chapters list background }; + private static final boolean GRADIENT_LOADING_SCREEN_ENABLED = Settings.GRADIENT_LOADING_SCREEN.get(); + // background colors private static int whiteColor = 0; private static int blackColor = 0; @@ -39,25 +41,29 @@ public class ThemePatch { } else { if (anyEquals(originalValue, WHITE_VALUES)) return getWhiteColor(); } + return originalValue; } public static boolean gradientLoadingScreenEnabled() { - return Settings.GRADIENT_LOADING_SCREEN.get(); + return GRADIENT_LOADING_SCREEN_ENABLED; } private static int getBlackColor() { if (blackColor == 0) blackColor = Utils.getResourceColor("yt_black1"); + return blackColor; } private static int getWhiteColor() { if (whiteColor == 0) whiteColor = Utils.getResourceColor("yt_white1"); + return whiteColor; } private static boolean anyEquals(int value, int... of) { for (int v : of) if (value == v) return true; + return false; } } diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java index edcdecfa1..dc0d15d18 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -80,7 +80,7 @@ public class Settings extends BaseSettings { // Uncategorized layout related settings. Do not add to this section, and instead move these out and categorize them. public static final BooleanSetting DISABLE_SUGGESTED_VIDEO_END_SCREEN = new BooleanSetting("revanced_disable_suggested_video_end_screen", FALSE, true); - public static final BooleanSetting GRADIENT_LOADING_SCREEN = new BooleanSetting("revanced_gradient_loading_screen", FALSE); + public static final BooleanSetting GRADIENT_LOADING_SCREEN = new BooleanSetting("revanced_gradient_loading_screen", FALSE, true); public static final BooleanSetting HIDE_HORIZONTAL_SHELVES = new BooleanSetting("revanced_hide_horizontal_shelves", TRUE); public static final BooleanSetting HIDE_CAPTIONS_BUTTON = new BooleanSetting("revanced_hide_captions_button", FALSE); public static final BooleanSetting HIDE_CHANNEL_BAR = new BooleanSetting("revanced_hide_channel_bar", FALSE); diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt index 7becb91d1..194c4dbba 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt @@ -17,7 +17,9 @@ import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.util.forEachChildElement +import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstLiteralInstructionOrThrow +import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import org.w3c.dom.Element @@ -210,18 +212,19 @@ val themePatch = bytecodePatch( ) useGradientLoadingScreenFingerprint.method.apply { - - val isEnabledIndex = indexOfFirstLiteralInstructionOrThrow(GRADIENT_LOADING_SCREEN_AB_CONSTANT) + 3 - val isEnabledRegister = getInstruction(isEnabledIndex - 1).registerA + val literalIndex = indexOfFirstLiteralInstructionOrThrow(GRADIENT_LOADING_SCREEN_AB_CONSTANT) + val isEnabledIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.MOVE_RESULT) + val isEnabledRegister = getInstruction(isEnabledIndex).registerA addInstructions( - isEnabledIndex, + isEnabledIndex + 1, """ invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->gradientLoadingScreenEnabled()Z move-result v$isEnabledRegister """, ) } + mapOf( themeHelperLightColorFingerprint to lightThemeBackgroundColor, themeHelperDarkColorFingerprint to darkThemeBackgroundColor,