diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/SharedThemePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/SharedThemePatch.kt index 0ca1403b1..db5bab1e4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/SharedThemePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/SharedThemePatch.kt @@ -6,8 +6,6 @@ import app.revanced.patches.shared.drawable.addDrawableColorHook import app.revanced.patches.shared.drawable.drawableColorHookPatch import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.extension.Constants.UTILS_PATH -import app.revanced.patches.youtube.utils.playservice.is_19_32_or_greater -import app.revanced.patches.youtube.utils.playservice.versionCheckPatch import org.w3c.dom.Element private const val SPLASH_SCREEN_COLOR_NAME = "splashScreenColor" @@ -18,10 +16,7 @@ val sharedThemePatch = resourcePatch( ) { compatibleWith(COMPATIBLE_PACKAGE) - dependsOn( - drawableColorHookPatch, - versionCheckPatch, - ) + dependsOn(drawableColorHookPatch) execute { addDrawableColorHook("$UTILS_PATH/DrawableColorPatch;->getLithoColor(I)I") @@ -106,36 +101,5 @@ val sharedThemePatch = resourcePatch( } } - if (is_19_32_or_greater) { - // Fix the splash screen dark mode background color. - // In earlier versions of the app this is white and makes no sense for dark mode. - // This is only required for 19.32 and greater, but is applied to all targets. - // Only dark mode needs this fix as light mode correctly uses the custom color. - document("res/values-night/styles.xml").use { document -> - val resourcesNode = document.getElementsByTagName("resources").item(0) as Element - val childNodes = resourcesNode.childNodes - - for (i in 0 until childNodes.length) { - val node = childNodes.item(i) as? Element ?: continue - val nodeAttributeName = node.getAttribute("name") - if (nodeAttributeName == "Theme.YouTube.Launcher" || nodeAttributeName == "Theme.YouTube.Launcher.Cairo") { - val nodeAttributeParent = node.getAttribute("parent") - - val style = document.createElement("style") - style.setAttribute("name", "Theme.YouTube.Home") - style.setAttribute("parent", nodeAttributeParent) - - val windowItem = document.createElement("item") - windowItem.setAttribute("name", "android:windowBackground") - windowItem.textContent = "@color/yt_black1" - style.appendChild(windowItem) - - resourcesNode.removeChild(node) - resourcesNode.appendChild(style) - } - } - } - } - } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt new file mode 100644 index 000000000..515dd45af --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt @@ -0,0 +1,52 @@ +package app.revanced.patches.youtube.utils.fix.splash + +import app.revanced.patcher.patch.resourcePatch +import app.revanced.patches.youtube.utils.playservice.is_19_32_or_greater +import app.revanced.patches.youtube.utils.playservice.versionCheckPatch +import org.w3c.dom.Element + +val darkModeSplashScreenPatch = resourcePatch( + description = "darkModeSplashScreenPatch" +) { + dependsOn(versionCheckPatch) + + execute { + if (!is_19_32_or_greater) { + return@execute + } + + /** + * Fix the splash screen dark mode background color. + * In earlier versions of the app this is white and makes no sense for dark mode. + * This is only required for 19.32 and greater, but is applied to all targets. + * Only dark mode needs this fix as light mode correctly uses the custom color. + * + * This is a bug in unpatched YouTube. + * Should always be applied even if the `Theme` patch is excluded. + */ + document("res/values-night/styles.xml").use { document -> + val resourcesNode = document.getElementsByTagName("resources").item(0) as Element + val childNodes = resourcesNode.childNodes + + for (i in 0 until childNodes.length) { + val node = childNodes.item(i) as? Element ?: continue + val nodeAttributeName = node.getAttribute("name") + if (nodeAttributeName.startsWith("Theme.YouTube.Launcher")) { + val nodeAttributeParent = node.getAttribute("parent") + + val style = document.createElement("style") + style.setAttribute("name", "Theme.YouTube.Home") + style.setAttribute("parent", nodeAttributeParent) + + val windowItem = document.createElement("item") + windowItem.setAttribute("name", "android:windowBackground") + windowItem.textContent = "@color/yt_black1" + style.appendChild(windowItem) + + resourcesNode.removeChild(node) + resourcesNode.appendChild(style) + } + } + } + } +} diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt index 14f371e81..7259a9a4d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt @@ -15,6 +15,7 @@ import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PAC import app.revanced.patches.youtube.utils.extension.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.extension.sharedExtensionPatch import app.revanced.patches.youtube.utils.fix.cairo.cairoSettingsPatch +import app.revanced.patches.youtube.utils.fix.splash.darkModeSplashScreenPatch import app.revanced.patches.youtube.utils.mainactivity.mainActivityResolvePatch import app.revanced.patches.youtube.utils.patch.PatchList.SETTINGS_FOR_YOUTUBE import app.revanced.patches.youtube.utils.playservice.versionCheckPatch @@ -120,6 +121,7 @@ val settingsPatch = resourcePatch( dependsOn( settingsBytecodePatch, cairoSettingsPatch, + darkModeSplashScreenPatch, ) val insertPosition = stringOption(