From ec49411bee9d7099e13685a02d54edabed863557 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 19 Feb 2023 11:48:26 -0500 Subject: [PATCH] Avoid crashes if headers can't be built for usage in WebView --- .../java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt | 7 ++++++- .../eu/kanade/tachiyomi/ui/webview/WebViewScreenModel.kt | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt index 12ae057141..773e63d313 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt @@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.toShareIntent import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.setComposeContent +import logcat.LogPriority import okhttp3.HttpUrl.Companion.toHttpUrl import tachiyomi.core.util.system.logcat import uy.kohesive.injekt.injectLazy @@ -47,7 +48,11 @@ class WebViewActivity : BaseActivity() { var headers = emptyMap() (sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource)?.let { source -> - headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" } + try { + headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" } + } catch (e: Exception) { + logcat(LogPriority.ERROR, e) { "Failed to build headers" } + } } setComposeContent { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewScreenModel.kt index a050560860..bd78fefc75 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewScreenModel.kt @@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.toShareIntent import eu.kanade.tachiyomi.util.system.toast +import logcat.LogPriority import okhttp3.HttpUrl.Companion.toHttpUrl import tachiyomi.core.util.system.logcat import uy.kohesive.injekt.Injekt @@ -25,7 +26,11 @@ class WebViewScreenModel( init { sourceId?.let { sourceManager.get(it) as? HttpSource }?.let { source -> - headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" } + try { + headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" } + } catch (e: Exception) { + logcat(LogPriority.ERROR, e) { "Failed to build headers" } + } } }