feat: migrate to osumatrix/revanced-patcher dependency

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
oSumAtrIX
2022-09-09 03:49:16 +02:00
parent cb10ea1797
commit 331107288d
5 changed files with 37 additions and 30 deletions

View File

@@ -11,7 +11,14 @@ repositories {
mavenCentral()
mavenLocal()
maven {
url = uri("https://maven.pkg.github.com/revanced/revanced-patcher")
url = uri("https://maven.pkg.github.com/osumatrix/revanced-patcher")
credentials {
username = githubUsername
password = githubPassword
}
}
maven {
url = uri("https://maven.pkg.github.com/revanced/multidexlib2")
credentials {
username = githubUsername
password = githubPassword

View File

@@ -10,7 +10,7 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.ResourcePatch
import app.revanced.patches.youtube.layout.amoled.annotations.AmoledCompatibility
import app.revanced.patches.youtube.layout.theme.patch.ThemePatch
import app.revanced.patches.youtube.layout.customthemes.patch.CustomThemePatch
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
@Patch
@@ -19,10 +19,10 @@ import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatc
@Description("Enables pure black theme.")
@AmoledCompatibility
@Version("0.0.1")
@PatchDeprecated("Theme patch already includes the Amoled theme.", ThemePatch::class)
@PatchDeprecated("Theme patch already includes the Amoled theme.", CustomThemePatch::class)
class AmoledPatch : ResourcePatch() {
override fun execute(data: ResourceData): PatchResult {
ThemePatch.theme = ThemePatch.Themes.Amoled.name
return ThemePatch().execute(data)
CustomThemePatch.themeOption.value = CustomThemePatch.Themes.AMOLED.name
return CustomThemePatch().execute(data)
}
}

View File

@@ -10,10 +10,11 @@ import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.ResourcePatch
import app.revanced.patches.youtube.layout.branding.icon.annotations.CustomBrandingCompatibility
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.exists
import kotlin.io.path.inputStream
@Patch
@DependsOn([FixLocaleConfigErrorPatch::class])
@@ -66,29 +67,28 @@ class CustomBrandingPatch : ResourcePatch() {
}
private fun getIconStream(iconPath: String): InputStream? {
if (appIconPath == null) {
return this.javaClass.classLoader.getResourceAsStream(iconPath)
}
val file = File(appIconPath!!).resolve(iconPath)
if (!file.exists()) return null
return FileInputStream(file)
val path = Path.of(appIconPath.value ?: return this.javaClass.classLoader.getResourceAsStream(iconPath))
return if (path.exists())
path.inputStream()
else
null
}
companion object : OptionsContainer() {
private var appName: String? by option(
private var appName = option(
PatchOption.StringOption(
key = "appName",
default = "YouTube ReVanced",
title = "Application Name",
description = "The name of the application it will show on your home screen.",
default = "YouTube ReVanced",
required = true
)
)
private var appIconPath: String? by option(
private var appIconPath = option(
PatchOption.StringOption(
key = "appIconPath",
default = null,
title = "Application Icon Path",
description = "A path to the icon of the application."
)

View File

@@ -1,4 +1,4 @@
package app.revanced.patches.youtube.layout.theme.annotations
package app.revanced.patches.youtube.layout.customthemes.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@@ -6,4 +6,4 @@ import app.revanced.patcher.annotation.Package
@Compatibility([Package("com.google.android.youtube")])
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class ThemeCompatibility
internal annotation class CustomThemeCompatibility

View File

@@ -1,4 +1,4 @@
package app.revanced.patches.youtube.layout.theme.patch
package app.revanced.patches.youtube.layout.customthemes.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
@@ -8,19 +8,20 @@ import app.revanced.patcher.patch.*
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.ResourcePatch
import app.revanced.patches.youtube.layout.theme.annotations.ThemeCompatibility
import app.revanced.patches.youtube.layout.customthemes.annotations.CustomThemeCompatibility
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
import org.w3c.dom.Element
@Patch
@DependsOn([FixLocaleConfigErrorPatch::class])
@Name("theme")
@Name("custom-theme")
@Description("Enables a custom theme.")
@ThemeCompatibility
@CustomThemeCompatibility
@Version("0.0.1")
class ThemePatch : ResourcePatch() {
class CustomThemePatch : ResourcePatch() {
override fun execute(data: ResourceData): PatchResult {
val theme = Themes.of(theme!!) ?: return PatchResultError("Theme '$theme' not found.")
val theme =
Themes.of(themeOption.value!!) ?: return PatchResultError("The theme '$themeOption' does not exist.")
data.xmlEditor["res/values/colors.xml"].use { editor ->
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
@@ -35,10 +36,10 @@ class ThemePatch : ResourcePatch() {
}
companion object : OptionsContainer() {
var theme: String? by option(
var themeOption = option(
PatchOption.StringListOption(
key = "theme",
default = Themes.Amoled.name,
default = Themes.AMOLED.name,
options = Themes.names,
title = "Theme",
description = "Select a theme.",
@@ -48,11 +49,10 @@ class ThemePatch : ResourcePatch() {
}
enum class Themes(val apply: (String) -> String?) {
Amoled({ attr ->
when (attr) {
AMOLED({ nodeName ->
when (nodeName) {
"yt_black1", "yt_black1_opacity95", "yt_black2", "yt_black3", "yt_black4",
"yt_status_bar_background_dark" -> "@android:color/black"
"yt_selected_nav_label_dark" -> "#ffdf0000"
else -> null
}