feat(music/patch-options): all patch options are now moved to the appropriate patch

This commit is contained in:
inotia00 2023-05-08 04:17:53 +09:00
parent 40e2761033
commit b0cb76682b
3 changed files with 29 additions and 20 deletions

View File

@ -5,18 +5,13 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.*
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.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
import app.revanced.patches.shared.patch.options.PatchOptions
import org.w3c.dom.Element import org.w3c.dom.Element
@Patch(false) @Patch(false)
@Name("custom-branding-music-name") @Name("custom-branding-music-name")
@DependsOn([PatchOptions::class])
@Description("Changes the Music launcher name to your choice (defaults to YTM Extended, ReVanced Music Extended).") @Description("Changes the Music launcher name to your choice (defaults to YTM Extended, ReVanced Music Extended).")
@YouTubeMusicCompatibility @YouTubeMusicCompatibility
@Version("0.0.1") @Version("0.0.1")
@ -25,8 +20,8 @@ class CustomBrandingMusicNamePatch : ResourcePatch {
// App name // App name
val resourceFileNames = arrayOf("strings.xml") val resourceFileNames = arrayOf("strings.xml")
val fullName = PatchOptions.MusicAppNameFull val longName = MusicLongName
val shortName = PatchOptions.MusicAppNameShort val shortName = MusicShortName
context.forEach { context.forEach {
if (!it.name.startsWithAny(*resourceFileNames)) return@forEach if (!it.name.startsWithAny(*resourceFileNames)) return@forEach
@ -40,7 +35,7 @@ class CustomBrandingMusicNamePatch : ResourcePatch {
val element = resourcesNode.childNodes.item(i) as Element val element = resourcesNode.childNodes.item(i) as Element
element.textContent = when (element.getAttribute("name")) { element.textContent = when (element.getAttribute("name")) {
"app_name" -> "$fullName" "app_name" -> "$longName"
"app_launcher_name" -> "$shortName" "app_launcher_name" -> "$shortName"
else -> continue else -> continue
} }
@ -50,4 +45,22 @@ class CustomBrandingMusicNamePatch : ResourcePatch {
return PatchResultSuccess() return PatchResultSuccess()
} }
companion object : OptionsContainer() {
var MusicLongName: String? by option(
PatchOption.StringOption(
key = "MusicLongName",
default = "ReVanced Music Extended",
title = "Application Name of YouTube Music",
description = "The name of the YouTube Music it will show on your notification panel."
)
)
var MusicShortName: String? by option(
PatchOption.StringOption(
key = "MusicShortName",
default = "YTM Extended",
title = "Application Name of YouTube Music",
description = "The name of the YouTube Music it will show on your home screen."
)
)
}
} }

View File

@ -15,7 +15,7 @@ import app.revanced.patches.music.misc.microg.resource.patch.MusicMicroGResource
import app.revanced.patches.music.misc.microg.shared.Constants.MUSIC_PACKAGE_NAME import app.revanced.patches.music.misc.microg.shared.Constants.MUSIC_PACKAGE_NAME
import app.revanced.patches.music.misc.microg.shared.Constants.YOUTUBE_PACKAGE_NAME import app.revanced.patches.music.misc.microg.shared.Constants.YOUTUBE_PACKAGE_NAME
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
import app.revanced.patches.shared.patch.options.PatchOptions import app.revanced.patches.shared.patch.packagename.PackageNamePatch
import app.revanced.util.microg.MicroGBytecodeHelper import app.revanced.util.microg.MicroGBytecodeHelper
@Patch @Patch
@ -23,7 +23,7 @@ import app.revanced.util.microg.MicroGBytecodeHelper
[ [
ClientSpoofMusicPatch::class, ClientSpoofMusicPatch::class,
MusicMicroGResourcePatch::class, MusicMicroGResourcePatch::class,
PatchOptions::class PackageNamePatch::class
] ]
) )
@Name("music-microg-support") @Name("music-microg-support")
@ -48,8 +48,8 @@ class MusicMicroGBytecodePatch : BytecodePatch(
// - "com.google.android.gms.phenotype.UPDATE", // - "com.google.android.gms.phenotype.UPDATE",
// - "com.google.android.gms.phenotype", // - "com.google.android.gms.phenotype",
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
val packageNameYouTube = PatchOptions.YouTubePackageName!! val packageNameYouTube = PackageNamePatch.YouTubePackageName!!
val packageNameMusic = PatchOptions.MusicPackageName!! val packageNameMusic = PackageNamePatch.MusicPackageName!!
// apply common microG patch // apply common microG patch
MicroGBytecodeHelper.patchBytecode( MicroGBytecodeHelper.patchBytecode(

View File

@ -12,23 +12,19 @@ import app.revanced.patches.music.misc.microg.shared.Constants.MUSIC_PACKAGE_NAM
import app.revanced.patches.music.misc.microg.shared.Constants.SPOOFED_PACKAGE_NAME import app.revanced.patches.music.misc.microg.shared.Constants.SPOOFED_PACKAGE_NAME
import app.revanced.patches.music.misc.microg.shared.Constants.SPOOFED_PACKAGE_SIGNATURE import app.revanced.patches.music.misc.microg.shared.Constants.SPOOFED_PACKAGE_SIGNATURE
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
import app.revanced.patches.shared.patch.options.PatchOptions import app.revanced.patches.shared.patch.packagename.PackageNamePatch
import app.revanced.util.microg.MicroGManifestHelper.addSpoofingMetadata import app.revanced.util.microg.MicroGManifestHelper.addSpoofingMetadata
import app.revanced.util.microg.MicroGResourceHelper.patchManifest import app.revanced.util.microg.MicroGResourceHelper.patchManifest
import app.revanced.util.resources.MusicResourceHelper.setMicroG import app.revanced.util.resources.MusicResourceHelper.setMicroG
@Name("music-microg-resource-patch") @Name("music-microg-resource-patch")
@Description("Resource patch to allow YouTube Music ReVanced to run without root and under a different package name.") @Description("Resource patch to allow YouTube Music ReVanced to run without root and under a different package name.")
@DependsOn( @DependsOn([PackageNamePatch::class])
[
PatchOptions::class
]
)
@YouTubeMusicCompatibility @YouTubeMusicCompatibility
@Version("0.0.2") @Version("0.0.2")
class MusicMicroGResourcePatch : ResourcePatch { class MusicMicroGResourcePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult { override fun execute(context: ResourceContext): PatchResult {
val packageNameMusic = PatchOptions.MusicPackageName!! val packageNameMusic = PackageNamePatch.MusicPackageName!!
// update manifest // update manifest
context.patchManifest( context.patchManifest(