From bd05ad0bbb5fa765b2361b76e0618b9e2cf555e3 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Tue, 23 Jan 2024 07:11:55 +0900 Subject: [PATCH] feat(YouTube Music): remove `Enable sleep timer` patch --- .../flyoutpanel/component/FlyoutPanelPatch.kt | 23 ++++++- .../fingerprints/SleepTimerFingerprint.kt | 2 +- .../flyoutpanel/sleeptimer/SleepTimerPatch.kt | 65 ------------------- .../music/settings/host/values/strings.xml | 2 - 4 files changed, 23 insertions(+), 69 deletions(-) rename src/main/kotlin/app/revanced/patches/music/flyoutpanel/{sleeptimer => component}/fingerprints/SleepTimerFingerprint.kt (74%) delete mode 100644 src/main/kotlin/app/revanced/patches/music/flyoutpanel/sleeptimer/SleepTimerPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt index 9cb73384a..2de72393a 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt @@ -1,12 +1,14 @@ package app.revanced.patches.music.flyoutpanel.component import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.music.flyoutpanel.component.fingerprints.SleepTimerFingerprint import app.revanced.patches.music.flyoutpanel.utils.EnumUtils.getEnumIndex import app.revanced.patches.music.utils.fingerprints.MenuItemFingerprint import app.revanced.patches.music.utils.flyoutbutton.FlyoutButtonContainerPatch @@ -46,7 +48,10 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction ) @Suppress("unused") object FlyoutPanelPatch : BytecodePatch( - setOf(MenuItemFingerprint) + setOf( + MenuItemFingerprint, + SleepTimerFingerprint + ) ) { override fun execute(context: BytecodeContext) { MenuItemFingerprint.result?.let { @@ -72,6 +77,22 @@ object FlyoutPanelPatch : BytecodePatch( } } ?: throw MenuItemFingerprint.exception + /** + * Forces sleep timer menu to be enabled. + * This method may be deperated in the future. + */ + SleepTimerFingerprint.result?.let { + it.mutableMethod.apply { + val insertIndex = implementation!!.instructions.size - 1 + val targetRegister = getInstruction(insertIndex).registerA + + addInstruction( + insertIndex, + "const/4 v$targetRegister, 0x1" + ) + } + } + SettingsPatch.addMusicPreferenceWithoutSummary( CategoryType.FLYOUT, "revanced_hide_flyout_panel_add_to_queue", diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/sleeptimer/fingerprints/SleepTimerFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/fingerprints/SleepTimerFingerprint.kt similarity index 74% rename from src/main/kotlin/app/revanced/patches/music/flyoutpanel/sleeptimer/fingerprints/SleepTimerFingerprint.kt rename to src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/fingerprints/SleepTimerFingerprint.kt index acf6f3b77..c33f80337 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/sleeptimer/fingerprints/SleepTimerFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/fingerprints/SleepTimerFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.music.flyoutpanel.sleeptimer.fingerprints +package app.revanced.patches.music.flyoutpanel.component.fingerprints import app.revanced.util.fingerprint.LiteralValueFingerprint diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/sleeptimer/SleepTimerPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/sleeptimer/SleepTimerPatch.kt deleted file mode 100644 index 88f860ae6..000000000 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/sleeptimer/SleepTimerPatch.kt +++ /dev/null @@ -1,65 +0,0 @@ -package app.revanced.patches.music.flyoutpanel.sleeptimer - -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructions -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.annotation.CompatiblePackage -import app.revanced.patcher.patch.annotation.Patch -import app.revanced.patches.music.flyoutpanel.sleeptimer.fingerprints.SleepTimerFingerprint -import app.revanced.patches.music.utils.integrations.Constants.FLYOUT -import app.revanced.patches.music.utils.settings.CategoryType -import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception -import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction - -@Patch( - name = "Enable sleep timer", - description = "Adds an option to add the sleep timer to the flyout menu.", - dependencies = [SettingsPatch::class], - compatiblePackages = [ - CompatiblePackage( - "com.google.android.apps.youtube.music", - [ - "6.21.52", - "6.22.52", - "6.23.56", - "6.25.53", - "6.26.51", - "6.27.54", - "6.28.53", - "6.29.58", - "6.31.55", - "6.33.52" - ] - ) - ] -) -@Suppress("unused") -object SleepTimerPatch : BytecodePatch( - setOf(SleepTimerFingerprint) -) { - override fun execute(context: BytecodeContext) { - - SleepTimerFingerprint.result?.let { - it.mutableMethod.apply { - val insertIndex = implementation!!.instructions.size - 1 - val targetRegister = getInstruction(insertIndex).registerA - - addInstructions( - insertIndex, """ - invoke-static {}, $FLYOUT->enableSleepTimer()Z - move-result v$targetRegister - """ - ) - } - } ?: throw SleepTimerFingerprint.exception - - SettingsPatch.addMusicPreference( - CategoryType.FLYOUT, - "revanced_enable_sleep_timer", - "true" - ) - - } -} \ No newline at end of file diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index b0c949a97..e6c932adc 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -69,8 +69,6 @@ WARNING: Do not enable "New player background" while this is enabled." Enable save playback speed Remembers the last video quality selected. Enable save video quality - Adds the sleep timer to the flyout menu. - Enable sleep timer Changes the player background to light grey to reduce eye strain. Enable zen mode Export settings to file