blocklist return ai fix
This commit is contained in:
@@ -245,6 +245,39 @@ class VpnPlugin(private val activity: Activity) : Plugin(activity) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun updateBlocklistIfNeeded() {
|
||||
try {
|
||||
val cachePath = activity.cacheDir.absolutePath
|
||||
val hostsFile = File(cachePath, "hosts_cache.txt")
|
||||
|
||||
val isFresh = hostsFile.exists() &&
|
||||
(System.currentTimeMillis() - hostsFile.lastModified() < 24 * 60 * 60 * 1000)
|
||||
|
||||
if (isFresh) {
|
||||
Log.d(TAG, "DNS: Blocklist is fresh, skipping download")
|
||||
return
|
||||
}
|
||||
|
||||
Log.d(TAG, "DNS: Starting blocklist download via Kotlin...")
|
||||
|
||||
// Качаем
|
||||
val url = URL("https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts")
|
||||
val connection = url.openConnection()
|
||||
connection.connectTimeout = 15000
|
||||
connection.readTimeout = 15000
|
||||
|
||||
val bytes = connection.getInputStream().use { it.readBytes() }
|
||||
|
||||
// Сохраняем
|
||||
hostsFile.writeBytes(bytes)
|
||||
|
||||
Log.d(TAG, "DNS: Blocklist updated! Size: ${bytes.size} bytes")
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "DNS: Failed to download blocklist: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun load(webView: WebView) {
|
||||
super.load(webView)
|
||||
try { System.loadLibrary("netrunner_client") } catch (e: Exception) { Log.e(TAG, "Lib fail") }
|
||||
@@ -257,6 +290,9 @@ class VpnPlugin(private val activity: Activity) : Plugin(activity) {
|
||||
activity.registerReceiver(statusReceiver, filter)
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
updateBlocklistIfNeeded()
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
kotlinx.coroutines.delay(500)
|
||||
|
||||
Reference in New Issue
Block a user