fix(extension): Prevent crashes related to extensions

Mostly to prevent "NetworkOnMainThreadException"
This commit is contained in:
Ahmad Ansori Palembani 2024-08-23 08:13:00 +07:00
parent ba7baba449
commit 4d2909340e
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
5 changed files with 10 additions and 6 deletions

View file

@ -10,4 +10,4 @@
## Other ?? Technical stuff, what happened behind the scene
-->
## Fixes
- Fixed custom cover set from reader didn't show up on manga details
- Fixed crashes caused by certain extension implementation

View file

@ -646,12 +646,13 @@ class Downloader(
) {
val categories =
db.getCategoriesForManga(manga).executeAsBlocking().map { it.name.trim() }.takeUnless { it.isEmpty() }
val urls = source.getChapterUrl(manga, chapter)?.let { listOf(it) } ?: listOf()
val url = try { source.getChapterUrl(chapter) } catch (_: Exception) { null }
?: source.getChapterUrl(manga, chapter).takeIf { !it.isNullOrBlank() } // FIXME: Not sure if this is necessary
val comicInfo = getComicInfo(
manga,
chapter,
urls,
url?.let { listOf(it) } ?: listOf(),
categories,
source.name,
source.lang,

View file

@ -308,7 +308,8 @@ class MangaDetailsPresenter(
fun getChapterUrl(chapter: Chapter): String? {
val source = source as? HttpSource ?: return null
val chapterUrl = try { source.getChapterUrl(chapter) } catch (_: Exception) { null }
return chapterUrl.takeIf { !it.isNullOrBlank() } ?: source.getChapterUrl(manga, chapter)
return chapterUrl.takeIf { !it.isNullOrBlank() }
?: try { source.getChapterUrl(manga, chapter) } catch (_: Exception) { null }
}
private fun getScrollType(chapters: List<ChapterItem>) {

View file

@ -682,7 +682,8 @@ class ReaderViewModel(
val source = getSource() ?: return null
val chapter = mainChapter ?: getCurrentChapter()?.chapter ?: return null
val chapterUrl = try { source.getChapterUrl(chapter) } catch (_: Exception) { null }
return chapterUrl.takeIf { !it.isNullOrBlank() } ?: source.getChapterUrl(manga, chapter)
return chapterUrl.takeIf { !it.isNullOrBlank() }
?: try { source.getChapterUrl(manga, chapter) } catch (_: Exception) { null }
}
fun getSource() = manga?.source?.let { sourceManager.getOrStub(it) } as? HttpSource

View file

@ -448,9 +448,10 @@ abstract class HttpSource : CatalogueSource {
* @return url of the chapter
*/
open fun getChapterUrl(chapter: SChapter): String {
return ""
return pageListRequest(chapter).url.toString()
}
// FIXME: Not sure if this is necessary, feels like this should be handled by the extension not by the app
fun getChapterUrl(manga: SManga?, chapter: SChapter): String? {
manga ?: return null