fix: marshal js bridge view ops to main thread
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user