From 425e48bec6edf6ea30d13dc8d46b79899122c61b Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 8 Jan 2023 10:17:50 -0500 Subject: [PATCH] Avoid crashes when opening WebView from reader Also ensure WebViewActivity has an Assistant URL when it first opens with a URL. --- .../eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt | 11 +++++++---- .../eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index d47f0d0e55..5be20f21dc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -67,6 +67,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.util.Constants +import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchNonCancellable import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.preference.toggle @@ -716,10 +717,12 @@ class ReaderActivity : BaseActivity() { private fun openChapterInWebview() { val manga = viewModel.manga ?: return val source = viewModel.getSource() ?: return - val url = viewModel.getChapterUrl() ?: return - - val intent = WebViewActivity.newIntent(this, url, source.id, manga.title) - startActivity(intent) + lifecycleScope.launchIO { + viewModel.getChapterUrl()?.let { url -> + val intent = WebViewActivity.newIntent(this@ReaderActivity, url, source.id, manga.title) + withUIContext { startActivity(intent) } + } + } } private fun showReadingModeToast(mode: Int) { 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 6ccfebb209..41e64846cd 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 @@ -42,10 +42,11 @@ class WebViewActivity : BaseActivity() { return } - val url = intent.extras!!.getString(URL_KEY) ?: return + val url = intent.extras?.getString(URL_KEY) ?: return + assistUrl = url + var headers = mutableMapOf() - val source = sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource - if (source != null) { + (sourceManager.get(intent.extras!!.getLong(SOURCE_KEY)) as? HttpSource)?.let { source -> headers = source.headers.toMultimap().mapValues { it.value.getOrNull(0) ?: "" }.toMutableMap() }