Skip to content

Commit 4c7b018

Browse files
author
LisoUseInAIKyrios
authored
feat(YouTube - Hide Shorts components): Add patch option to hide Shorts from app launcher widget Beta (#3707)
1 parent 5ddd957 commit 4c7b018

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ object HideShortsComponentsPatch : BytecodePatch(
8181
key = "hideShortsAppShortcut",
8282
default = false,
8383
title = "Hide Shorts app shortcut",
84-
description = "Permanently hides the shortcut to open Shorts from long pressing the app icon in your launcher."
84+
description = "Permanently hides the shortcut to open Shorts when long pressing the app icon in your launcher."
85+
)
86+
87+
internal val hideShortsWidget by booleanPatchOption(
88+
key = "hideShortsWidget",
89+
default = false,
90+
title = "Hide Shorts widget",
91+
description = "Permanently hides the launcher widget Shorts button."
8592
)
8693

8794
override fun execute(context: BytecodeContext) {

src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsResourcePatch.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import app.revanced.patches.all.misc.resources.AddResourcesPatch
77
import app.revanced.patches.shared.misc.mapping.ResourceMappingPatch
88
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
99
import app.revanced.patches.youtube.layout.hide.shorts.HideShortsComponentsPatch.hideShortsAppShortcut
10+
import app.revanced.patches.youtube.layout.hide.shorts.HideShortsComponentsPatch.hideShortsWidget
1011
import app.revanced.patches.youtube.misc.settings.SettingsPatch
1112
import app.revanced.util.findElementByAttributeValueOrThrow
1213
import org.w3c.dom.Element
@@ -57,12 +58,21 @@ object HideShortsComponentsResourcePatch : ResourcePatch() {
5758

5859
if (hideShortsAppShortcut == true) {
5960
context.xmlEditor["res/xml/main_shortcuts.xml"].use { editor ->
60-
val shortcuts = editor.file.getElementsByTagName("shortcuts").item(0) as Element
61-
val shortsItem =
62-
shortcuts.getElementsByTagName("shortcut").findElementByAttributeValueOrThrow(
63-
"android:shortcutId",
64-
"shorts-shortcut"
65-
)
61+
val shortsItem = editor.file.childNodes.findElementByAttributeValueOrThrow(
62+
"android:shortcutId",
63+
"shorts-shortcut"
64+
)
65+
66+
shortsItem.parentNode.removeChild(shortsItem)
67+
}
68+
}
69+
70+
if (hideShortsWidget == true) {
71+
context.xmlEditor["res/layout/appwidget_two_rows.xml"].use { editor ->
72+
val shortsItem = editor.file.childNodes.findElementByAttributeValueOrThrow(
73+
"android:id",
74+
"@id/button_shorts_container"
75+
)
6676

6777
shortsItem.parentNode.removeChild(shortsItem)
6878
}

0 commit comments

Comments
 (0)