feat(YouTube): Add patch Disable resuming Miniplayer on startup https://github.com/inotia00/ReVanced_Extended/issues/469

This commit is contained in:
inotia00 2025-02-11 17:03:15 +09:00
parent 8e5ea0a8d8
commit ddbfc747b8
9 changed files with 107 additions and 4 deletions

View File

@ -147,6 +147,9 @@ public final class MiniplayerPatch {
private static final int MODERN_OVERLAY_SUBTITLE_TEXT private static final int MODERN_OVERLAY_SUBTITLE_TEXT
= ResourceUtils.getIdIdentifier("modern_miniplayer_subtitle_text"); = ResourceUtils.getIdIdentifier("modern_miniplayer_subtitle_text");
private static final boolean DISABLE_RESUMING_MINIPLAYER =
Settings.DISABLE_RESUMING_MINIPLAYER.get();
private static final MiniplayerType CURRENT_TYPE = Settings.MINIPLAYER_TYPE.get(); private static final MiniplayerType CURRENT_TYPE = Settings.MINIPLAYER_TYPE.get();
/** /**
@ -219,6 +222,13 @@ public final class MiniplayerPatch {
} }
} }
/**
* Injection point.
*/
public static boolean disableResumingStartupMiniPlayer(boolean original) {
return !DISABLE_RESUMING_MINIPLAYER && original;
}
/** /**
* Injection point. * Injection point.
* <p> * <p>

View File

@ -365,6 +365,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting DISABLE_HAPTIC_FEEDBACK_ZOOM = new BooleanSetting("revanced_disable_haptic_feedback_zoom", FALSE); public static final BooleanSetting DISABLE_HAPTIC_FEEDBACK_ZOOM = new BooleanSetting("revanced_disable_haptic_feedback_zoom", FALSE);
// PreferenceScreen: Player - Miniplayer // PreferenceScreen: Player - Miniplayer
public static final BooleanSetting DISABLE_RESUMING_MINIPLAYER = new BooleanSetting("revanced_disable_resuming_miniplayer", FALSE, true);
public static final EnumSetting<MiniplayerType> MINIPLAYER_TYPE = new EnumSetting<>("revanced_miniplayer_type", MiniplayerType.DEFAULT, true); public static final EnumSetting<MiniplayerType> MINIPLAYER_TYPE = new EnumSetting<>("revanced_miniplayer_type", MiniplayerType.DEFAULT, true);
private static final Setting.Availability MINIPLAYER_ANY_MODERN = MINIPLAYER_TYPE.availability(MODERN_1, MODERN_2, MODERN_3, MODERN_4); private static final Setting.Availability MINIPLAYER_ANY_MODERN = MINIPLAYER_TYPE.availability(MODERN_1, MODERN_2, MODERN_3, MODERN_4);
public static final BooleanSetting MINIPLAYER_DOUBLE_TAP_ACTION = new BooleanSetting("revanced_miniplayer_double_tap_action", TRUE, true, MINIPLAYER_ANY_MODERN); public static final BooleanSetting MINIPLAYER_DOUBLE_TAP_ACTION = new BooleanSetting("revanced_miniplayer_double_tap_action", TRUE, true, MINIPLAYER_ANY_MODERN);

View File

@ -1,6 +1,6 @@
@file:Suppress("SpellCheckingInspection") @file:Suppress("SpellCheckingInspection")
package app.revanced.patches.youtube.player.miniplayer package app.revanced.patches.youtube.player.miniplayer.general
import app.revanced.patches.youtube.utils.resourceid.floatyBarTopMargin import app.revanced.patches.youtube.utils.resourceid.floatyBarTopMargin
import app.revanced.patches.youtube.utils.resourceid.miniplayerMaxSize import app.revanced.patches.youtube.utils.resourceid.miniplayerMaxSize

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.player.miniplayer package app.revanced.patches.youtube.player.miniplayer.general
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructions

View File

@ -0,0 +1,26 @@
@file:Suppress("SpellCheckingInspection")
package app.revanced.patches.youtube.player.miniplayer.startup
import app.revanced.util.fingerprint.legacyFingerprint
import app.revanced.util.or
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
/**
* Tested on YouTube 18.25.40 ~ 20.05.44
*
* This fingerprint is not compatible with YouTube 18.19.36 or earlier
*/
internal val showMiniplayerCommandFingerprint = legacyFingerprint(
name = "showMiniplayerCommandFingerprint",
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L", "Ljava/util/Map;"),
// Opcode pattern looks very weak, but it's not really.
opcodes = listOf(
Opcode.IF_NEZ,
Opcode.IF_EQZ,
),
literals = listOf(121253L, 164817L),
)

View File

@ -0,0 +1,55 @@
package app.revanced.patches.youtube.player.miniplayer.startup
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.extension.Constants.PLAYER_PATH
import app.revanced.patches.youtube.utils.patch.PatchList.DISABLE_RESUMING_MINIPLAYER_ON_STARTUP
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
import app.revanced.patches.youtube.utils.settings.settingsPatch
import app.revanced.util.fingerprint.matchOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
private const val EXTENSION_CLASS_DESCRIPTOR =
"$PLAYER_PATH/MiniplayerPatch;"
// YT uses "Miniplayer" without a space between 'mini' and 'player: https://support.google.com/youtube/answer/9162927.
@Suppress("unused", "SpellCheckingInspection")
val resumingMiniplayerOnStartupPatch = bytecodePatch(
DISABLE_RESUMING_MINIPLAYER_ON_STARTUP.title,
DISABLE_RESUMING_MINIPLAYER_ON_STARTUP.summary,
) {
compatibleWith(COMPATIBLE_PACKAGE)
dependsOn(settingsPatch)
execute {
showMiniplayerCommandFingerprint.matchOrThrow().let {
it.method.apply {
val insertIndex = it.patternMatch!!.endIndex
val insertRegister =
getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
insertIndex, """
invoke-static {v$insertRegister}, $EXTENSION_CLASS_DESCRIPTOR->disableResumingStartupMiniPlayer(Z)Z
move-result v$insertRegister
"""
)
}
}
addPreference(
arrayOf(
"PREFERENCE_SCREEN: PLAYER",
"SETTINGS: MINIPLAYER_COMPONENTS",
"SETTINGS: DISABLE_RESUMING_MINIPLAYER"
),
DISABLE_RESUMING_MINIPLAYER_ON_STARTUP
)
}
}

