Skip to content

Commit ab808ae

Browse files
feat(YouTube Music): Add Change miniplayer color patch (#6259)
Co-authored-by: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
1 parent a6b07cc commit ab808ae

File tree

6 files changed

+161
-0
lines changed

6 files changed

+161
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package app.revanced.extension.music.patches;
2+
3+
import app.revanced.extension.music.settings.Settings;
4+
5+
@SuppressWarnings("unused")
6+
public class ChangeMiniplayerColorPatch {
7+
8+
/**
9+
* Injection point
10+
*/
11+
public static boolean changeMiniplayerColor() {
12+
return Settings.CHANGE_MINIPLAYER_COLOR.get();
13+
}
14+
}

extensions/music/src/main/java/app/revanced/extension/music/settings/Settings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class Settings extends BaseSettings {
3030
public static final BooleanSetting HIDE_NAVIGATION_BAR_LABEL = new BooleanSetting("revanced_music_hide_navigation_bar_labels", FALSE, true);
3131

3232
// Player
33+
public static final BooleanSetting CHANGE_MINIPLAYER_COLOR = new BooleanSetting("revanced_music_change_miniplayer_color", FALSE, true);
3334
public static final BooleanSetting PERMANENT_REPEAT = new BooleanSetting("revanced_music_play_permanent_repeat", FALSE, true);
3435

3536
// Miscellaneous

patches/api/patches.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ public final class app/revanced/patches/music/layout/compactheader/HideCategoryB
416416
public static final fun getHideCategoryBar ()Lapp/revanced/patcher/patch/BytecodePatch;
417417
}
418418

419+
public final class app/revanced/patches/music/layout/miniplayercolor/ChangeMiniplayerColorKt {
420+
public static final fun getChangeMiniplayerColor ()Lapp/revanced/patcher/patch/BytecodePatch;
421+
}
422+
419423
public final class app/revanced/patches/music/layout/navigationbar/NavigationBarPatchKt {
420424
public static final fun getNavigationBarPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
421425
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
@file:Suppress("SpellCheckingInspection")
2+
3+
package app.revanced.patches.music.layout.miniplayercolor
4+
5+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
6+
import app.revanced.patcher.patch.bytecodePatch
7+
import app.revanced.patches.all.misc.resources.addResources
8+
import app.revanced.patches.all.misc.resources.addResourcesPatch
9+
import app.revanced.patches.music.misc.extension.sharedExtensionPatch
10+
import app.revanced.patches.music.misc.settings.PreferenceScreen
11+
import app.revanced.patches.music.misc.settings.settingsPatch
12+
import app.revanced.patches.shared.misc.mapping.get
13+
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
14+
import app.revanced.patches.shared.misc.mapping.resourceMappings
15+
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
16+
import app.revanced.util.addInstructionsAtControlFlowLabel
17+
import app.revanced.util.findFreeRegister
18+
import app.revanced.util.getReference
19+
import app.revanced.util.indexOfFirstInstructionOrThrow
20+
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
21+
import com.android.tools.smali.dexlib2.AccessFlags
22+
import com.android.tools.smali.dexlib2.Opcode
23+
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
24+
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
25+
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
26+
27+
internal var mpp_player_bottom_sheet = -1L
28+
private set
29+
30+
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/music/patches/ChangeMiniplayerColorPatch;"
31+
32+
@Suppress("unused")
33+
val changeMiniplayerColor = bytecodePatch(
34+
name = "Change miniplayer color",
35+
description = "Adds an option to change the miniplayer background color to match the fullscreen player."
36+
) {
37+
dependsOn(
38+
sharedExtensionPatch,
39+
settingsPatch,
40+
addResourcesPatch,
41+
resourceMappingPatch
42+
)
43+
44+
compatibleWith(
45+
"com.google.android.apps.youtube.music"(
46+
"7.29.52",
47+
"8.10.52"
48+
)
49+
)
50+
51+
execute {
52+
mpp_player_bottom_sheet = resourceMappings["id", "mpp_player_bottom_sheet"]
53+
54+
addResources("music", "layout.miniplayercolor.changeMiniplayerColor")
55+
56+
PreferenceScreen.PLAYER.addPreferences(
57+
SwitchPreference("revanced_music_change_miniplayer_color"),
58+
)
59+
60+
switchToggleColorFingerprint.match(miniPlayerConstructorFingerprint.classDef).let {
61+
val relativeIndex = it.patternMatch!!.endIndex + 1
62+
63+
val invokeVirtualIndex = it.method.indexOfFirstInstructionOrThrow(
64+
relativeIndex, Opcode.INVOKE_VIRTUAL
65+
)
66+
val colorMathPlayerInvokeVirtualReference = it.method
67+
.getInstruction<ReferenceInstruction>(invokeVirtualIndex).reference
68+
69+
val iGetIndex = it.method.indexOfFirstInstructionOrThrow(
70+
relativeIndex, Opcode.IGET
71+
)
72+
val colorMathPlayerIGetReference = it.method
73+
.getInstruction<ReferenceInstruction>(iGetIndex).reference as FieldReference
74+
75+
val colorGreyIndex = miniPlayerConstructorFingerprint.method.indexOfFirstInstructionReversedOrThrow {
76+
getReference<MethodReference>()?.name == "getColor"
77+
}
78+
val iPutIndex = miniPlayerConstructorFingerprint.method.indexOfFirstInstructionOrThrow(
79+
colorGreyIndex, Opcode.IPUT
80+
)
81+
val colorMathPlayerIPutReference = miniPlayerConstructorFingerprint.method
82+
.getInstruction<ReferenceInstruction>(iPutIndex).reference
83+
84+
miniPlayerConstructorFingerprint.classDef.methods.single { method ->
85+
method.accessFlags == AccessFlags.PUBLIC.value or AccessFlags.FINAL.value &&
86+
method.returnType == "V" &&
87+
method.parameters == it.originalMethod.parameters
88+
}.apply {
89+
val insertIndex = indexOfFirstInstructionReversedOrThrow(Opcode.INVOKE_DIRECT)
90+
val freeRegister = findFreeRegister(insertIndex)
91+
92+
addInstructionsAtControlFlowLabel(
93+
insertIndex,
94+
"""
95+
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->changeMiniplayerColor()Z
96+
move-result v$freeRegister
97+
if-eqz v$freeRegister, :off
98+
invoke-virtual { p1 }, $colorMathPlayerInvokeVirtualReference
99+
move-result-object v$freeRegister
100+
check-cast v$freeRegister, ${colorMathPlayerIGetReference.definingClass}
101+
iget v$freeRegister, v$freeRegister, $colorMathPlayerIGetReference
102+
iput v$freeRegister, p0, $colorMathPlayerIPutReference
103+
:off
104+
nop
105+
"""
106+
)
107+
}
108+
}
109+
}
110+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package app.revanced.patches.music.layout.miniplayercolor
2+
3+
import app.revanced.patcher.fingerprint
4+
import app.revanced.util.literal
5+
import com.android.tools.smali.dexlib2.AccessFlags
6+
import com.android.tools.smali.dexlib2.Opcode
7+
8+
internal val miniPlayerConstructorFingerprint = fingerprint {
9+
returns("V")
10+
strings("sharedToggleMenuItemMutations")
11+
literal { mpp_player_bottom_sheet }
12+
}
13+
14+
/**
15+
* Matches to the class found in [miniPlayerConstructorFingerprint].
16+
*/
17+
internal val switchToggleColorFingerprint = fingerprint {
18+
accessFlags(AccessFlags.PRIVATE, AccessFlags.FINAL)
19+
returns("V")
20+
parameters("L", "J")
21+
opcodes(
22+
Opcode.INVOKE_VIRTUAL,
23+
Opcode.MOVE_RESULT_OBJECT,
24+
Opcode.CHECK_CAST,
25+
Opcode.IGET
26+
)
27+
}

patches/src/main/resources/addresources/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,11 @@ Video playback with AV1 may stutter or drop frames."</string>
17181718
<string name="revanced_music_hide_category_bar_summary_on">Category bar is hidden</string>
17191719
<string name="revanced_music_hide_category_bar_summary_off">Category bar is shown</string>
17201720
</patch>
1721+
<patch id="layout.miniplayercolor.changeMiniplayerColor">
1722+
<string name="revanced_music_change_miniplayer_color_title">Change miniplayer color</string>
1723+
<string name="revanced_music_change_miniplayer_color_summary_on">Miniplayer color matches fullscreen player</string>
1724+
<string name="revanced_music_change_miniplayer_color_summary_off">Miniplayer uses default color</string>
1725+
</patch>
17211726
<patch id="layout.navigationbar.navigationBarPatch">
17221727
<string name="revanced_music_navigation_bar_screen_title">Navigation bar</string>
17231728
<string name="revanced_music_navigation_bar_screen_summary">Hide or change navigation bar buttons</string>

0 commit comments

Comments
 (0)