@@ -9,9 +9,9 @@ import app.revanced.patcher.patch.stringOption
99import app.revanced.util.ResourceGroup
1010import app.revanced.util.Utils.trimIndentMultiline
1111import app.revanced.util.copyResources
12+ import app.revanced.util.findElementByAttributeValueOrThrow
1213import java.io.File
1314import java.nio.file.Files
14- import java.util.logging.Logger
1515
1616private const val REVANCED_ICON = " ReVanced*Logo" // Can never be a valid path.
1717
@@ -26,26 +26,6 @@ internal val mipmapDirectories = arrayOf(
2626
2727private fun formatResourceFileList (resourceNames : Array <String >) = resourceNames.joinToString(" \n " ) { " - $it " }
2828
29- /* *
30- * Attempts to fix unescaped and invalid characters not allowed for an Android app name.
31- */
32- private fun escapeAppName (name : String ): String? {
33- // Remove ASCII control characters.
34- val cleanedName = name.filter { it.code >= 32 }
35-
36- // Replace invalid XML characters with escaped equivalents.
37- val escapedName = cleanedName
38- .replace(" &" , " &" ) // Must be first to avoid double-escaping.
39- .replace(" <" , " <" )
40- .replace(" >" , " >" )
41- .replace(Regex (" (?<!&)\" " ), " "" )
42-
43- // Trim empty spacing.
44- val trimmed = escapedName.trim()
45-
46- return trimmed.ifBlank { null }
47- }
48-
4929/* *
5030 * Shared custom branding patch for YouTube and YT Music.
5131 */
@@ -57,6 +37,7 @@ internal fun baseCustomBrandingPatch(
5737 adaptiveMipmapFileNames : Array <String >,
5838 legacyMipmapFileNames : Array <String >,
5939 monochromeFileNames : Array <String >,
40+ manifestAppLauncherValue : String ,
6041 block : ResourcePatchBuilder .() -> Unit = {},
6142 executeBlock : ResourcePatchContext .() -> Unit = {}
6243): ResourcePatch = resourcePatch(
@@ -93,6 +74,20 @@ internal fun baseCustomBrandingPatch(
9374
9475 block()
9576
77+ dependsOn(
78+ // Change the app name.
79+ resourcePatch {
80+ execute {
81+ document(" AndroidManifest.xml" ).use { document ->
82+ document.childNodes.findElementByAttributeValueOrThrow(
83+ " android:label" ,
84+ manifestAppLauncherValue
85+ ).nodeValue = appName!!
86+ }
87+ }
88+ }
89+ )
90+
9691 execute {
9792 val iconPathTrimmed = iconPath!! .trim()
9893
@@ -164,27 +159,6 @@ internal fun baseCustomBrandingPatch(
164159 }
165160 }
166161
167- // Change the app name.
168- escapeAppName(appName!! )?.let { escapedAppName ->
169- val newValue = " android:label=\" $escapedAppName \" "
170-
171- val manifest = get(" AndroidManifest.xml" )
172- val original = manifest.readText()
173- val replacement = original
174- // YouTube
175- .replace(" android:label=\" @string/application_name\" " , newValue)
176- // YT Music
177- .replace(" android:label=\" @string/app_launcher_name\" " , newValue)
178-
179- if (original == replacement) {
180- Logger .getLogger(this ::class .java.name).warning(
181- " Could not replace manifest app name"
182- )
183- }
184-
185- manifest.writeText(replacement)
186- }
187-
188162 executeBlock() // Must be after the main code to rename the new icons for YouTube 19.34+.
189163 }
190164}
0 commit comments