add custom-branding-music-name patch

This commit is contained in:
inotia00
2023-05-03 19:43:29 +09:00
parent 59d465a8ef
commit 2485f3e1ea
2 changed files with 78 additions and 1 deletions

View File

@ -0,0 +1,53 @@
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
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 app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
import app.revanced.patches.shared.patch.options.PatchOptions
import org.w3c.dom.Element
@Patch(false)
@Name("custom-branding-music-name")
@DependsOn([PatchOptions::class])
@Description("Changes the Music launcher name to your choice (defaults to RVX Music, ReVanced Extended Music).")
@YouTubeMusicCompatibility
@Version("0.0.1")
class CustomBrandingMusicNamePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
// App name
val resourceFileNames = arrayOf("strings.xml")
val fullName = PatchOptions.MusicAppNameFull
val shortName = PatchOptions.MusicAppNameShort
context.forEach {
if (!it.name.startsWithAny(*resourceFileNames)) return@forEach
context.xmlEditor[it.absolutePath].use { editor ->
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
for (i in 0 until resourcesNode.childNodes.length) {
val node = resourcesNode.childNodes.item(i)
if (node !is Element) continue
val element = resourcesNode.childNodes.item(i) as Element
element.textContent = when (element.getAttribute("name")) {
"app_name" -> "$fullName"
"app_launcher_name" -> "$shortName"
else -> continue
}
}
}
}
return PatchResultSuccess()
}
}

View File

@ -25,7 +25,7 @@ class PatchOptions : ResourcePatch {
companion object : OptionsContainer() {
/**
* Custom Branding Name
* Custom Branding Name (YouTube)
*/
internal var YouTubeAppName: String? by option(
PatchOption.StringOption(
@ -48,6 +48,30 @@ class PatchOptions : ResourcePatch {
)
)
/**
* Custom Branding Full Name (YouTube Music)
*/
internal var MusicAppNameFull: String? by option(
PatchOption.StringOption(
key = "MusicAppNameFull",
default = "ReVanced Extended Music",
title = "Application Name of YouTube Music",
description = "The name of the YouTube Music it will show on your notification panel."
)
)
/**
* Custom Branding Short Name (YouTube Music)
*/
internal var MusicAppNameShort: String? by option(
PatchOption.StringOption(
key = "MusicAppNameShort",
default = "RVX Music",
title = "Application Name of YouTube Music",
description = "The name of the YouTube Music it will show on your home screen."
)
)
/**
* Custom Package Name (YouTube Music)
*/