Avoid crashing when clearing cookies for invalid source URLs

e.g. Komga sources with no URLs set

(cherry picked from commit b6d6de6b9f80798c5b363f7e361de073db4a6d55)
This commit is contained in:
arkon 2022-12-05 22:18:19 -05:00 committed by Jobobby04
parent a280a5ed77
commit d59ec04812

View File

@ -115,11 +115,16 @@ class ExtensionDetailsScreenModel(
val urls = extension.sources
.filterIsInstance<HttpSource>()
.map { it.baseUrl }
.mapNotNull { it.baseUrl.takeUnless { url -> url.isEmpty() } }
.distinct()
val cleared = urls.sumOf {
network.cookieManager.remove(it.toHttpUrl())
try {
network.cookieManager.remove(it.toHttpUrl())
} catch (e: Exception) {
logcat(LogPriority.ERROR, e) { "Failed to clear cookies for $it" }
0
}
}
logcat { "Cleared $cleared cookies for: ${urls.joinToString()}" }