Skip to content

Commit 9140194

Browse files
fix YT Music
1 parent 45b3737 commit 9140194

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

patches/src/main/kotlin/app/revanced/patches/music/layout/branding/CustomBrandingPatch.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ val customBrandingPatch = baseCustomBrandingPatch(
6161
originalLauncherIconName = "ic_launcher_release",
6262
originalAppName = "@string/app_launcher_name",
6363
originalAppPackageName = MUSIC_PACKAGE_NAME,
64+
copyExistingIntentsToAliases = false,
6465
numberOfPresetAppNames = 4,
6566
mainActivityOnCreateFingerprint = musicActivityOnCreateFingerprint,
6667
mainActivityName = MUSIC_MAIN_ACTIVITY_NAME,
67-
activityAliasNameWithIntentToRemove = MUSIC_MAIN_ACTIVITY_NAME,
68+
activityAliasNameWithIntents = MUSIC_MAIN_ACTIVITY_NAME,
6869
preferenceScreen = PreferenceScreen.GENERAL,
6970

7071
block = {

patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ internal fun baseCustomBrandingPatch(
6464
originalLauncherIconName: String,
6565
originalAppName: String,
6666
originalAppPackageName: String,
67+
copyExistingIntentsToAliases: Boolean,
6768
numberOfPresetAppNames: Int,
6869
mainActivityOnCreateFingerprint: Fingerprint,
6970
mainActivityName: String,
70-
activityAliasNameWithIntentToRemove: String,
71+
activityAliasNameWithIntents: String,
7172
preferenceScreen: BasePreferenceScreen.Screen,
7273
block: ResourcePatchBuilder.() -> Unit = {},
7374
executeBlock: ResourcePatchContext.() -> Unit = {}
@@ -297,25 +298,35 @@ internal fun baseCustomBrandingPatch(
297298
alias.setAttribute("android:targetActivity", mainActivityName)
298299

299300
// Copy all intents from the original alias so long press actions still work.
300-
for (i in 0 until intents.length) {
301-
alias.appendChild(
302-
intents.item(i).cloneNode(true)
303-
)
301+
if (copyExistingIntentsToAliases) {
302+
for (i in 0 until intents.length) {
303+
alias.appendChild(
304+
intents.item(i).cloneNode(true)
305+
)
306+
}
307+
} else {
308+
val intentFilter = document.createElement("intent-filter").apply {
309+
val action = document.createElement("action")
310+
action.setAttribute("android:name", "android.intent.action.MAIN")
311+
appendChild(action)
312+
313+
val category = document.createElement("category")
314+
category.setAttribute("android:name", "android.intent.category.LAUNCHER")
315+
appendChild(category)
316+
}
317+
alias.appendChild(intentFilter)
304318
}
305319

306320
return alias
307321
}
308322

309-
// Remove the original main alias.
310-
val originalIntent = document.childNodes.findElementByAttributeValueOrThrow(
323+
val intentFilters = document.childNodes.findElementByAttributeValueOrThrow(
311324
"android:name",
312-
activityAliasNameWithIntentToRemove
313-
)
314-
originalIntent.parentNode.removeChild(originalIntent)
325+
activityAliasNameWithIntents
326+
).childNodes
315327

316328
val namePrefix = ".revanced_"
317329
val iconResourcePrefix = "revanced_launcher_"
318-
val intentFilters = originalIntent.childNodes
319330
val application = document.getElementsByTagName("application")
320331
.item(0) as Element
321332

@@ -366,6 +377,15 @@ internal fun baseCustomBrandingPatch(
366377
)
367378
)
368379
}
380+
381+
// Remove the main action from the original alias, otherwise two apps icons
382+
// can be shown in the launcher. Must do this after adding new aliases.
383+
intentFilters.findElementByAttributeValueOrThrow(
384+
"android:name",
385+
"android.intent.action.MAIN"
386+
).let { intent ->
387+
intent.parentNode.removeChild(intent)
388+
}
369389
}
370390

371391
executeBlock()

patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/CustomBrandingPatch.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ val customBrandingPatch = baseCustomBrandingPatch(
1313
originalLauncherIconName = "ic_launcher",
1414
originalAppName = "@string/application_name",
1515
originalAppPackageName = YOUTUBE_PACKAGE_NAME,
16+
copyExistingIntentsToAliases = true,
1617
numberOfPresetAppNames = 4,
1718
mainActivityOnCreateFingerprint = mainActivityOnCreateFingerprint,
1819
mainActivityName = YOUTUBE_MAIN_ACTIVITY_NAME,
19-
activityAliasNameWithIntentToRemove = "com.google.android.youtube.app.honeycomb.Shell\$HomeActivity",
20+
activityAliasNameWithIntents = "com.google.android.youtube.app.honeycomb.Shell\$HomeActivity",
2021
preferenceScreen = PreferenceScreen.GENERAL_LAYOUT,
2122

2223
block = {

0 commit comments

Comments
 (0)