1+ package com.wizpizz.onepluspluslauncher.hook.features
2+
3+ import android.util.Log
4+ import com.highcapable.yukihookapi.hook.param.PackageParam
5+ import com.highcapable.yukihookapi.hook.factory.current
6+ import com.highcapable.yukihookapi.hook.factory.field
7+ import com.highcapable.yukihookapi.hook.factory.method
8+ import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_LEFT_SWIPE_DISCOVER_REDIRECT
9+ import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.PREF_AUTO_FOCUS_LEFT_SWIPE_REDIRECT
10+ import com.wizpizz.onepluspluslauncher.hook.features.HookUtils.TAG
11+
12+ /* *
13+ * Intercepts the left-swipe (Discover/Feed/News) overlay and opens the app drawer instead.
14+ * Hooks OplusLauncherOverlay.onScrollInteractionBegin().
15+ *
16+ * Features:
17+ * - Toggle to enable/disable the redirect
18+ * - Optional auto-focus on search input when redirecting
19+ */
20+ object LeftSwipeDiscoverRedirectHook {
21+ private const val OPLUS_LAUNCHER_OVERLAY_CLASS = " com.android.overlay.OplusLauncherOverlay"
22+
23+ fun apply (packageParam : PackageParam ) {
24+ packageParam.apply {
25+ OPLUS_LAUNCHER_OVERLAY_CLASS .toClassOrNull(appClassLoader)?.method {
26+ name = " onScrollInteractionBegin"
27+ paramCount = 0
28+ }?.hook {
29+ before {
30+ // Check if left-swipe redirect is enabled
31+ val leftSwipeRedirectEnabled = prefs.getBoolean(PREF_LEFT_SWIPE_DISCOVER_REDIRECT , true )
32+ if (! leftSwipeRedirectEnabled) {
33+ Log .d(TAG , " [LeftSwipe] Feature disabled, allowing original behavior" )
34+ return @before
35+ }
36+
37+ Log .d(TAG , " [LeftSwipe] Intercepting left-swipe overlay, redirecting to app drawer" )
38+
39+ // Mark that we're starting a redirect to prevent AutoFocusHook from triggering
40+ HookUtils .setRedirectInProgress(true )
41+
42+ // Get the Launcher instance from the overlay
43+ val launcher = instance.javaClass.field {
44+ name = " mLauncher"
45+ superClass(true )
46+ }.get(instance).any()
47+
48+ if (launcher != null ) {
49+ try {
50+ // Try to call showAllAppsFromIntent(true) on the launcher
51+ launcher.current().method {
52+ name = " showAllAppsFromIntent"
53+ param(Boolean ::class .java)
54+ }.call(true )
55+ Log .d(TAG , " [LeftSwipe] Successfully opened app drawer from left swipe" )
56+
57+ // If redirect was successful and auto focus on redirect is enabled, focus search
58+ val autoFocusRedirectEnabled = prefs.getBoolean(PREF_AUTO_FOCUS_LEFT_SWIPE_REDIRECT , true )
59+ if (autoFocusRedirectEnabled) {
60+ Log .d(TAG , " [LeftSwipe] Auto focus enabled, focusing search input" )
61+ appClassLoader?.let { HookUtils .focusSearchInput(launcher, it) }
62+ // Clear redirect flag after focusing
63+ HookUtils .setRedirectInProgress(false )
64+ } else {
65+ Log .d(TAG , " [LeftSwipe] Auto focus disabled, clearing redirect flag" )
66+ // Clear redirect flag immediately if not focusing
67+ HookUtils .setRedirectInProgress(false )
68+ }
69+
70+ } catch (e: Throwable ) {
71+ Log .e(TAG , " [LeftSwipe] Failed to open app drawer: ${e.message} " )
72+ // Reset flag if redirect failed
73+ HookUtils .setRedirectInProgress(false )
74+ }
75+ } else {
76+ Log .e(TAG , " [LeftSwipe] Failed to get launcher instance from overlay" )
77+ // Reset flag if we couldn't get launcher
78+ HookUtils .setRedirectInProgress(false )
79+ }
80+
81+ // Prevent the overlay from opening
82+ result = null
83+ return @before
84+ }
85+ } ? : Log .e(TAG , " [LeftSwipe] Failed to find OplusLauncherOverlay.onScrollInteractionBegin method" )
86+ }
87+ }
88+ }
0 commit comments