fix(music/custom-branding-music-name): compile error in RVX Manager

This commit is contained in:
inotia00
2023-07-23 21:42:38 +09:00
parent ba53f73739
commit e0e6dadfe6
2 changed files with 152 additions and 24 deletions

View File

@ -1,6 +1,5 @@
package app.revanced.patches.music.layout.branding.name.patch
import app.revanced.extensions.startsWithAny
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
@ -14,14 +13,14 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.fix.decoding.patch.DecodingPatch
import org.w3c.dom.Element
@Patch(false)
@Patch
@Name("Custom branding Music name")
@Description("Rename the YouTube Music app to the name specified in options.json.")
@DependsOn(
[
DecodingPatch::class
DecodingPatch::class,
RemoveElementsPatch::class
]
)
@MusicCompatibility
@ -29,28 +28,31 @@ import org.w3c.dom.Element
class CustomBrandingNamePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
// App name
val resourceFileNames = arrayOf("strings.xml")
val longName = MusicLongName
val shortName = MusicShortName
val longName =
if (MusicLongName != null)
MusicLongName
else
"ReVanced Extended Music"
context.forEach {
if (!it.name.startsWithAny(*resourceFileNames)) return@forEach
val shortName =
if (MusicShortName != null)
MusicShortName
else
"RVX Music"
context.xmlEditor[it.absolutePath].use { editor ->
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
context.xmlEditor["res/values/strings.xml"].use { editor ->
val document = editor.file
for (i in 0 until resourcesNode.childNodes.length) {
val node = resourcesNode.childNodes.item(i)
if (node !is Element) continue
mapOf(
"app_name" to longName,
"app_launcher_name" to shortName
).forEach { (k, v) ->
val stringElement = document.createElement("string")
val element = resourcesNode.childNodes.item(i) as Element
element.textContent = when (element.getAttribute("name")) {
"app_name" -> "$longName"
"app_launcher_name" -> "$shortName"
else -> continue
}
}
stringElement.setAttribute("name", k)
stringElement.textContent = v
document.getElementsByTagName("resources").item(0).appendChild(stringElement)
}
}
@ -61,7 +63,7 @@ class CustomBrandingNamePatch : ResourcePatch {
var MusicLongName: String? by option(
PatchOption.StringOption(
key = "MusicLongName",
default = "ReVanced Music Extended",
default = "ReVanced Extended Music",
title = "Application Name of YouTube Music",
description = "The name of the YouTube Music it will show on your notification panel."
)
@ -69,7 +71,7 @@ class CustomBrandingNamePatch : ResourcePatch {
var MusicShortName: String? by option(
PatchOption.StringOption(
key = "MusicShortName",
default = "YTM Extended",
default = "RVX Music",
title = "Application Name of YouTube Music",
description = "The name of the YouTube Music it will show on your home screen."
)

View File

@ -0,0 +1,126 @@
package app.revanced.patches.music.layout.branding.name.patch
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import kotlin.io.path.exists
class RemoveElementsPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
LANGUAGE_LIST.forEach { path ->
val resDirectory = context["res"]
val targetXmlPath = resDirectory.resolve(path).resolve("strings.xml").toPath()
if (targetXmlPath.exists()) {
val targetXml = context["res/$path/strings.xml"]
targetXml.writeText(
targetXml.readText()
.replace(""".+"app_launcher_name".+""".toRegex(), "")
.replace(""".+"app_name".+""".toRegex(), "")
)
}
}
return PatchResultSuccess()
}
companion object {
val LANGUAGE_LIST = arrayOf(
"values",
"values-af",
"values-am",
"values-ar",
"values-ar-rXB",
"values-as",
"values-az",
"values-b+es+419",
"values-b+sr+Latn",
"values-be",
"values-bg",
"values-bn",
"values-bs",
"values-ca",
"values-cs",
"values-da",
"values-de",
"values-el",
"values-en-rAU",
"values-en-rCA",
"values-en-rGB",
"values-en-rIN",
"values-en-rXA",
"values-en-rXC",
"values-es",
"values-es-rUS",
"values-et",
"values-eu",
"values-fa",
"values-fi",
"values-fr",
"values-fr-rCA",
"values-gl",
"values-gu",
"values-hi",
"values-hr",
"values-hu",
"values-hy",
"values-id",
"values-in",
"values-is",
"values-it",
"values-iw",
"values-ja",
"values-ka",
"values-kk",
"values-km",
"values-kn",
"values-ko",
"values-ky",
"values-lo",
"values-lt",
"values-lv",
"values-mk",
"values-ml",
"values-mn",
"values-mr",
"values-ms",
"values-my",
"values-nb",
"values-ne",
"values-nl",
"values-no",
"values-or",
"values-pa",
"values-pl",
"values-pt",
"values-pt-rBR",
"values-pt-rPT",
"values-ro",
"values-ru",
"values-si",
"values-sk",
"values-sl",
"values-sq",
"values-sr",
"values-sv",
"values-sw",
"values-ta",
"values-te",
"values-th",
"values-tl",
"values-tr",
"values-uk",
"values-ur",
"values-uz",
"values-vi",
"values-zh",
"values-zh-rCN",
"values-zh-rHK",
"values-zh-rTW",
"values-zu"
)
}
}