Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(YouTube - Hide Shorts components): Add patch option to hide Shorts from app launcher widget #3707

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Loading