Skip to content

Commit 71db0a2

Browse files
abel1502LisoUseInAIKyriosoSumAtrIX
authored
feat(YouTube): Disable two-finger tap gesture for skipping chapters (#5374)
Co-authored-by: LisoUseInAIKyrios <[email protected]> Co-authored-by: oSumAtrIX <[email protected]>
1 parent 37112dc commit 71db0a2

File tree

6 files changed

+120
-0
lines changed

6 files changed

+120
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app.revanced.extension.youtube.patches;
2+
3+
import app.revanced.extension.youtube.settings.Settings;
4+
5+
@SuppressWarnings("unused")
6+
public final class DisableChapterSkipDoubleTapPatch {
7+
8+
/**
9+
* Injection point.
10+
*
11+
* @return If "should skip to chapter start" flag is set.
12+
*/
13+
public static boolean disableDoubleTapChapters(boolean original) {
14+
return original && !Settings.DISABLE_CHAPTER_SKIP_DOUBLE_TAP.get();
15+
}
16+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public class Settings extends BaseSettings {
146146
public static final BooleanSetting COPY_VIDEO_URL = new BooleanSetting("revanced_copy_video_url", FALSE);
147147
public static final BooleanSetting COPY_VIDEO_URL_TIMESTAMP = new BooleanSetting("revanced_copy_video_url_timestamp", TRUE);
148148
public static final BooleanSetting DISABLE_AUTO_CAPTIONS = new BooleanSetting("revanced_disable_auto_captions", FALSE, true);
149+
public static final BooleanSetting DISABLE_CHAPTER_SKIP_DOUBLE_TAP = new BooleanSetting("revanced_disable_chapter_skip_double_tap", FALSE);
149150
public static final BooleanSetting DISABLE_FULLSCREEN_AMBIENT_MODE = new BooleanSetting("revanced_disable_fullscreen_ambient_mode", TRUE, true);
150151
public static final BooleanSetting DISABLE_ROLLING_NUMBER_ANIMATIONS = new BooleanSetting("revanced_disable_rolling_number_animations", FALSE);
151152
public static final EnumSetting<FullscreenMode> EXIT_FULLSCREEN = new EnumSetting<>("revanced_exit_fullscreen", FullscreenMode.DISABLED);

patches/api/patches.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,10 @@ public final class app/revanced/patches/youtube/interaction/dialog/RemoveViewerD
12361236
public static final fun getRemoveViewerDiscretionDialogPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
12371237
}
12381238

1239+
public final class app/revanced/patches/youtube/interaction/doubletap/DisableChapterSkipDoubleTapPatchKt {
1240+
public static final fun getDisableChapterSkipDoubleTapPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
1241+
}
1242+
12391243
public final class app/revanced/patches/youtube/interaction/downloads/DownloadsPatchKt {
12401244
public static final fun getDownloadsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
12411245
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package app.revanced.patches.youtube.interaction.doubletap
2+
3+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
4+
import app.revanced.patcher.patch.bytecodePatch
5+
import app.revanced.patches.all.misc.resources.addResources
6+
import app.revanced.patches.all.misc.resources.addResourcesPatch
7+
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
8+
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
9+
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
10+
import app.revanced.patches.youtube.misc.settings.settingsPatch
11+
12+
private const val EXTENSION_CLASS_DESCRIPTOR =
13+
"Lapp/revanced/extension/youtube/patches/DisableChapterSkipDoubleTapPatch;"
14+
15+
@Suppress("unused")
16+
val disableChapterSkipDoubleTapPatch = bytecodePatch(
17+
name = "Disable double tap actions",
18+
description = "Adds an option to disable player double tap gestures.",
19+
) {
20+
dependsOn(
21+
sharedExtensionPatch,
22+
settingsPatch,
23+
addResourcesPatch,
24+
)
25+
26+
compatibleWith(
27+
"com.google.android.youtube"(
28+
"19.34.42",
29+
"19.43.41",
30+
"19.47.53",
31+
"20.07.39",
32+
"20.12.46",
33+
"20.13.41",
34+
)
35+
)
36+
37+
execute {
38+
addResources("youtube", "interaction.doubletap.disableChapterSkipDoubleTapPatch")
39+
40+
PreferenceScreen.PLAYER.addPreferences(
41+
SwitchPreference("revanced_disable_chapter_skip_double_tap"),
42+
)
43+
44+
// Force isChapterSeek flag to false.
45+
doubleTapInfoGetSeekSourceFingerprint.method.addInstructions(
46+
0,
47+
"""
48+
invoke-static { p1 }, $EXTENSION_CLASS_DESCRIPTOR->disableDoubleTapChapters(Z)Z
49+
move-result p1
50+
"""
51+
)
52+
53+
doubleTapInfoCtorFingerprint.match(
54+
doubleTapInfoGetSeekSourceFingerprint.classDef
55+
).method.addInstructions(
56+
0,
57+
"""
58+
invoke-static { p3 }, $EXTENSION_CLASS_DESCRIPTOR->disableDoubleTapChapters(Z)Z
59+
move-result p3
60+
"""
61+
)
62+
}
63+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package app.revanced.patches.youtube.interaction.doubletap
2+
3+
import app.revanced.patcher.fingerprint
4+
import com.android.tools.smali.dexlib2.AccessFlags
5+
import com.android.tools.smali.dexlib2.Opcode
6+
7+
internal val doubleTapInfoGetSeekSourceFingerprint = fingerprint {
8+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
9+
parameters("Z")
10+
returns("L") // Enum SeekSource, but name obfuscated.
11+
opcodes(
12+
Opcode.IF_EQZ,
13+
Opcode.SGET_OBJECT,
14+
Opcode.RETURN_OBJECT,
15+
Opcode.SGET_OBJECT,
16+
Opcode.RETURN_OBJECT,
17+
)
18+
custom { _, classDef ->
19+
classDef.fields.count() == 4
20+
}
21+
}
22+
23+
internal val doubleTapInfoCtorFingerprint = fingerprint {
24+
accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR)
25+
parameters(
26+
"Landroid/view/MotionEvent;",
27+
"I",
28+
"Z",
29+
"Lj\$/time/Duration;"
30+
)
31+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@ This feature is only available for older devices"</string>
516516
<string name="revanced_remove_viewer_discretion_dialog_summary_off">Dialog will be shown</string>
517517
<string name="revanced_remove_viewer_discretion_dialog_user_dialog_message">This does not bypass the age restriction. It just accepts it automatically.</string>
518518
</patch>
519+
<patch id="interaction.doubletap.disableChapterSkipDoubleTapPatch">
520+
<string name="revanced_disable_chapter_skip_double_tap_title">Disable double tap chapter skip</string>
521+
<string name="revanced_disable_chapter_skip_double_tap_summary_on">Double tap can never trigger a skip to the next/previous chapter</string>
522+
<string name="revanced_disable_chapter_skip_double_tap_summary_off">Double tap can occasionally trigger a skip to the next/previous chapter</string>
523+
</patch>
519524
<patch id="interaction.downloads.downloadsResourcePatch">
520525
<string name="revanced_external_downloader_screen_title">External downloads</string>
521526
<string name="revanced_external_downloader_screen_summary">Settings for using an external downloader</string>

0 commit comments

Comments
 (0)