From 838f1834a5df547ce2c3217b874c0594b6878a67 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sat, 28 Sep 2024 17:02:42 -0400 Subject: [PATCH] feat(YouTube - Hide Shorts components): Add patch option to hide Shorts from app launcher widget Beta (#3707) --- .../hide/shorts/HideShortsComponentsPatch.kt | 9 +++++++- .../HideShortsComponentsResourcePatch.kt | 22 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt index b87662d86a..e1ba723910 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt @@ -81,7 +81,14 @@ object HideShortsComponentsPatch : BytecodePatch( key = "hideShortsAppShortcut", default = false, title = "Hide Shorts app shortcut", - description = "Permanently hides the shortcut to open Shorts from long pressing the app icon in your launcher." + description = "Permanently hides the shortcut to open Shorts when long pressing the app icon in your launcher." + ) + + internal val hideShortsWidget by booleanPatchOption( + key = "hideShortsWidget", + default = false, + title = "Hide Shorts widget", + description = "Permanently hides the launcher widget Shorts button." ) override fun execute(context: BytecodeContext) { diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsResourcePatch.kt index 714fa62d2e..a3c58a30b1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsResourcePatch.kt @@ -7,6 +7,7 @@ import app.revanced.patches.all.misc.resources.AddResourcesPatch import app.revanced.patches.shared.misc.mapping.ResourceMappingPatch import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.youtube.layout.hide.shorts.HideShortsComponentsPatch.hideShortsAppShortcut +import app.revanced.patches.youtube.layout.hide.shorts.HideShortsComponentsPatch.hideShortsWidget import app.revanced.patches.youtube.misc.settings.SettingsPatch import app.revanced.util.findElementByAttributeValueOrThrow import org.w3c.dom.Element @@ -57,12 +58,21 @@ object HideShortsComponentsResourcePatch : ResourcePatch() { if (hideShortsAppShortcut == true) { context.xmlEditor["res/xml/main_shortcuts.xml"].use { editor -> - val shortcuts = editor.file.getElementsByTagName("shortcuts").item(0) as Element - val shortsItem = - shortcuts.getElementsByTagName("shortcut").findElementByAttributeValueOrThrow( - "android:shortcutId", - "shorts-shortcut" - ) + val shortsItem = editor.file.childNodes.findElementByAttributeValueOrThrow( + "android:shortcutId", + "shorts-shortcut" + ) + + shortsItem.parentNode.removeChild(shortsItem) + } + } + + if (hideShortsWidget == true) { + context.xmlEditor["res/layout/appwidget_two_rows.xml"].use { editor -> + val shortsItem = editor.file.childNodes.findElementByAttributeValueOrThrow( + "android:id", + "@id/button_shorts_container" + ) shortsItem.parentNode.removeChild(shortsItem) }