feat: glass effect toggle, media refresh timing fix, page transition perf
This commit is contained in:
@@ -4,6 +4,7 @@ import android.util.Log
|
||||
import top.yeij.hearth.app.AppRepository
|
||||
import top.yeij.hearth.card.Card
|
||||
import top.yeij.hearth.card.CardRepository
|
||||
import top.yeij.hearth.media.MediaInfo
|
||||
import top.yeij.hearth.media.MediaSessionSource
|
||||
import top.yeij.hearth.webapp.Tab
|
||||
import top.yeij.hearth.webapp.WebApp
|
||||
@@ -283,15 +284,27 @@ class JsBridge(
|
||||
|
||||
// 注册媒体会话监听,回调推送给 H5(info 为 null 时推 "null")
|
||||
// Register media session listener; push callbacks to H5 (push "null" when info is null)
|
||||
private var mediaSourceRef: MediaSessionSource? = null
|
||||
|
||||
fun setMediaListener(source: MediaSessionSource, webView: android.webkit.WebView) {
|
||||
source.start { info ->
|
||||
webView.post {
|
||||
val json = info?.toJson() ?: "null"
|
||||
webView.evaluateJavascript(
|
||||
"window.HearthEvents && window.HearthEvents.mediaSessionChanged($json);",
|
||||
null
|
||||
)
|
||||
}
|
||||
mediaSourceRef = source
|
||||
source.start { info -> pushMedia(info, webView) }
|
||||
}
|
||||
|
||||
// H5 页面就绪后重新拉取一次媒体:修复启动时推送早于页面渲染的时序问题
|
||||
// Re-pull media once the H5 page is ready: fixes the startup timing where the
|
||||
// push happens before the page has rendered
|
||||
fun refreshMedia() {
|
||||
mediaSourceRef?.refresh()
|
||||
}
|
||||
|
||||
private fun pushMedia(info: MediaInfo?, webView: android.webkit.WebView) {
|
||||
webView.post {
|
||||
val json = info?.toJson() ?: "null"
|
||||
webView.evaluateJavascript(
|
||||
"window.HearthEvents && window.HearthEvents.mediaSessionChanged($json);",
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user