-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube & YouTube Music - Hide settings menu): Add switch prefer…
…ences for each setting entry
- Loading branch information
Showing
14 changed files
with
266 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...tlin/app/revanced/patches/music/ads/general/fingerprints/MembershipSettingsFingerprint.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...pp/revanced/patches/music/ads/general/fingerprints/MembershipSettingsParentFingerprint.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...n/app/revanced/patches/music/general/components/fingerprints/ParentToolMenuFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package app.revanced.patches.music.general.components.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
internal object ParentToolMenuFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
opcodes = listOf( | ||
Opcode.CONST_4, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.IGET, | ||
), | ||
strings = listOf("pref_key_parent_tools"), | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.name == "onSettingsLoaded" | ||
} | ||
) |
11 changes: 11 additions & 0 deletions
11
...app/revanced/patches/music/general/components/fingerprints/PreferenceScreenFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package app.revanced.patches.music.general.components.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
internal object PreferenceScreenFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.definingClass == "Lcom/google/android/apps/youtube/music/settings/fragment/SettingsHeadersFragment;" && | ||
methodDef.name == "onCreatePreferences" | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 24 additions & 23 deletions
47
src/main/kotlin/app/revanced/patches/shared/settingmenu/SettingsMenuPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
package app.revanced.patches.shared.settingmenu | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH | ||
import app.revanced.patches.shared.settingmenu.fingerprints.SettingsMenuFingerprint | ||
import app.revanced.patches.shared.viewgroup.ViewGroupMarginLayoutParamsHookPatch | ||
import app.revanced.util.getReference | ||
import app.revanced.util.indexOfFirstInstructionOrThrow | ||
import app.revanced.util.resultOrThrow | ||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction | ||
import com.android.tools.smali.dexlib2.iface.reference.FieldReference | ||
import app.revanced.patches.shared.settingmenu.fingerprints.FindPreferenceFingerprint | ||
import app.revanced.patches.shared.settingmenu.fingerprints.RemovePreferenceFingerprint | ||
import app.revanced.util.findMethodOrThrow | ||
import app.revanced.util.getMethodCall | ||
|
||
@Patch( | ||
description = "Hide the settings menu for YouTube or YouTube Music.", | ||
dependencies = [ViewGroupMarginLayoutParamsHookPatch::class] | ||
) | ||
object SettingsMenuPatch : BytecodePatch( | ||
setOf(SettingsMenuFingerprint) | ||
setOf( | ||
FindPreferenceFingerprint, | ||
RemovePreferenceFingerprint | ||
) | ||
) { | ||
private const val INTEGRATIONS_CLASS_DESCRIPTOR = | ||
"$PATCHES_PATH/SettingsMenuPatch;" | ||
"$PATCHES_PATH/BaseSettingsMenuPatch;" | ||
|
||
override fun execute(context: BytecodeContext) { | ||
|
||
SettingsMenuFingerprint.resultOrThrow().mutableMethod.apply { | ||
val insertIndex = indexOfFirstInstructionOrThrow { | ||
getReference<FieldReference>()?.type == "Landroid/support/v7/widget/RecyclerView;" | ||
} | ||
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA | ||
val findPreferenceMethodCall = FindPreferenceFingerprint.getMethodCall() | ||
val removePreferenceMethodCall = RemovePreferenceFingerprint.getMethodCall() | ||
|
||
addInstruction( | ||
insertIndex, | ||
"invoke-static {v$insertRegister}, " + | ||
"$INTEGRATIONS_CLASS_DESCRIPTOR->hideSettingsMenu(Landroid/support/v7/widget/RecyclerView;)V" | ||
) | ||
} | ||
context.findMethodOrThrow(INTEGRATIONS_CLASS_DESCRIPTOR) { | ||
name == "removePreference" | ||
}.addInstructionsWithLabels( | ||
0, """ | ||
invoke-virtual {p0, p1}, $findPreferenceMethodCall | ||
move-result-object v0 | ||
if-eqz v0, :ignore | ||
invoke-virtual {p0, v0}, $removePreferenceMethodCall | ||
:ignore | ||
return-void | ||
""" | ||
) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
.../kotlin/app/revanced/patches/shared/settingmenu/fingerprints/FindPreferenceFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package app.revanced.patches.shared.settingmenu.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
|
||
internal object FindPreferenceFingerprint : MethodFingerprint( | ||
returnType = "Landroidx/preference/Preference;", | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
parameters = listOf("Ljava/lang/CharSequence;"), | ||
strings = listOf("Key cannot be null"), | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.definingClass == "Landroidx/preference/PreferenceGroup;" | ||
} | ||
) |
19 changes: 19 additions & 0 deletions
19
...otlin/app/revanced/patches/shared/settingmenu/fingerprints/RemovePreferenceFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app.revanced.patches.shared.settingmenu.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
internal object RemovePreferenceFingerprint : MethodFingerprint( | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
parameters = listOf("Landroidx/preference/Preference;"), | ||
opcodes = listOf(Opcode.INVOKE_VIRTUAL), | ||
customFingerprint = custom@{ methodDef, _ -> | ||
if (methodDef.definingClass != "Landroidx/preference/PreferenceGroup;") { | ||
return@custom false | ||
} | ||
val instructions = methodDef.implementation?.instructions ?: return@custom false | ||
instructions.elementAt(0).opcode == Opcode.INVOKE_DIRECT | ||
} | ||
) |
8 changes: 0 additions & 8 deletions
8
...in/kotlin/app/revanced/patches/shared/settingmenu/fingerprints/SettingsMenuFingerprint.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.