feat(youtube/hide-player-overlay): make it toggleable in settings (#2044)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
johnconner122 2023-05-08 04:57:44 +05:00 committed by GitHub
parent 3ec25bb543
commit f693d55caf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 126 additions and 51 deletions

View File

@ -12,16 +12,12 @@ import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.youtube.layout.buttons.player.background.annotations.PlayerButtonBackgroundCompatibility
import org.w3c.dom.Element
@Patch
@Patch(false)
@Name("remove-player-button-background")
@Description("Removes the background from the video player buttons.")
@PlayerButtonBackgroundCompatibility
@Version("0.0.1")
class PlayerButtonBackgroundPatch : ResourcePatch {
private companion object {
const val RESOURCE_FILE_PATH = "res/drawable/player_button_circle_background.xml"
}
override fun execute(context: ResourceContext): PatchResult {
context.xmlEditor[RESOURCE_FILE_PATH].use { editor ->
editor.file.doRecursively node@{ node ->
@ -35,4 +31,8 @@ class PlayerButtonBackgroundPatch : ResourcePatch {
return PatchResultSuccess()
}
private companion object {
const val RESOURCE_FILE_PATH = "res/drawable/player_button_circle_background.xml"
}
}

View File

@ -0,0 +1,28 @@
package app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch.HidePlayerOverlayResourcePatch
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
object CreatePlayerOverviewFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PRIVATE or AccessFlags.FINAL,
opcodes = listOf(
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CHECK_CAST
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
if (it.opcode != Opcode.INVOKE_VIRTUAL) return@any false
val literal = (it as WideLiteralInstruction).wideLiteral
literal == HidePlayerOverlayResourcePatch.scrimOverlayId
} ?: false
}
)

View File

@ -0,0 +1,53 @@
package app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.youtube.layout.hide.player.overlay.annotations.HidePlayerOverlayPatchCompatibility
import app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.fingerprints.CreatePlayerOverviewFingerprint
import app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch.HidePlayerOverlayResourcePatch
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
@Patch
@Name("hide-player-overlay")
@Description("Hides the dark background overlay from the player when player controls are visible.")
@DependsOn([HidePlayerOverlayResourcePatch::class])
@HidePlayerOverlayPatchCompatibility
@Version("0.0.2")
class HidePlayerOverlayPatch : BytecodePatch(listOf(CreatePlayerOverviewFingerprint)) {
override fun execute(context: BytecodeContext): PatchResult {
CreatePlayerOverviewFingerprint.result?.let { result ->
result.mutableMethod.apply {
val viewRegisterIndex = implementation!!.instructions.indexOfFirst {
val literal = (it as? WideLiteralInstruction)?.wideLiteral
literal == HidePlayerOverlayResourcePatch.scrimOverlayId
} + 3
val viewRegister = instruction<OneRegisterInstruction>(viewRegisterIndex).registerA
val insertIndex = viewRegisterIndex + 1
addInstruction(
insertIndex,
"invoke-static { v$viewRegister }, " +
"$INTEGRATIONS_CLASS_DESCRIPTOR->hidePlayerOverlay(Landroid/widget/ImageView;)V"
)
}
} ?: return CreatePlayerOverviewFingerprint.toErrorResult()
return PatchResultSuccess()
}
private companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/HidePlayerOverlayPatch;"
}
}

View File

@ -1,46 +0,0 @@
package app.revanced.patches.youtube.layout.hide.player.overlay.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.youtube.layout.hide.player.overlay.annotations.HidePlayerOverlayPatchCompatibility
@Patch(false)
@Name("hide-player-overlay")
@Description("Hides the dark player overlay when player controls are visible.")
@HidePlayerOverlayPatchCompatibility
@Version("0.0.1")
class HidePlayerOverlayPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
val attributes = arrayOf("height", "width")
context.xmlEditor[RESOURCE_FILE_PATH].use { editor ->
editor.file.getElementsByTagName("FrameLayout").item(0).childNodes.apply {
for (i in 1 until length) {
val view = item(i)
if (
view.attributes.getNamedItem("android:id")
?.nodeValue
?.endsWith("scrim_overlay") == true
) {
attributes.forEach {
view.attributes.getNamedItem("android:layout_$it").nodeValue = "0.0dip"
}
break
}
}
}
}
return PatchResultSuccess()
}
private companion object {
const val RESOURCE_FILE_PATH = "res/layout/youtube_controls_overlay.xml"
}
}

View File

@ -0,0 +1,40 @@
package app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
import app.revanced.patches.youtube.layout.hide.player.overlay.annotations.HidePlayerOverlayPatchCompatibility
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import jdk.jfr.Name
@Name("hide-player-overlay-resource-patch")
@DependsOn([SettingsPatch::class, ResourceMappingPatch::class])
@HidePlayerOverlayPatchCompatibility
class HidePlayerOverlayResourcePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SwitchPreference(
"revanced_hide_player_overlay",
StringResource("revanced_hide_player_overlay_title", "Hide background overlay in player"),
false,
StringResource("revanced_hide_player_overlay_summary_on", "Background overlay is hidden"),
StringResource("revanced_hide_player_overlay_summary_off", "Background overlay is shown")
)
)
scrimOverlayId = ResourceMappingPatch.resourceMappings.single {
it.type == "id" && it.name == "scrim_overlay"
}.id
return PatchResultSuccess()
}
internal companion object {
var scrimOverlayId: Long = -1
}
}