From 2c52f9c2f7f88d8cfba34380d9d49df94bc2c22a Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 16 Nov 2023 20:30:32 +0900 Subject: [PATCH] fix(YouTube/Settings): Patch Information is no longer updated by `ReVancedSettingsFragment` --- .../utils/settings/SettingsBytecodePatch.kt | 3 ++ .../youtube/utils/settings/SettingsPatch.kt | 30 ++++++++++++++++++- .../revanced/util/resources/ResourceHelper.kt | 2 +- .../youtube/settings/xml/revanced_prefs.xml | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsBytecodePatch.kt index aa1f57176..4d5d17fb5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsBytecodePatch.kt @@ -24,6 +24,8 @@ object SettingsBytecodePatch : BytecodePatch( setOf(ThemeSetterSystemFingerprint) ) { override fun execute(context: BytecodeContext) { + contexts = context + // apply the current theme of the settings page ThemeSetterSystemFingerprint.result?.let { it.mutableMethod.apply { @@ -47,6 +49,7 @@ object SettingsBytecodePatch : BytecodePatch( context.injectInit("InitializationPatch", "initializeReVancedSettings", true) } + internal lateinit var contexts: BytecodeContext private const val SET_THEME = "invoke-static {v0}, $INTEGRATIONS_PATH/utils/ThemeHelper;->setTheme(Ljava/lang/Object;)V" diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt index b80faf3c9..e980f532d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt @@ -13,9 +13,11 @@ import app.revanced.util.resources.IconHelper.makeDirectoryAndCopyFiles import app.revanced.util.resources.ResourceHelper.addPreference import app.revanced.util.resources.ResourceHelper.addReVancedPreference import app.revanced.util.resources.ResourceHelper.updatePatchStatus +import app.revanced.util.resources.ResourceHelper.updatePatchStatusSettings import app.revanced.util.resources.ResourceUtils import app.revanced.util.resources.ResourceUtils.copyResources import org.w3c.dom.Element +import java.io.Closeable import java.io.File import java.nio.file.Paths import java.util.concurrent.Executors @@ -63,7 +65,7 @@ object SettingsPatch : AbstractSettingsResourcePatch( "youtube/settings", "youtube/settings/host", true -) { +), Closeable { override fun execute(context: ResourceContext) { super.execute(context) contexts = context @@ -220,4 +222,30 @@ object SettingsPatch : AbstractSettingsResourcePatch( internal fun updatePatchStatus(patchTitle: String) { contexts.updatePatchStatus(patchTitle) } + + override fun close() { + SettingsBytecodePatch.contexts.classes.forEach { classDef -> + if (classDef.sourceFile != "BuildConfig.java") + return@forEach + + classDef.fields.forEach { field -> + if (field.name == "VERSION_NAME") { + contexts.updatePatchStatusSettings( + "ReVanced Integrations", + field.initialValue.toString().trim() + ) + } + } + } + + contexts["res/xml/revanced_prefs.xml"].apply { + writeText( + readText() + .replace( + """, + "" + ) + ) + } + } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt b/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt index 8d4d9cb68..589a3a0c6 100644 --- a/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt +++ b/src/main/kotlin/app/revanced/util/resources/ResourceHelper.kt @@ -82,7 +82,7 @@ internal object ResourceHelper { updatePatchStatusSettings("Theme", themeName) } - private fun ResourceContext.updatePatchStatusSettings( + internal fun ResourceContext.updatePatchStatusSettings( patchTitle: String, updateText: String ) { diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 9dbcc30cb..8f1a1c124 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -338,7 +338,7 @@ - +