mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 11:28:22 +00:00
Wire Coil ImageLoader to use OkHttpClient with proxy awareness
Adds OkHttpNetworkFetcherFactory with a custom Call.Factory that mirrors the same proxy selection logic used for relay connections: private IPs bypass the proxy unconditionally, all other URLs respect settings.useProxy. This ensures image fetches go through Tor/SOCKS when the user has it enabled. https://claude.ai/code/session_01Wmsp6FWziPs8X3NNK7bKJT
This commit is contained in:
@@ -23,6 +23,7 @@ import coil3.PlatformContext
|
||||
import coil3.SingletonImageLoader
|
||||
import coil3.disk.DiskCache
|
||||
import coil3.memory.MemoryCache
|
||||
import coil3.network.okhttp.OkHttpNetworkFetcherFactory
|
||||
import coil3.request.ErrorResult
|
||||
import coil3.request.ImageRequest
|
||||
import coil3.request.SuccessResult
|
||||
@@ -412,10 +413,16 @@ class Amber :
|
||||
.directory((context as Context).cacheDir.resolve("coil_image_cache").toOkioPath())
|
||||
.maxSizeBytes(10 * 1024 * 1024) // 10 MB
|
||||
.build()
|
||||
val coilCallFactory = okhttp3.Call.Factory { request ->
|
||||
val url = request.url.toString()
|
||||
val useProxy = if (isPrivateIp(url)) false else settings.useProxy
|
||||
HttpClientManager.getHttpClient(useProxy).newCall(request)
|
||||
}
|
||||
return ImageLoader.Builder(context)
|
||||
.memoryCache { memCache }
|
||||
.diskCache { diskCache }
|
||||
.crossfade(true)
|
||||
.components { add(OkHttpNetworkFetcherFactory(callFactory = { coilCallFactory })) }
|
||||
.eventListener(
|
||||
object : EventListener() {
|
||||
override fun onStart(request: ImageRequest) {
|
||||
|
||||
Reference in New Issue
Block a user