feat: h5 webapp list page with rich cards
This commit is contained in:
@@ -4,8 +4,16 @@ import com.google.gson.Gson
|
||||
import top.yeij.hearth.cache.CacheManager
|
||||
|
||||
// Web 应用清单条目
|
||||
// offline 为离线包路径,null 表示纯在线应用
|
||||
// Web app manifest entry
|
||||
data class WebApp(val id: String, val name: String, val icon: String, val url: String)
|
||||
// offline is the offline package path, null means online-only
|
||||
data class WebApp(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val icon: String,
|
||||
val url: String,
|
||||
val offline: String? = null,
|
||||
)
|
||||
|
||||
// 网络抽象接口:Task 10 的 CardRepository 也会复用
|
||||
// HTTP abstraction reused by Task 10 CardRepository
|
||||
@@ -41,7 +49,10 @@ class WebAppRepository(
|
||||
val name = map["name"] as? String ?: return@mapNotNull null
|
||||
val icon = map["icon"] as? String ?: return@mapNotNull null
|
||||
val url = map["url"] as? String ?: return@mapNotNull null
|
||||
WebApp(id, name, icon, url)
|
||||
// offline 是对象时取其 package 字段,否则 null(纯在线)
|
||||
// offline is an object -> take its package field, otherwise null (online-only)
|
||||
val offline = (map["offline"] as? Map<*, *>)?.get("package") as? String
|
||||
WebApp(id, name, icon, url, offline)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package top.yeij.hearth.webview
|
||||
|
||||
import android.util.Log
|
||||
import top.yeij.hearth.app.AppRepository
|
||||
import top.yeij.hearth.webapp.WebApp
|
||||
import top.yeij.hearth.webapp.WebAppRepository
|
||||
|
||||
class JsBridge(
|
||||
private val deviceWidthPx: Int,
|
||||
@@ -9,6 +11,7 @@ class JsBridge(
|
||||
private val density: Float,
|
||||
private val darkMode: Boolean,
|
||||
private val appRepository: AppRepository? = null,
|
||||
private val webAppRepository: WebAppRepository? = null,
|
||||
) {
|
||||
private val gson = com.google.gson.Gson()
|
||||
|
||||
@@ -34,4 +37,9 @@ class JsBridge(
|
||||
// Launch an app by package name, true on success (false when no repository wired)
|
||||
@android.webkit.JavascriptInterface
|
||||
fun launchApp(packageName: String): Boolean = appRepository?.launchApp(packageName) ?: false
|
||||
|
||||
// 返回 H5 应用清单 JSON(无仓库时返回空数组)
|
||||
// Return the H5 web app manifest JSON (empty array when no repository wired)
|
||||
@android.webkit.JavascriptInterface
|
||||
fun fetchWebApps(): String = gson.toJson(webAppRepository?.fetchManifest() ?: emptyList<WebApp>())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user