From 331107288d87535ad5148bf2a22a62470a868823 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Fri, 9 Sep 2022 03:49:16 +0200 Subject: [PATCH] feat: migrate to `osumatrix/revanced-patcher` dependency Signed-off-by: oSumAtrIX --- build.gradle.kts | 9 ++++++- .../layout/amoled/patch/AmoledPatch.kt | 8 +++---- .../icon/patch/CustomBrandingPatch.kt | 24 +++++++++---------- .../annotations/CustomThemeCompatibility.kt} | 4 ++-- .../patch/CustomThemePatch.kt} | 22 ++++++++--------- 5 files changed, 37 insertions(+), 30 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/layout/{theme/annotations/ThemeCompatibility.kt => customthemes/annotations/CustomThemeCompatibility.kt} (65%) rename src/main/kotlin/app/revanced/patches/youtube/layout/{theme/patch/ThemePatch.kt => customthemes/patch/CustomThemePatch.kt} (78%) diff --git a/build.gradle.kts b/build.gradle.kts index 1b15fdeb0..8c6b3eee9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/amoled/patch/AmoledPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/amoled/patch/AmoledPatch.kt index 1e66caf7b..2dda2cc75 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/amoled/patch/AmoledPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/amoled/patch/AmoledPatch.kt @@ -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) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/patch/CustomBrandingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/patch/CustomBrandingPatch.kt index 3e3ad9872..351ae3ae5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/patch/CustomBrandingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/patch/CustomBrandingPatch.kt @@ -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." ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/annotations/ThemeCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/customthemes/annotations/CustomThemeCompatibility.kt similarity index 65% rename from src/main/kotlin/app/revanced/patches/youtube/layout/theme/annotations/ThemeCompatibility.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/customthemes/annotations/CustomThemeCompatibility.kt index 5bf335060..34c7e1cc6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/annotations/ThemeCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/customthemes/annotations/CustomThemeCompatibility.kt @@ -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 diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/ThemePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/customthemes/patch/CustomThemePatch.kt similarity index 78% rename from src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/ThemePatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/customthemes/patch/CustomThemePatch.kt index f843009b1..3d3550867 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/ThemePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/customthemes/patch/CustomThemePatch.kt @@ -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 }