@@ -12,6 +12,7 @@ import android.widget.LinearLayout
1212import de.robv.android.xposed.XC_MethodHook.Unhook
1313import java.lang.reflect.Modifier
1414import java.util.ArrayList
15+ import java.util.LinkedHashSet
1516import org.matrix.chromext.Chrome
1617import org.matrix.chromext.Listener
1718import 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+
5064object 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