fix: marshal js bridge view ops to main thread

This commit is contained in:
2026-08-16 17:21:02 +08:00
parent 6ca55dbe5f
commit a0f8873b7a
5 changed files with 126 additions and 45 deletions
@@ -86,6 +86,7 @@ class MainActivity : Activity() {
cardRepository = CardRepository(http, cache, CATALOG_URL),
webAppContainer = webAppContainer,
webAppHost = webAppHost,
postToMainThread = { desktopWebView.post(it) },
)
root = FrameLayout(this)
setContentView(root)
@@ -195,15 +196,15 @@ class MainActivity : Activity() {
}
override fun syncTabs(tabs: List<Tab>) {
// JsBridge 已把该调用 marshal 到主线程,这里可直接 evaluateJavascript
// JsBridge already marshaled this call to the main thread, so evaluateJavascript is safe
val json = gson.toJson(
tabs.map { mapOf("id" to it.id, "name" to it.name, "active" to it.active) }
)
desktopWebView.post {
desktopWebView.evaluateJavascript(
"window.showTopbar && window.showTopbar($json);",
null
)
}
desktopWebView.evaluateJavascript(
"window.showTopbar && window.showTopbar($json);",
null
)
Log.d(TAG, "syncTabs: ${tabs.size} tabs")
}