add enable-compact-dialog patch

This commit is contained in:
inotia00 2023-04-06 20:03:25 +09:00
parent 275385139b
commit 40a09ed46b
4 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package app.revanced.patches.music.layout.compactdialog.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.music.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object DialogSolidFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.dialogSolidLabelId
} == true
}
)

View File

@ -0,0 +1,58 @@
package app.revanced.patches.music.layout.compactdialog.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.music.layout.compactdialog.fingerprints.DialogSolidFingerprint
import app.revanced.patches.music.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.music.misc.settings.patch.MusicSettingsPatch
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
import app.revanced.util.integrations.Constants.MUSIC_SETTINGS_PATH
@Patch
@Name("enable-compact-dialog")
@Description("Enable compact dialog on phone.")
@DependsOn(
[
MusicSettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeMusicCompatibility
@Version("0.0.1")
class CompactDialogPatch : BytecodePatch(
listOf(
DialogSolidFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
DialogSolidFingerprint.result?.let {
with(context
.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.endIndex, true)
.getMethod() as MutableMethod
) {
addInstructions(
2, """
invoke-static {p0}, $MUSIC_SETTINGS_PATH->enableCompactDialog(I)I
move-result p0
"""
)
}
} ?: return DialogSolidFingerprint.toErrorResult()
MusicSettingsPatch.addMusicPreference("navigation", "revanced_enable_compact_dialog", "true")
return PatchResultSuccess()
}
}

View File

@ -17,6 +17,7 @@ import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch
class SharedResourceIdPatch : ResourcePatch {
internal companion object {
var colorGreyLabelId: Long = -1
var dialogSolidLabelId: Long = -1
var disabledIconLabelId: Long = -1
var isTabletLabelId: Long = -1
}
@ -28,6 +29,7 @@ class SharedResourceIdPatch : ResourcePatch {
.single { it.type == type && it.name == name }.id
colorGreyLabelId = findSharedResourceId("color", "ytm_color_grey_12")
dialogSolidLabelId = findSharedResourceId("style", "Theme.YouTubeMusic.Dialog.Solid")
disabledIconLabelId = findSharedResourceId("dimen", "disabled_icon_alpha")
isTabletLabelId = findSharedResourceId("bool", "is_tablet")

View File

@ -10,6 +10,8 @@
<string name="revanced_enable_black_navbar_title">Enable black navbar</string>
<string name="revanced_enable_color_match_player_summary">Matches the fullscreen player color with the minimized one.</string>
<string name="revanced_enable_color_match_player_title">Enable color match Players</string>
<string name="revanced_enable_compact_dialog_summary">Enable compact dialog on phone.</string>
<string name="revanced_enable_compact_dialog_title">Enable compact dialog</string>
<string name="revanced_enable_force_minimized_player_summary">Keep player permanently minimized even if another track is played.</string>
<string name="revanced_enable_force_minimized_player_title">Enable force minimized player</string>
<string name="revanced_enable_force_shuffle_summary">Enable force shuffle even if another track is played.</string>