feat: bundle demo webapp in apk
This commit is contained in:
@@ -44,15 +44,37 @@ class WebAppRepository(
|
||||
// 先解析、成功才缓存,避免畸形 body 或空结果被永久缓存
|
||||
// Parse first, cache only on success (never cache malformed/empty bodies)
|
||||
val apps = parse(body)
|
||||
if (apps != null) {
|
||||
if (apps != null && apps.isNotEmpty()) {
|
||||
cache.save(KEY, body)
|
||||
return apps
|
||||
}
|
||||
Log.w(TAG, "fetchManifest: invalid body, not cached")
|
||||
return emptyList()
|
||||
Log.w(TAG, "fetchManifest: invalid/empty body, not cached")
|
||||
return builtinWebApps()
|
||||
}
|
||||
val cached = cache.load(KEY) ?: return emptyList()
|
||||
return parse(cached) ?: emptyList()
|
||||
val cached = cache.load(KEY)
|
||||
if (cached != null) {
|
||||
val apps = parse(cached)
|
||||
if (apps != null && apps.isNotEmpty()) return apps
|
||||
}
|
||||
// 无远程清单:返回内置示例 webapp,保证列表不为空、可演示
|
||||
// No remote manifest: return the builtin demo webapp so the list is non-empty
|
||||
return builtinWebApps()
|
||||
}
|
||||
|
||||
// 内置示例 webapp(打包在 assets 内,无需服务器)
|
||||
// Builtin demo webapp (bundled in assets, no server required)
|
||||
private fun builtinWebApps(): List<WebApp> {
|
||||
return listOf(
|
||||
WebApp(
|
||||
id = "demo",
|
||||
name = "示例应用",
|
||||
icon = "data:image/svg+xml;utf8," +
|
||||
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'>" +
|
||||
"<rect width='24' height='24' rx='6' fill='%23ff6900'/>" +
|
||||
"<text x='12' y='17' font-size='13' text-anchor='middle' fill='white'>H</text></svg>",
|
||||
url = "file:///android_asset/webapps/demo/index.html",
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// 解析清单 JSON;畸形 JSON 或缺少 apps 字段返回 null(调用方决定回退)
|
||||
|
||||
Reference in New Issue
Block a user