From 4d29ce5792d0fbbd8788b30ee6252c7adfb8969d Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 24 Nov 2022 23:14:02 +0100 Subject: [PATCH] refactor(youtube/hide-cast-button): quality of life changes --- .../castbutton/patch/HideCastButtonPatch.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/HideCastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/HideCastButtonPatch.kt index c37d2c5a8..b511660f6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/HideCastButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/castbutton/patch/HideCastButtonPatch.kt @@ -7,6 +7,7 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch @@ -34,19 +35,20 @@ class HideCastButtonPatch : BytecodePatch() { ) ) - context.classes.forEach { classDef -> - classDef.methods.forEach { method -> - if (classDef.type.endsWith("MediaRouteButton;") && method.name == "setVisibility") { - val setVisibilityMethod = - context.proxy(classDef).mutableClass.methods.first { it.name == "setVisibility" } - - setVisibilityMethod.addInstructions( - 0, """ + with( + context.findClass("MediaRouteButton") + ?: return PatchResultError("MediaRouteButton class not found.") + ) { + with( + mutableClass.methods.find { it.name == "setVisibility" } + ?: return PatchResultError("setVisibility method not found.") + ) { + addInstructions( + 0, """ invoke-static {p1}, Lapp/revanced/integrations/patches/HideCastButtonPatch;->getCastButtonOverrideV2(I)I move-result p1 """ - ) - } + ) } }