-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(YouTube): Splash screen background color does not change in dark …
…mode if `Theme` patch is excluded
Showing
3 changed files
with
55 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...rc/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters