Skip to content

Commit

Permalink
Fix ReaderMode for chrome v114
Browse files Browse the repository at this point in the history
EmptyTabObserver could be an abstract class
  • Loading branch information
JingMatrix committed Jun 3, 2023
1 parent 72959fd commit 788802f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/build
.gradle
smali
apktool
27 changes: 17 additions & 10 deletions app/src/main/java/org/matrix/chromext/hook/Menu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object readerMode {
val mDistillerUrl =
readerModeManager!!.getDeclaredFields().filter { it.type == UserScriptProxy.gURL }.last()!!
val activateReaderMode =
// This is purely luck, there are other methods with the same signatures
// There exist other methods with the same signatures
findMethod(readerModeManager!!) {
getParameterTypes().size == 0 && getReturnType() == Void.TYPE
}
Expand Down Expand Up @@ -97,7 +97,7 @@ object MenuHook : BaseHook() {
pageInfoController!!.invokeMethod() { name == "destroy" }
}
}
(proxy.mRowWrapper.get(it.thisObject) as LinearLayout).addView(erudaRow)
(proxy.mRowWrapper!!.get(it.thisObject) as LinearLayout).addView(erudaRow)
}
}

Expand Down Expand Up @@ -226,14 +226,21 @@ object MenuHook : BaseHook() {

var findReaderHook: Unhook? = null
findReaderHook =
proxy.emptyTabObserver.getDeclaredConstructors()[0].hookAfter {
val subType = it.thisObject::class.java
if (subType.getInterfaces().size == 1 &&
subType.getDeclaredFields().find { it.getType() == proxy.propertyModel } != null) {
readerMode.init(subType)
findReaderHook!!.unhook()
}
}
findMethod(proxy.tabImpl) {
getParameterTypes() contentDeepEquals arrayOf(proxy.emptyTabObserver) &&
getReturnType() == Void.TYPE
// There exist other methods with the same signatures
}
// public void addObserver(TabObserver observer)
.hookAfter {
val subType = it.args[0]::class.java
if (subType.getInterfaces().size == 1 &&
subType.getDeclaredFields().find { it.getType() == proxy.propertyModel } !=
null) {
readerMode.init(subType)
findReaderHook!!.unhook()
}
}
}

// var findSwipeRefreshHandler: Unhook? = null
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/matrix/chromext/proxy/Menu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object MenuProxy {
.find { it.type.getSuperclass() == FrameLayout::class.java }!!
.type
}
val mRowWrapper = pageInfoView.getDeclaredFields().find { it.type == LinearLayout::class.java }!!
val mRowWrapper = pageInfoView.getDeclaredFields().find { it.type == LinearLayout::class.java }
val pageInfoControllerRef =
// A particular WebContentsObserver designed for PageInfoController
pageInfoController
Expand All @@ -59,6 +59,7 @@ object MenuProxy {
val emptyTabObserver =
Chrome.load("org.chromium.chrome.browser.login.ChromeHttpAuthHandler").getSuperclass()
as Class<*>
val tabImpl = Chrome.load("org.chromium.chrome.browser.tab.TabImpl")

private val preference = Chrome.load("androidx.preference.Preference")
private val mClickListener =
Expand Down

0 comments on commit 788802f

Please sign in to comment.