Skip to content

Commit

Permalink
refactor(YouTube - Theme): Use more robust gradient theme insert index
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed Nov 7, 2024
1 parent 3e285e5 commit 88709e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,25 +41,29 @@ public static int getValue(int originalValue) {
} 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -210,18 +212,19 @@ val themePatch = bytecodePatch(
)

useGradientLoadingScreenFingerprint.method.apply {

val isEnabledIndex = indexOfFirstLiteralInstructionOrThrow(GRADIENT_LOADING_SCREEN_AB_CONSTANT) + 3
val isEnabledRegister = getInstruction<OneRegisterInstruction>(isEnabledIndex - 1).registerA
val literalIndex = indexOfFirstLiteralInstructionOrThrow(GRADIENT_LOADING_SCREEN_AB_CONSTANT)
val isEnabledIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.MOVE_RESULT)
val isEnabledRegister = getInstruction<OneRegisterInstruction>(isEnabledIndex).registerA

addInstructions(
isEnabledIndex,
isEnabledIndex + 1,
"""
invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->gradientLoadingScreenEnabled()Z
move-result v$isEnabledRegister
""",
)
}

mapOf(
themeHelperLightColorFingerprint to lightThemeBackgroundColor,
themeHelperDarkColorFingerprint to darkThemeBackgroundColor,
Expand Down

0 comments on commit 88709e1

Please sign in to comment.