chore: Lint code

This commit is contained in:
inotia00 2024-12-21 14:55:46 +09:00
parent dc0a5973ad
commit a353a48aa3
22 changed files with 88 additions and 47 deletions

View File

@ -179,7 +179,8 @@ val sponsorBlockPatch = resourcePatch(
val tags = document.getElementsByTagName(PREFERENCE_SCREEN_TAG_NAME)
List(tags.length) { tags.item(it) as Element }
.filter {
it.getAttribute("android:key").contains("revanced_preference_screen_$category")
it.getAttribute("android:key")
.contains("revanced_preference_screen_$category")
}
.forEach {
it.adoptChild(SWITCH_PREFERENCE_TAG_NAME) {
@ -210,7 +211,8 @@ val sponsorBlockPatch = resourcePatch(
val tags = document.getElementsByTagName(PREFERENCE_SCREEN_TAG_NAME)
List(tags.length) { tags.item(it) as Element }
.filter {
it.getAttribute("android:key").contains("revanced_preference_screen_$category")
it.getAttribute("android:key")
.contains("revanced_preference_screen_$category")
}
.forEach {
it.adoptChild("Preference") {

View File

@ -114,7 +114,8 @@ val adsPatch = bytecodePatch(
// AdElementConverter is conveniently responsible for inserting all feed ads.
// By removing the appending instruction no ad posts gets appended to the feed.
newAdPostFingerprint.methodOrThrow().apply {
val stringIndex = indexOfFirstStringInstructionOrThrow("android_feed_freeform_render_variant")
val stringIndex =
indexOfFirstStringInstructionOrThrow("android_feed_freeform_render_variant")
val targetIndex = indexOfFirstInstructionOrThrow(stringIndex) {
opcode == Opcode.INVOKE_VIRTUAL
&& getReference<MethodReference>()?.toString() == "Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z"

View File

@ -24,7 +24,9 @@ val recommendedCommunitiesPatch = bytecodePatch(
dependsOn(settingsPatch)
execute {
communityRecommendationSectionFingerprint.methodOrThrow(communityRecommendationSectionParentFingerprint).apply {
communityRecommendationSectionFingerprint.methodOrThrow(
communityRecommendationSectionParentFingerprint
).apply {
addInstructionsWithLabels(
0,
"""

View File

@ -42,14 +42,16 @@ val navigationButtonsPatch = bytecodePatch(
val bottomNavScreenMutableClass = with(bottomNavScreenFingerprint.methodOrThrow()) {
val startIndex = indexOfGetDimensionPixelSizeInstruction(this)
val targetIndex = indexOfFirstInstructionOrThrow(startIndex, Opcode.NEW_INSTANCE)
val targetReference = getInstruction<ReferenceInstruction>(targetIndex).reference.toString()
val targetReference =
getInstruction<ReferenceInstruction>(targetIndex).reference.toString()
classBy { it.type == targetReference }
?.mutableClass
?: throw ClassNotFoundException("Failed to find class $targetReference")
}
bottomNavScreenOnGlobalLayoutFingerprint.second.matchOrNull(bottomNavScreenMutableClass)?.let {
bottomNavScreenOnGlobalLayoutFingerprint.second.matchOrNull(bottomNavScreenMutableClass)
?.let {
it.method.apply {
val startIndex = it.patternMatch!!.startIndex
val targetRegister =

View File

@ -31,7 +31,8 @@ val recentlyVisitedShelfPatch = bytecodePatch(
execute {
val recentlyVisitedReference = with (communityDrawerPresenterConstructorFingerprint.methodOrThrow()) {
val recentlyVisitedReference =
with(communityDrawerPresenterConstructorFingerprint.methodOrThrow()) {
val recentlyVisitedFieldIndex = indexOfHeaderItemInstruction(this)
val recentlyVisitedObjectIndex =
indexOfFirstInstructionOrThrow(recentlyVisitedFieldIndex, Opcode.IPUT_OBJECT)
@ -39,7 +40,9 @@ val recentlyVisitedShelfPatch = bytecodePatch(
getInstruction<ReferenceInstruction>(recentlyVisitedObjectIndex).reference.toString()
}
communityDrawerPresenterFingerprint.methodOrThrow(communityDrawerPresenterConstructorFingerprint).apply {
communityDrawerPresenterFingerprint.methodOrThrow(
communityDrawerPresenterConstructorFingerprint
).apply {
val recentlyVisitedObjectIndex =
indexOfFirstInstructionOrThrow {
(this as? ReferenceInstruction)?.reference?.toString() == recentlyVisitedReference

View File

@ -19,7 +19,8 @@ internal val customReportsFingerprint = legacyFingerprint(
fun indexOfScreenNavigatorInstruction(method: Method) =
method.indexOfFirstInstruction {
(this as? ReferenceInstruction)?.reference?.toString()?.contains("Landroid/app/Activity;Landroid/net/Uri;") == true
(this as? ReferenceInstruction)?.reference?.toString()
?.contains("Landroid/app/Activity;Landroid/net/Uri;") == true
}
internal val screenNavigatorFingerprint = legacyFingerprint(

View File

@ -9,7 +9,6 @@ import app.revanced.patches.reddit.utils.extension.Constants.PATCHES_PATH
import app.revanced.patches.reddit.utils.patch.PatchList.OPEN_LINKS_EXTERNALLY
import app.revanced.patches.reddit.utils.settings.settingsPatch
import app.revanced.patches.reddit.utils.settings.updatePatchStatus
import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.indexOfFirstStringInstructionOrThrow
private const val EXTENSION_METHOD_DESCRIPTOR =

View File

@ -51,7 +51,9 @@ private val settingsBytecodePatch = bytecodePatch(
&& (this as? BuilderInstruction21c)?.reference.toString().startsWith("202")
}
val versionNumber = getInstruction<BuilderInstruction21c>(versionIndex).reference.toString().replace(".", "").toInt()
val versionNumber =
getInstruction<BuilderInstruction21c>(versionIndex).reference.toString()
.replace(".", "").toInt()
is_2024_18_or_greater = 2024180 <= versionNumber
}

View File

@ -80,8 +80,10 @@ val shortsActionButtonsPatch = resourcePatch(
val fromPath = res.resolve(fromFile).toPath()
val toFile = "$drawableDirectory/$toFileName.webp"
val toPath = res.resolve(toFile).toPath()
val inputStreamForLegacy = inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)
val inputStreamForNew = inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)
val inputStreamForLegacy =
inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)
val inputStreamForNew =
inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)
Files.copy(inputStreamForLegacy, fromPath, StandardCopyOption.REPLACE_EXISTING)

View File

@ -178,7 +178,8 @@ val customBrandingIconPatch = resourcePatch(
}
document("res/values/styles.xml").use { document ->
val resourcesNode = document.getElementsByTagName("resources").item(0) as Element
val resourcesNode =
document.getElementsByTagName("resources").item(0) as Element
val childNodes = resourcesNode.childNodes
for (i in 0 until childNodes.length) {
@ -205,7 +206,8 @@ val customBrandingIconPatch = resourcePatch(
}
val styleMap = mutableMapOf<String, String>()
styleMap["Base.Theme.YouTube.Launcher"] = "@style/Theme.AppCompat.DayNight.NoActionBar"
styleMap["Base.Theme.YouTube.Launcher"] =
"@style/Theme.AppCompat.DayNight.NoActionBar"
if (is_19_32_or_greater) {
styleMap["Theme.YouTube.Home"] = "@style/Base.V27.Theme.YouTube.Home"
@ -213,7 +215,8 @@ val customBrandingIconPatch = resourcePatch(
styleMap.forEach { (nodeAttributeName, nodeAttributeParent) ->
document("res/values-v31/styles.xml").use { document ->
val resourcesNode = document.getElementsByTagName("resources").item(0) as Element
val resourcesNode =
document.getElementsByTagName("resources").item(0) as Element
val style = document.createElement("style")
style.setAttribute("name", nodeAttributeName)
@ -223,7 +226,10 @@ val customBrandingIconPatch = resourcePatch(
primaryItem.setAttribute("name", "android:windowSplashScreenAnimatedIcon")
primaryItem.textContent = "@drawable/avd_anim"
val secondaryItem = document.createElement("item")
secondaryItem.setAttribute("name", "android:windowSplashScreenAnimationDuration")
secondaryItem.setAttribute(
"name",
"android:windowSplashScreenAnimationDuration"
)
secondaryItem.textContent = if (appIcon.startsWith("revancify"))
"1500"
else

View File

@ -67,6 +67,7 @@ val sharedThemePatch = resourcePatch(
1 -> when (nodeAttributeName) {
"Base.Theme.YouTube.Launcher",
"Base.Theme.YouTube.Launcher.Cairo" -> SPLASH_SCREEN_COLOR_ATTRIBUTE
else -> "null"
}
@ -115,7 +116,8 @@ val sharedThemePatch = resourcePatch(
return@editSplashScreen
}
document("res/$drawable/$fileName.xml").use { document ->
val layerList = document.getElementsByTagName("layer-list").item(0) as Element
val layerList =
document.getElementsByTagName("layer-list").item(0) as Element
val childNodes = layerList.childNodes
for (i in 0 until childNodes.length) {

View File

@ -169,7 +169,8 @@ val playerButtonsPatch = bytecodePatch(
if (is_19_34_or_greater) {
layoutConstructorFingerprint.methodOrThrow().apply {
val resourceIndex = indexOfFirstLiteralInstructionOrThrow(playerControlPreviousButtonTouchArea)
val resourceIndex =
indexOfFirstLiteralInstructionOrThrow(playerControlPreviousButtonTouchArea)
val insertIndex = indexOfFirstInstructionOrThrow(resourceIndex) {
opcode == Opcode.INVOKE_STATIC &&

View File

@ -16,8 +16,8 @@ import app.revanced.patches.youtube.utils.playertype.playerTypeHookPatch
import app.revanced.patches.youtube.utils.playservice.is_18_49_or_greater
import app.revanced.patches.youtube.utils.playservice.is_19_02_or_greater
import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
import app.revanced.patches.youtube.utils.recyclerview.recyclerViewTreeObserverPatch
import app.revanced.patches.youtube.utils.recyclerview.recyclerViewTreeObserverHook
import app.revanced.patches.youtube.utils.recyclerview.recyclerViewTreeObserverPatch
import app.revanced.patches.youtube.utils.resourceid.sharedResourceIdPatch
import app.revanced.patches.youtube.utils.rollingNumberTextViewAnimationUpdateFingerprint
import app.revanced.patches.youtube.utils.rollingNumberTextViewFingerprint

View File

@ -37,8 +37,8 @@ import app.revanced.patches.youtube.utils.playservice.is_19_25_or_greater
import app.revanced.patches.youtube.utils.playservice.is_19_28_or_greater
import app.revanced.patches.youtube.utils.playservice.is_19_34_or_greater
import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
import app.revanced.patches.youtube.utils.recyclerview.recyclerViewTreeObserverPatch
import app.revanced.patches.youtube.utils.recyclerview.recyclerViewTreeObserverHook
import app.revanced.patches.youtube.utils.recyclerview.recyclerViewTreeObserverPatch
import app.revanced.patches.youtube.utils.resourceid.bottomBarContainer
import app.revanced.patches.youtube.utils.resourceid.metaPanel
import app.revanced.patches.youtube.utils.resourceid.reelDynRemix

View File

@ -165,10 +165,22 @@ val swipeControlsPatch = bytecodePatch(
reference.parameterTypes.size == 0
}
if (getInstruction(targetIndex - 1).opcode != Opcode.IGET_OBJECT) {
throw PatchException("Previous Opcode pattern does not match: ${getInstruction(targetIndex - 1).opcode}")
throw PatchException(
"Previous Opcode pattern does not match: ${
getInstruction(
targetIndex - 1
).opcode
}"
)
}
if (getInstruction(targetIndex + 1).opcode != Opcode.IF_EQZ) {
throw PatchException("Next Opcode pattern does not match: ${getInstruction(targetIndex + 1).opcode}")
throw PatchException(
"Next Opcode pattern does not match: ${
getInstruction(
targetIndex + 1
).opcode
}"
)
}
val fieldReference = getInstruction<ReferenceInstruction>(targetIndex - 1).reference
val fieldInstruction = getInstruction<TwoRegisterInstruction>(targetIndex - 1)

View File

@ -67,7 +67,12 @@ internal val layoutConstructorFingerprint = legacyFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = emptyList(),
strings = listOf("1.0x"),
literals = listOf(autoNavToggle, autoNavPreviewStub, playerControlPreviousButtonTouchArea, playerControlNextButtonTouchArea),
literals = listOf(
autoNavToggle,
autoNavPreviewStub,
playerControlPreviousButtonTouchArea,
playerControlNextButtonTouchArea
),
)
internal val playbackRateBottomSheetBuilderFingerprint = legacyFingerprint(

View File

@ -5,7 +5,6 @@ import app.revanced.patches.youtube.misc.backgroundplayback.backgroundPlaybackPa
import app.revanced.patches.youtube.utils.playservice.is_19_04_or_greater
import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
import app.revanced.util.fingerprint.injectLiteralInstructionBooleanCall
import app.revanced.util.fingerprint.resolvable
val cairoSettingsPatch = bytecodePatch(
description = "cairoSettingsPatch"

View File

@ -45,7 +45,8 @@ val playbackSpeedWhilePlayingPatch = bytecodePatch(
playbackSpeedInFeedsFingerprint.methodOrThrow().apply {
val freeRegister = implementation!!.registerCount - parameters.size - 2
val playbackSpeedIndex = indexOfGetPlaybackSpeedInstruction(this)
val playbackSpeedRegister = getInstruction<TwoRegisterInstruction>(playbackSpeedIndex).registerA
val playbackSpeedRegister =
getInstruction<TwoRegisterInstruction>(playbackSpeedIndex).registerA
val jumpIndex = indexOfFirstInstructionOrThrow(playbackSpeedIndex, Opcode.RETURN_VOID)
addInstructionsWithLabels(

View File

@ -19,8 +19,8 @@ import app.revanced.patches.youtube.utils.flyoutmenu.flyoutMenuHookPatch
import app.revanced.patches.youtube.utils.patch.PatchList.VIDEO_PLAYBACK
import app.revanced.patches.youtube.utils.playertype.playerTypeHookPatch
import app.revanced.patches.youtube.utils.qualityMenuViewInflateFingerprint
import app.revanced.patches.youtube.utils.recyclerview.recyclerViewTreeObserverPatch
import app.revanced.patches.youtube.utils.recyclerview.recyclerViewTreeObserverHook
import app.revanced.patches.youtube.utils.recyclerview.recyclerViewTreeObserverPatch
import app.revanced.patches.youtube.utils.resourceid.sharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
import app.revanced.patches.youtube.utils.settings.settingsPatch

View File

@ -123,7 +123,8 @@ fun ResourcePatchContext.copyAdaptiveIcon(
}
if (adaptiveIconMonoChromeFileName != null &&
adaptiveIconMonoChromeFileName != getAdaptiveIconMonoChromeResourceFile()) {
adaptiveIconMonoChromeFileName != getAdaptiveIconMonoChromeResourceFile()
) {
val drawableDirectory = get("res").resolve("drawable")
Files.copy(
drawableDirectory