优化滚动条

This commit is contained in:
fengge 2026-07-08 16:28:58 +08:00
parent 8fe4a28f4c
commit b451e694f4
1 changed files with 25 additions and 4 deletions

View File

@ -275,10 +275,31 @@ class MainActivity : AppCompatActivity() {
} }
private fun createGeckoRuntime(): GeckoRuntime { private fun createGeckoRuntime(): GeckoRuntime {
val runtime = GeckoRuntime.getDefault(this) // 1. 将配置写入应用的本地沙盒文件 (YAML 格式)
runtime.settings.aboutConfigEnabled = true val configFile = java.io.File(filesDir, "geckoview-config.yaml")
runtime.settings.consoleOutputEnabled = true try {
// 强制清缓存,确保 JS/CSS 等资源获取最新版本 val configContent = """
prefs:
layout.testing.overlay-scrollbars.always-visible: true
""".trimIndent()
configFile.writeText(configContent)
Timber.tag("MainActivity").d("Wrote GeckoView config to: ${configFile.absolutePath}")
} catch (e: Exception) {
Timber.tag("MainActivity").e(e, "Failed to write geckoview-config.yaml")
}
// 2. 通过 GeckoRuntimeSettings.Builder 加载该 YAML 配置文件并创建 GeckoRuntime 实例
val settingsBuilder = org.mozilla.geckoview.GeckoRuntimeSettings.Builder()
.aboutConfigEnabled(true)
.consoleOutput(true)
if (configFile.exists()) {
settingsBuilder.configFilePath(configFile.absolutePath)
}
val runtime = GeckoRuntime.create(this, settingsBuilder.build())
// 3. 强制清缓存,确保 JS/CSS 等资源获取最新版本
try { try {
// runtime.storageController.clearData(ClearFlags.ALL) // runtime.storageController.clearData(ClearFlags.ALL)
Timber.tag("MainActivity").i("GeckoView cache cleared") Timber.tag("MainActivity").i("GeckoView cache cleared")