feat: hide foreground webapp when switching sidebar pages
This commit is contained in:
@@ -24,6 +24,15 @@ const router = {
|
||||
this.current = id;
|
||||
document.querySelectorAll('[data-page]').forEach(el =>
|
||||
el.classList.toggle('active', el.dataset.page === id));
|
||||
// 切页时把前台 webapp 丢到后台(隐藏内容 WebView,标签状态保留)
|
||||
// Hide the foreground webapp when switching pages (keep tab state)
|
||||
bridge.call('hideWebApps').catch(() => {});
|
||||
// 同时隐藏 webapp 顶栏与标签面板(离开 webapp 场景)
|
||||
// Also hide the webapp topbar and tab panel (leaving the webapp context)
|
||||
const topbar = document.getElementById('web-topbar');
|
||||
if (topbar) topbar.style.display = 'none';
|
||||
const tabPanel = document.getElementById('tab-panel');
|
||||
if (tabPanel) tabPanel.style.display = 'none';
|
||||
// 非首页时侧边栏顶部显示小时间(容器始终占位,仅切换可见性避免撑动图标)
|
||||
// Show the small clock at the sidebar top when not on home (the container
|
||||
// always occupies space; only toggle visibility to avoid shifting icons)
|
||||
|
||||
@@ -293,6 +293,12 @@ class MainActivity : Activity() {
|
||||
Log.d(TAG, "switchWebView: id=$id")
|
||||
}
|
||||
|
||||
override fun hideAll() {
|
||||
contentWebViews.values.forEach { it.visibility = View.GONE }
|
||||
currentVisibleId = null
|
||||
Log.d(TAG, "hideAll: hidden ${contentWebViews.size} webviews")
|
||||
}
|
||||
|
||||
override fun goBack(): Boolean {
|
||||
val webView = currentVisibleId?.let { contentWebViews[it] }
|
||||
return if (webView != null && webView.canGoBack()) {
|
||||
|
||||
@@ -202,6 +202,16 @@ class JsBridge(
|
||||
Log.d("HearthBridge", "webReload called")
|
||||
}
|
||||
|
||||
// 隐藏所有内容 WebView(把前台 webapp 丢到后台,标签状态保留)
|
||||
// Hide all content WebViews (send the foreground webapp to background,
|
||||
// keeping the tab state) — called when the user switches pages via the sidebar
|
||||
@android.webkit.JavascriptInterface
|
||||
fun hideWebApps() {
|
||||
val host = webAppHost ?: return
|
||||
onMain { host.hideAll() }
|
||||
Log.d("HearthBridge", "hideWebApps called")
|
||||
}
|
||||
|
||||
// 清单内存缓存:首次拉取成功后缓存,后续复用(避免 openWebApp 重复 I/O)
|
||||
// 空结果(离线失败)不缓存,下次调用重试拉取,避免空清单被永久缓存
|
||||
// In-memory manifest cache: cache only on a successful non-empty fetch (avoid
|
||||
|
||||
@@ -35,4 +35,9 @@ interface WebAppHost {
|
||||
// 将标签状态推送到桌面 H5 顶栏
|
||||
// Push the tab state to the desktop H5 topbar
|
||||
fun syncTabs(tabs: List<Tab>)
|
||||
|
||||
// 隐藏所有内容 WebView(把前台 webapp 丢到后台,标签状态保留)
|
||||
// Hide all content WebViews (send the foreground webapp to background,
|
||||
// keeping the tab state)
|
||||
fun hideAll()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user