fix(YouTube - Theme): Resolve dark mode startup crash with Android 9.0 (Match with ReVanced)

This commit is contained in:
inotia00 2025-03-14 18:26:38 +09:00
parent 1a0b32b8d5
commit 6b1e45f234

View File

@ -24,29 +24,30 @@ val darkModeSplashScreenPatch = resourcePatch(
* This is a bug in unpatched YouTube. * This is a bug in unpatched YouTube.
* Should always be applied even if the `Theme` patch is excluded. * Should always be applied even if the `Theme` patch is excluded.
*/ */
document("res/values-night/styles.xml").use { document -> document("res/values-night-v27/styles.xml").use { document ->
val resourcesNode = document.getElementsByTagName("resources").item(0) as Element // Create a night mode specific override for the splash screen background.
val childNodes = resourcesNode.childNodes val style = document.createElement("style")
style.setAttribute("name", "Theme.YouTube.Home")
style.setAttribute("parent", "@style/Base.V27.Theme.YouTube.Home")
for (i in 0 until childNodes.length) { // Fix status and navigation bar showing white on some Android devices,
val node = childNodes.item(i) as? Element ?: continue // such as SDK 28 Android 10 medium tablet.
val nodeAttributeName = node.getAttribute("name") val colorSplashBackgroundColor = "@color/yt_black1"
if (nodeAttributeName.startsWith("Theme.YouTube.Launcher")) { arrayOf(
val nodeAttributeParent = node.getAttribute("parent") "android:navigationBarColor" to colorSplashBackgroundColor,
"android:windowBackground" to colorSplashBackgroundColor,
val style = document.createElement("style") "android:colorBackground" to colorSplashBackgroundColor,
style.setAttribute("name", "Theme.YouTube.Home") "colorPrimaryDark" to colorSplashBackgroundColor,
style.setAttribute("parent", nodeAttributeParent) "android:windowLightStatusBar" to "false",
).forEach { (name, value) ->
val windowItem = document.createElement("item") val styleItem = document.createElement("item")
windowItem.setAttribute("name", "android:windowBackground") styleItem.setAttribute("name", name)
windowItem.textContent = "@color/yt_black1" styleItem.textContent = value
style.appendChild(windowItem) style.appendChild(styleItem)
resourcesNode.removeChild(node)
resourcesNode.appendChild(style)
}
} }
val resourcesNode = document.getElementsByTagName("resources").item(0) as Element
resourcesNode.appendChild(style)
} }
} }
} }