feat: add "Application Name" option to branding and move renaming to CustomBrandingPatch.kt

This commit is contained in:
Sculas 2022-08-02 21:28:22 +02:00
parent adcf4065ac
commit 8dafe05b2c
No known key found for this signature in database
GPG Key ID: 1530BFF96D1EEB89
3 changed files with 29 additions and 8 deletions

View File

@ -4,9 +4,7 @@ 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.impl.ResourceData import app.revanced.patcher.data.impl.ResourceData
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.*
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.ResourcePatch import app.revanced.patcher.patch.impl.ResourcePatch
@ -17,7 +15,7 @@ import java.nio.file.Files
@Patch @Patch
@DependsOn(FixLocaleConfigErrorPatch::class) @DependsOn(FixLocaleConfigErrorPatch::class)
@Name("custom-branding") @Name("custom-branding")
@Description("Changes the YouTube launcher icon to be ReVanced's.") @Description("Changes the YouTube launcher icon and name to your choice (defaults to ReVanced).")
@CustomBrandingCompatibility @CustomBrandingCompatibility
@Version("0.0.1") @Version("0.0.1")
class CustomBrandingPatch : ResourcePatch() { class CustomBrandingPatch : ResourcePatch() {
@ -25,6 +23,7 @@ class CustomBrandingPatch : ResourcePatch() {
val resDirectory = data["res"] val resDirectory = data["res"]
if (!resDirectory.isDirectory) return PatchResultError("The res folder can not be found.") if (!resDirectory.isDirectory) return PatchResultError("The res folder can not be found.")
// Icon branding
val iconNames = arrayOf( val iconNames = arrayOf(
"adaptiveproduct_youtube_background_color_108", "adaptiveproduct_youtube_background_color_108",
"adaptiveproduct_youtube_foreground_color_108", "adaptiveproduct_youtube_foreground_color_108",
@ -50,6 +49,32 @@ class CustomBrandingPatch : ResourcePatch() {
} }
} }
// Name branding
val appName = options[keyAppName].value
val manifest = data["AndroidManifest.xml"]
manifest.writeText(
manifest.readText()
.replace(
"android:label=\"@string/application_name",
"android:label=\"$appName"
)
)
return PatchResultSuccess() return PatchResultSuccess()
} }
override val options = PatchOptions(
PatchOption.StringOption(
key = keyAppName,
default = "YouTube ReVanced",
title = "Application Name",
description = "The name of the application it will show on your home screen.",
required = true
)
)
private companion object {
private const val keyAppName = "appName"
}
} }

View File

@ -11,7 +11,6 @@ import app.revanced.patcher.patch.impl.ResourcePatch
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
import app.revanced.patches.youtube.misc.microg.annotations.MicroGPatchCompatibility import app.revanced.patches.youtube.misc.microg.annotations.MicroGPatchCompatibility
import app.revanced.patches.youtube.misc.microg.shared.Constants.BASE_MICROG_PACKAGE_NAME import app.revanced.patches.youtube.misc.microg.shared.Constants.BASE_MICROG_PACKAGE_NAME
import app.revanced.patches.youtube.misc.microg.shared.Constants.REVANCED_APP_NAME
import app.revanced.patches.youtube.misc.microg.shared.Constants.REVANCED_PACKAGE_NAME import app.revanced.patches.youtube.misc.microg.shared.Constants.REVANCED_PACKAGE_NAME
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourcePatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourcePatch
@ -48,8 +47,6 @@ class MicroGResourcePatch : ResourcePatch() {
manifest.readText() manifest.readText()
.replace( .replace(
"package=\"com.google.android.youtube", "package=\"$REVANCED_PACKAGE_NAME" "package=\"com.google.android.youtube", "package=\"$REVANCED_PACKAGE_NAME"
).replace(
"android:label=\"@string/application_name", "android:label=\"$REVANCED_APP_NAME"
).replace( ).replace(
"android:authorities=\"com.google.android.youtube", "android:authorities=\"$REVANCED_PACKAGE_NAME" "android:authorities=\"com.google.android.youtube", "android:authorities=\"$REVANCED_PACKAGE_NAME"
).replace( ).replace(

View File

@ -3,5 +3,4 @@ package app.revanced.patches.youtube.misc.microg.shared
object Constants { object Constants {
internal const val BASE_MICROG_PACKAGE_NAME = "com.mgoogle" internal const val BASE_MICROG_PACKAGE_NAME = "com.mgoogle"
internal const val REVANCED_PACKAGE_NAME = "app.revanced.android.youtube" internal const val REVANCED_PACKAGE_NAME = "app.revanced.android.youtube"
internal const val REVANCED_APP_NAME = "YouTube ReVanced"
} }