fix: per-app scale via CSS zoom, hide download icon when local version matches

This commit is contained in:
2026-08-17 21:40:06 +08:00
parent 0194a57734
commit 06377f067f
3 changed files with 37 additions and 20 deletions
@@ -278,6 +278,22 @@ class MainActivity : Activity() {
}
val webView = WebViewManager(this@MainActivity).createContentWebView(ua, scale)
webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
Log.d(TAG, "content onPageFinished: url=$url scale=$scale")
// 缩放:网易云 PC 版不响应 viewport meta 的 initial-scale
// 改用 CSS zoom(会 reflow,内容填满不留白),对任何页面可靠生效
// Zoom: desktop pages (e.g. NetEase Music) ignore viewport-meta
// initial-scale, so use CSS zoom (reflows, no blank space), which
// works reliably on any page
if (scale != null && scale in 1..100) {
val zoom = scale / 100f
view?.evaluateJavascript(
"(function(){var z='$zoom';var s=document.createElement('style');s.innerHTML='html{zoom:'+z+'}';document.head.appendChild(s);})();",
null
)
}
}
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
override fun onReceivedError(
view: WebView?,
@@ -43,18 +43,10 @@ class WebViewManager(private val activity: Activity) {
ua == "desktop" || ua == "pc" -> UA_DESKTOP
else -> ua
}
// 缩放(1-100):View 级别 scaleX/scaleY,不依赖页面渲染或 viewport,对任何页面可靠生效。
// 缩放后内容相对左上角缩小;触摸坐标由 View 自动映射
// Zoom (1-100): view-level scaleX/scaleY, independent of page rendering or
// viewport, so it reliably works for any page. Content shrinks toward the
// top-left; touch coordinates are auto-mapped by the View
if (scale != null && scale in 1..100) {
val s = scale / 100f
webView.scaleX = s
webView.scaleY = s
webView.pivotX = 0f
webView.pivotY = 0f
}
// scale 由 WebAppHost 在 onPageFinished 里通过 CSS zoom 实现(reflow 缩放),
// 此处不再做 View 级别缩放
// scale is applied by WebAppHost via CSS zoom in onPageFinished (reflow
// scaling); no view-level scaling here
return webView
}