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.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.*
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 YTM Extended, ReVanced Music Extended).")
@YouTubeMusicCompatibility
@Version("0.0.1")
@ -25,8 +20,8 @@ class CustomBrandingMusicNamePatch : ResourcePatch {
// App name
val resourceFileNames = arrayOf("strings.xml")
val fullName = PatchOptions.MusicAppNameFull
val shortName = PatchOptions.MusicAppNameShort
val longName = MusicLongName
val shortName = MusicShortName
context.forEach {
if (!it.name.startsWithAny(*resourceFileNames)) return@forEach
@ -40,7 +35,7 @@ class CustomBrandingMusicNamePatch : ResourcePatch {
val element = resourcesNode.childNodes.item(i) as Element
element.textContent = when (element.getAttribute("name")) {
"app_name" -> "$fullName"
"app_name" -> "$longName"
"app_launcher_name" -> "$shortName"
else -> continue
}
@ -50,4 +45,22 @@ class CustomBrandingMusicNamePatch : ResourcePatch {
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.YOUTUBE_PACKAGE_NAME
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
@Patch
@ -23,7 +23,7 @@ import app.revanced.util.microg.MicroGBytecodeHelper
[
ClientSpoofMusicPatch::class,
MusicMicroGResourcePatch::class,
PatchOptions::class
PackageNamePatch::class
]
)
@Name("music-microg-support")
@ -48,8 +48,8 @@ class MusicMicroGBytecodePatch : BytecodePatch(
// - "com.google.android.gms.phenotype.UPDATE",
// - "com.google.android.gms.phenotype",
override fun execute(context: BytecodeContext): PatchResult {
val packageNameYouTube = PatchOptions.YouTubePackageName!!
val packageNameMusic = PatchOptions.MusicPackageName!!
val packageNameYouTube = PackageNamePatch.YouTubePackageName!!
val packageNameMusic = PackageNamePatch.MusicPackageName!!
// apply common microG patch
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_SIGNATURE
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.MicroGResourceHelper.patchManifest
import app.revanced.util.resources.MusicResourceHelper.setMicroG
@Name("music-microg-resource-patch")
@Description("Resource patch to allow YouTube Music ReVanced to run without root and under a different package name.")
@DependsOn(
[
PatchOptions::class
]
)
@DependsOn([PackageNamePatch::class])
@YouTubeMusicCompatibility
@Version("0.0.2")
class MusicMicroGResourcePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
val packageNameMusic = PatchOptions.MusicPackageName!!
val packageNameMusic = PackageNamePatch.MusicPackageName!!
// update manifest
context.patchManifest(