From 041adc981b714e514bc12748bf88d134b1308572 Mon Sep 17 00:00:00 2001 From: aliernfrog <45766489+aliernfrog@users.noreply.github.com> Date: Sun, 20 Nov 2022 16:24:41 +0300 Subject: [PATCH] feat(youtube): `disable-zoom-haptics` patch (#1079) --- .../annotations/ZoomHapticsCompatibility.kt | 9 ++++ .../fingerprints/ZoomHapticsFingerprint.kt | 9 ++++ .../zoomhaptics/patch/ZoomHapticsPatch.kt | 54 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/annotations/ZoomHapticsCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/fingerprints/ZoomHapticsFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/patch/ZoomHapticsPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/annotations/ZoomHapticsCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/annotations/ZoomHapticsCompatibility.kt new file mode 100644 index 00000000..86819cdd --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/annotations/ZoomHapticsCompatibility.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.youtube.misc.zoomhaptics.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("com.google.android.youtube")]) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class ZoomHapticsCompatibility \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/fingerprints/ZoomHapticsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/fingerprints/ZoomHapticsFingerprint.kt new file mode 100644 index 00000000..cc4c9d03 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/fingerprints/ZoomHapticsFingerprint.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.youtube.misc.zoomhaptics.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object ZoomHapticsFingerprint : MethodFingerprint( + strings = listOf( + "Failed to haptics vibrate for video zoom" + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/patch/ZoomHapticsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/patch/ZoomHapticsPatch.kt new file mode 100644 index 00000000..a10f59da --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/patch/ZoomHapticsPatch.kt @@ -0,0 +1,54 @@ +package app.revanced.patches.youtube.misc.zoomhaptics.patch + +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.extensions.addInstructions +import app.revanced.patcher.extensions.instruction +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.smali.ExternalLabel +import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource +import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference +import app.revanced.patches.youtube.misc.zoomhaptics.annotations.ZoomHapticsCompatibility +import app.revanced.patches.youtube.misc.zoomhaptics.fingerprints.ZoomHapticsFingerprint + +@Patch +@Name("disable-zoom-haptics") +@Description("Disables haptics when zooming.") +@DependsOn([SettingsPatch::class]) +@ZoomHapticsCompatibility +@Version("0.0.1") +class ZoomHapticsPatch : BytecodePatch( + listOf(ZoomHapticsFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + SettingsPatch.PreferenceScreen.MISC.addPreferences( + SwitchPreference( + "revanced_disable_zoom_haptics", + StringResource("revanced_disable_zoom_haptics_title", "Disable zoom haptics"), + true, + StringResource("revanced_disable_zoom_haptics_summary_on", "Haptics are disabled"), + StringResource("revanced_disable_zoom_haptics_summary_off", "Haptics are enabled") + ) + ) + + val zoomHapticsFingerprintMethod = ZoomHapticsFingerprint.result!!.mutableMethod + + zoomHapticsFingerprintMethod.addInstructions( + 0, """ + invoke-static { }, Lapp/revanced/integrations/patches/ZoomHapticsPatch;->shouldVibrate()Z + move-result v0 + if-nez v0, :vibrate + return-void + """, listOf(ExternalLabel("vibrate", zoomHapticsFingerprintMethod.instruction(0))) + ) + + return PatchResultSuccess() + } +} \ No newline at end of file