Skip to content

Commit

Permalink
feat(youtube/hide-player-overlay): make it toggleable in settings (#2044
Browse files Browse the repository at this point in the history
)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
johnconner122 and oSumAtrIX committed May 7, 2023
1 parent 3ec25bb commit f693d55
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -35,4 +31,8 @@ class PlayerButtonBackgroundPatch : ResourcePatch {

return PatchResultSuccess()
}

private companion object {
const val RESOURCE_FILE_PATH = "res/drawable/player_button_circle_background.xml"
}
}
Original file line number Diff line number Diff line change
@@ -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
}
)
Original file line number Diff line number Diff line change
@@ -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;"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit f693d55

Please sign in to comment.