Refactor H5 line management and cache handling in WebView app

- Introduced shared_preferences for initial H5 cache management.
- Added methods to clear H5 caches and probe line availability.
- Enhanced error handling for line loading and switching.
- Removed openim_common package and its configurations.
- Updated widget tests to reflect changes in H5 line handling and URL management.
This commit is contained in:
Booker
2026-05-29 17:56:55 +07:00
parent 131df57dfe
commit a1e7b3e52c
11 changed files with 881 additions and 288 deletions

View File

@@ -16,6 +16,9 @@ import android.util.Base64
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.webkit.CookieManager
import android.webkit.WebStorage
import android.webkit.WebView
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.core.content.FileProvider
@@ -31,6 +34,7 @@ class MainActivity : FlutterActivity() {
private val CHANNEL = "io.openim.flutter.openim/apk_info"
private val SHELL_BRANDING_CHANNEL = "io.openim.flutter.im_webview_app/shell_branding"
private val FILE_PICKER_CHANNEL = "io.openim.flutter.openim/file_picker"
private val H5_CACHE_CHANNEL = "io.openim.flutter.im_webview_app/h5_cache"
private val TAG = "MainActivity"
private val MAX_BRANDING_ICON_SIZE = 192
private val FILE_PICKER_REQUEST_CODE = 4201
@@ -144,6 +148,36 @@ class MainActivity : FlutterActivity() {
}
}
}
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, H5_CACHE_CHANNEL).setMethodCallHandler { call, result ->
when (call.method) {
"clearAllWebsiteData" -> {
try {
clearAllH5WebsiteData()
result.success(true)
} catch (e: Exception) {
result.error("CLEAR_H5_CACHE_FAILED", e.message, null)
}
}
else -> {
result.notImplemented()
}
}
}
}
private fun clearAllH5WebsiteData() {
WebStorage.getInstance().deleteAllData()
CookieManager.getInstance().removeAllCookies(null)
CookieManager.getInstance().flush()
val webView = WebView(this)
try {
webView.clearCache(true)
webView.clearHistory()
webView.clearFormData()
} finally {
webView.destroy()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {