Skip to content

Commit 6f92b6c

Browse files
fix(YouTube - Settings): Handle on screen back swipe gesture (#6002)
1 parent 1e023fa commit 6f92b6c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static void updateLightDarkModeStatus(Enum<?> value) {
152152
* @return if the original activity finish method should be allowed to run.
153153
*/
154154
@SuppressWarnings("unused")
155-
public static boolean handleFinish() {
155+
public static boolean handleBackPress() {
156156
return YouTubeSearchViewController.handleFinish(searchViewController);
157157
}
158158
}

patches/src/main/kotlin/app/revanced/patches/music/misc/settings/SettingsPatch.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ val settingsPatch = bytecodePatch(
108108
modifyActivityForSettingsInjection(
109109
googleApiActivityFingerprint.classDef,
110110
googleApiActivityFingerprint.method,
111-
GOOGLE_API_ACTIVITY_HOOK_CLASS_DESCRIPTOR
111+
GOOGLE_API_ACTIVITY_HOOK_CLASS_DESCRIPTOR,
112+
true
112113
)
113114
}
114115

patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsPatch.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ val settingsPatch = bytecodePatch(
218218
modifyActivityForSettingsInjection(
219219
licenseActivityOnCreateFingerprint.classDef,
220220
licenseActivityOnCreateFingerprint.method,
221-
YOUTUBE_ACTIVITY_HOOK_CLASS_DESCRIPTOR
221+
YOUTUBE_ACTIVITY_HOOK_CLASS_DESCRIPTOR,
222+
false
222223
)
223224
}
224225

@@ -233,7 +234,8 @@ val settingsPatch = bytecodePatch(
233234
internal fun modifyActivityForSettingsInjection(
234235
activityOnCreateClass: MutableClass,
235236
activityOnCreateMethod: MutableMethod,
236-
extensionClassType: String
237+
extensionClassType: String,
238+
isYouTubeMusic: Boolean
237239
) {
238240
// Modify Activity and remove all existing layout code.
239241
// Must modify an existing activity and cannot add a new activity to the manifest,
@@ -275,21 +277,24 @@ internal fun modifyActivityForSettingsInjection(
275277
// Override finish() to intercept back gesture.
276278
ImmutableMethod(
277279
activityOnCreateClass.type,
278-
"finish",
280+
if (isYouTubeMusic) "finish" else "onBackPressed",
279281
emptyList(),
280282
"V",
281283
AccessFlags.PUBLIC.value,
282284
null,
283285
null,
284286
MutableMethodImplementation(3),
285287
).toMutable().apply {
288+
// Slightly different hooks are needed, otherwise the back button can behave wrong.
289+
val extensionMethodName = if (isYouTubeMusic) "handleFinish" else "handleBackPress"
290+
val invokeFinishOpcode = if (isYouTubeMusic) "invoke-super" else "invoke-virtual"
291+
286292
addInstructions(
287293
"""
288-
invoke-static {}, $extensionClassType->handleFinish()Z
294+
invoke-static {}, $extensionClassType->$extensionMethodName()Z
289295
move-result v0
290296
if-nez v0, :search_handled
291-
invoke-super { p0 }, Landroid/app/Activity;->finish()V
292-
return-void
297+
$invokeFinishOpcode { p0 }, Landroid/app/Activity;->finish()V
293298
:search_handled
294299
return-void
295300
"""

0 commit comments

Comments
 (0)