Skip to content

Commit

Permalink
Test if current url is a chrome scheme
Browse files Browse the repository at this point in the history
Avoid showing the eruda menu for empty tabs
  • Loading branch information
JingMatrix committed Nov 13, 2023
1 parent 7866119 commit a958799
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/org/matrix/chromext/hook/PageInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ object PageInfoHook : BaseHook() {
controller!!.invokeMethod() { name == "destroy" }
}
}
Log.d("${infoRow}")
return infoRow
}

proxy.pageInfoControllerRef.declaredConstructors[0].hookAfter { controller = it.thisObject }

proxy.pageInfoController.declaredConstructors[0].hookAfter {
val url = Chrome.getUrl()!!
if (controller == null) return@hookAfter
if (isChromeScheme(url) || controller == null) return@hookAfter
(proxy.mRowWrapper.get(proxy.mView.get(it.thisObject)) as LinearLayout).addView(
addErudaRow(url))
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/matrix/chromext/hook/PageMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ object PageMenuHook : BaseHook() {
mId.setAccessible(false)
}

val skip = menu.size() <= 20
val skip = menu.size() <= 20 || isChromeScheme(url)
// Inflate only for the main_menu, which has more than 20 items at least

if (skip && !isUserScript(url)) return@inflate
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/org/matrix/chromext/utils/Url.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,9 @@ fun parseOrigin(url: String): String? {
return null
}
}

fun isChromeScheme(url: String): Boolean {
val protocol = url.split("://")
return (protocol.size > 1 &&
arrayOf("chrome", "chrome-native", "edge").contains(protocol.first()))
}

0 comments on commit a958799

Please sign in to comment.