Skip to content

Commit

Permalink
feat(YouTube): Add Disable resuming Miniplayer on startup patch
Browse files Browse the repository at this point in the history
  • Loading branch information
anddea committed Feb 11, 2025
1 parent 3356691 commit 69b67a0
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ private static void setMiniPlayerSize() {
private static final int MODERN_OVERLAY_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();

/**
Expand Down Expand Up @@ -219,6 +222,13 @@ public boolean isAvailable() {
}
}

/**
* Injection point.
*/
public static boolean disableResumingStartupMiniPlayer(boolean original) {
return !DISABLE_RESUMING_MINIPLAYER && original;
}

/**
* Injection point.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting DISABLE_HAPTIC_FEEDBACK_ZOOM = new BooleanSetting("revanced_disable_haptic_feedback_zoom", FALSE);

// 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);
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@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.miniplayerMaxSize
Expand Down
Original file line number Diff line number Diff line change
@@ -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.addInstructions
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
)
Original file line number Diff line number Diff line change
@@ -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
)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ internal enum class PatchList(
"Disable haptic feedback",
"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",
"Adds an option to disable the Shorts player from resuming on app startup when Shorts were last being watched."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@
<!-- 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
<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 -->

Expand Down Expand Up @@ -933,6 +936,7 @@
<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="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="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"/>
Expand Down

0 comments on commit 69b67a0

Please sign in to comment.