Skip to content

Commit 7e060c8

Browse files
committed
Fix invocation of ReaderModeManager
1. This class now has multiple interfaces 2. Its method `activateReaderMode` is easier to identify than `navigateToReaderMode`
1 parent 36593e4 commit 7e060c8

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

app/src/main/java/org/matrix/chromext/hook/PageMenu.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import android.widget.LinearLayout
1212
import de.robv.android.xposed.XC_MethodHook.Unhook
1313
import java.lang.reflect.Modifier
1414
import java.util.ArrayList
15+
import java.util.LinkedHashSet
1516
import org.matrix.chromext.Chrome
1617
import org.matrix.chromext.Listener
1718
import org.matrix.chromext.R
@@ -47,6 +48,19 @@ enum class AppMenuItemType(val value: Int) {
4748
NUM_ENTRIES(4)
4849
}
4950

51+
enum class EntryPoint(val value: Int) {
52+
UNKNOWN(0),
53+
54+
/** The user opened reader mode through an app message. */
55+
MESSAGE(1),
56+
57+
/** The user opened reader mode through the app menu. */
58+
APP_MENU(2),
59+
60+
/** The user opened reader mode through the toolbar button. */
61+
TOOLBAR_BUTTON(3),
62+
}
63+
5064
object readerMode {
5165
val ID = 31415926
5266

@@ -55,22 +69,22 @@ object readerMode {
5569
val observers = (PageMenuProxy.mObservers.get(Chrome.getTab()) as Iterable<Any>).toList()
5670
val readerModeManager =
5771
observers.find {
58-
it::class.java.interfaces.size == 1 &&
72+
findFieldOrNull(it::class.java) {
73+
type == LinkedHashSet::class.java && Modifier.isStatic(modifiers)
74+
} != null &&
5975
findFieldOrNull(it::class.java) { type == PageMenuProxy.propertyModel } != null
6076
}!!
6177

6278
readerModeManager::class
6379
.java
6480
.declaredMethods
65-
.filter {
66-
// There exist other methods with the same signatures,
67-
// which might be tryShowingPrompt
68-
it.parameterTypes.size == 0 &&
81+
.find {
82+
// public void activateReaderMode(@EntryPoint int entryPoint)
83+
it.parameterTypes contentEquals arrayOf(Int::class.java) &&
6984
!Modifier.isStatic(it.modifiers) &&
70-
it.returnType == Void.TYPE &&
71-
it.name != "destroy"
85+
it.returnType == Void.TYPE
7286
}
73-
.forEach { it.invoke(readerModeManager) }
87+
?.invoke(readerModeManager, EntryPoint.UNKNOWN.value)
7488
}
7589
}
7690

0 commit comments

Comments
 (0)