From bf8afddae275b9ef7568fb68398749d2b3f47941 Mon Sep 17 00:00:00 2001
From: inotia00 <108592928+inotia00@users.noreply.github.com>
Date: Sat, 21 Dec 2024 14:07:30 +0900
Subject: [PATCH] feat(YouTube - Shorts components): Add `Restore old player
layout` setting (YouTube 18.29.38 ~ 19.16.39)
---
.../youtube/patches/shorts/ShortsPatch.java | 4 ++++
.../extension/youtube/settings/Settings.java | 1 +
.../youtube/shorts/components/Fingerprints.kt | 10 ++++++++++
.../shorts/components/ShortsComponentPatch.kt | 12 ++++++++++++
.../youtube/settings/xml/revanced_prefs.xml | 7 ++++++-
5 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/shorts/ShortsPatch.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/shorts/ShortsPatch.java
index ee598aacd..9125a2138 100644
--- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/shorts/ShortsPatch.java
+++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/shorts/ShortsPatch.java
@@ -207,4 +207,8 @@ private static void setNavigationBarLayoutParams(@NonNull ShortsPlayerState shor
);
}
+ public static boolean restoreShortsOldPlayerLayout() {
+ return !Settings.RESTORE_SHORTS_OLD_PLAYER_LAYOUT.get();
+ }
+
}
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 edb48a626..6c2a6ae44 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
@@ -494,6 +494,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting HIDE_SHORTS_NAVIGATION_BAR = new BooleanSetting("revanced_hide_shorts_navigation_bar", FALSE, true);
public static final IntegerSetting SHORTS_NAVIGATION_BAR_HEIGHT_PERCENTAGE = new IntegerSetting("revanced_shorts_navigation_bar_height_percentage", 45, true, parent(HIDE_SHORTS_NAVIGATION_BAR));
public static final BooleanSetting REPLACE_CHANNEL_HANDLE = new BooleanSetting("revanced_replace_channel_handle", FALSE, true);
+ public static final BooleanSetting RESTORE_SHORTS_OLD_PLAYER_LAYOUT = new BooleanSetting("revanced_restore_shorts_old_player_layout", FALSE, true);
// PreferenceScreen: Swipe controls
public static final BooleanSetting ENABLE_SWIPE_BRIGHTNESS = new BooleanSetting("revanced_enable_swipe_brightness", TRUE, true);
diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/Fingerprints.kt
index 7f281b150..3ebc3e3db 100644
--- a/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/Fingerprints.kt
+++ b/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/Fingerprints.kt
@@ -177,3 +177,13 @@ internal val shortsToolBarFingerprint = legacyFingerprint(
method.parameterTypes.firstOrNull() == "Z"
}
)
+
+internal const val FULLSCREEN_FEATURE_FLAG = 45398938L
+
+internal val shortsFullscreenFeatureFingerprint = legacyFingerprint(
+ name = "shortsFullscreenFeatureFingerprint",
+ returnType = "Z",
+ accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
+ literals = listOf(FULLSCREEN_FEATURE_FLAG),
+)
+
diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt
index e68949a0e..8d9bbc34c 100644
--- a/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt
+++ b/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt
@@ -864,6 +864,18 @@ val shortsComponentPatch = bytecodePatch(
// endregion
+ // region patch for restore shorts old player layout
+
+ if (!is_19_25_or_greater) {
+ shortsFullscreenFeatureFingerprint.injectLiteralInstructionBooleanCall(
+ FULLSCREEN_FEATURE_FLAG,
+ "$SHORTS_CLASS_DESCRIPTOR->restoreShortsOldPlayerLayout()Z"
+ )
+ settingArray += "SETTINGS: RESTORE_SHORTS_OLD_PLAYER_LAYOUT"
+ }
+
+ // endregion
+
addLithoFilter(BUTTON_FILTER_CLASS_DESCRIPTOR)
addLithoFilter(SHELF_FILTER_CLASS_DESCRIPTOR)
addLithoFilter(RETURN_YOUTUBE_CHANNEL_NAME_FILTER_CLASS_DESCRIPTOR)
diff --git a/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml
index e0d46bd7b..305dea7e0 100644
--- a/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml
+++ b/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml
@@ -619,7 +619,12 @@
-
+ SETTINGS: SHORTS_COMPONENTS -->
+
+
+
+