forked from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube):
disable-zoom-haptics
patch (ReVanced#1079)
- Loading branch information
1 parent
ee461a5
commit a7cfba5
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...lin/app/revanced/patches/youtube/misc/zoomhaptics/annotations/ZoomHapticsCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
9 changes: 9 additions & 0 deletions
9
...tlin/app/revanced/patches/youtube/misc/zoomhaptics/fingerprints/ZoomHapticsFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
) | ||
) |
54 changes: 54 additions & 0 deletions
54
src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/patch/ZoomHapticsPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |