Skip to content

Commit

Permalink
fix(YouTube): Splash screen background color does not change in dark …
Browse files Browse the repository at this point in the history
…mode if `Theme` patch is excluded
inotia00 authored and anddea committed Dec 21, 2024
1 parent 40f8401 commit 28df1b4
Showing 3 changed files with 55 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}

}
}
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)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -16,6 +16,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
@@ -121,6 +122,7 @@ val settingsPatch = resourcePatch(
dependsOn(
settingsBytecodePatch,
cairoSettingsPatch,
darkModeSplashScreenPatch,
)

val insertPosition = stringOption(

0 comments on commit 28df1b4

Please sign in to comment.