View File

@ -81,6 +81,10 @@ internal enum class PatchList(
"Disable haptic feedback", "Disable haptic feedback",
"Adds options to disable haptic feedback when swiping in the video player." "Adds options to disable haptic feedback when swiping in the video player."
), ),
DISABLE_RESUMING_MINIPLAYER_ON_STARTUP(
"Disable resuming Miniplayer on startup",
"Adds an option to disable the Miniplayer 'Continue watching' from resuming on app startup."
),
DISABLE_RESUMING_SHORTS_ON_STARTUP( DISABLE_RESUMING_SHORTS_ON_STARTUP(
"Disable resuming Shorts on startup", "Disable resuming Shorts on startup",
"Adds an option to disable the Shorts player from resuming on app startup when Shorts were last being watched." "Adds an option to disable the Shorts player from resuming on app startup when Shorts were last being watched."

View File

@ -1085,8 +1085,11 @@ Limitation: Video title disappears when clicked."</string>
<!-- PreferenceScreen: Player, PreferenceCategory: Player, PreferenceScreen: Miniplayer --> <!-- PreferenceScreen: Player, PreferenceCategory: Player, PreferenceScreen: Miniplayer -->
<string name="revanced_preference_screen_miniplayer_title">Miniplayer</string> <string name="revanced_preference_screen_miniplayer_title">Miniplayer</string>
<string name="revanced_preference_screen_miniplayer_summary">Change the style of the in-app minimized player.</string> <string name="revanced_preference_screen_miniplayer_summary">Hide or change components related to Miniplayer.</string>
<string name="revanced_disable_resuming_miniplayer_title">Disable resuming Miniplayer</string>
<string name="revanced_disable_resuming_miniplayer_summary_on">&lt;b>Continue watching&lt;/b> will not resume on app startup.</string>
<string name="revanced_disable_resuming_miniplayer_summary_off">&lt;b>Continue watching&lt;/b> will resume on app startup.&lt;br>&lt;br>Info:&lt;br>• &lt;b>Continue watching&lt;/b> is the YouTube Premium feature.&lt;br>• This setting does not force &lt;b>Continue watching&lt;/b> to be enabled.</string>
<string name="revanced_miniplayer_type_title">Miniplayer type</string> <string name="revanced_miniplayer_type_title">Miniplayer type</string>
<string name="revanced_miniplayer_type_entry_0">Disabled</string> <string name="revanced_miniplayer_type_entry_0">Disabled</string>
<string name="revanced_miniplayer_type_entry_1">Default</string> <string name="revanced_miniplayer_type_entry_1">Default</string>
@ -1102,7 +1105,7 @@ Limitation: Video title disappears when clicked."</string>
<string name="revanced_miniplayer_double_tap_action_title">Enable double-tap and pinch to resize</string> <string name="revanced_miniplayer_double_tap_action_title">Enable double-tap and pinch to resize</string>
<string name="revanced_miniplayer_double_tap_action_summary_on">"Double-tap action and pinch to resize is enabled. <string name="revanced_miniplayer_double_tap_action_summary_on">"Double-tap action and pinch to resize is enabled.
• Double tap to increase miniplayer size. • Double tap to increase Miniplayer size.
• Double tap again to restore original size."</string> • Double tap again to restore original size."</string>
<string name="revanced_miniplayer_double_tap_action_summary_off">Double-tap action and pinch to resize is disabled.</string> <string name="revanced_miniplayer_double_tap_action_summary_off">Double-tap action and pinch to resize is disabled.</string>
<string name="revanced_miniplayer_drag_and_drop_title">Enable drag and drop</string> <string name="revanced_miniplayer_drag_and_drop_title">Enable drag and drop</string>

View File

@ -418,6 +418,9 @@
<!-- SETTINGS: MINIPLAYER_COMPONENTS <!-- SETTINGS: MINIPLAYER_COMPONENTS
<PreferenceScreen android:title="@string/revanced_preference_screen_miniplayer_title" android:key="revanced_preference_screen_miniplayer" android:summary="@string/revanced_preference_screen_miniplayer_summary">SETTINGS: MINIPLAYER_COMPONENTS --> <PreferenceScreen android:title="@string/revanced_preference_screen_miniplayer_title" android:key="revanced_preference_screen_miniplayer" android:summary="@string/revanced_preference_screen_miniplayer_summary">SETTINGS: MINIPLAYER_COMPONENTS -->
<!-- SETTINGS: DISABLE_RESUMING_MINIPLAYER
<app.revanced.extension.shared.settings.preference.HtmlSwitchPreference android:title="@string/revanced_disable_resuming_miniplayer_title" android:key="revanced_disable_resuming_miniplayer" android:summaryOn="@string/revanced_disable_resuming_miniplayer_summary_on" android:summaryOff="@string/revanced_disable_resuming_miniplayer_summary_off" />DISABLE_RESUMING_MINIPLAYER -->
<!-- SETTINGS: MINIPLAYER_TYPE_19_14 <!-- SETTINGS: MINIPLAYER_TYPE_19_14
<ListPreference android:entries="@array/revanced_miniplayer_type_19_14_entries" android:title="@string/revanced_miniplayer_type_title" android:key="revanced_miniplayer_type" android:entryValues="@array/revanced_miniplayer_type_19_14_entry_values" />SETTINGS: MINIPLAYER_TYPE_19_14 --> <ListPreference android:entries="@array/revanced_miniplayer_type_19_14_entries" android:title="@string/revanced_miniplayer_type_title" android:key="revanced_miniplayer_type" android:entryValues="@array/revanced_miniplayer_type_19_14_entry_values" />SETTINGS: MINIPLAYER_TYPE_19_14 -->
@ -923,6 +926,7 @@
<Preference android:title="Change player flyout menu toggles" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="Change player flyout menu toggles" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Description components" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="Description components" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Disable haptic feedback" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="Disable haptic feedback" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Disable resuming Miniplayer on startup" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Fullscreen components" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="Fullscreen components" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Hide action buttons" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="Hide action buttons" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Hide comments components" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="Hide comments components" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>