瀏覽代碼

Avoid crash during migration

arkon 4 年之前
父節點
當前提交
f51e32f39b
共有 1 個文件被更改,包括 10 次插入4 次删除
  1. 10 4
      app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt

+ 10 - 4
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt

@@ -17,6 +17,8 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter
 import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
 import eu.kanade.tachiyomi.util.lang.launchIO
 import eu.kanade.tachiyomi.util.lang.launchUI
+import eu.kanade.tachiyomi.util.lang.withUIContext
+import eu.kanade.tachiyomi.util.system.toast
 import java.util.Date
 
 class SearchPresenter(
@@ -56,11 +58,15 @@ class SearchPresenter(
         replacingMangaRelay.call(true)
 
         presenterScope.launchIO {
-            val chapters = source.getChapterList(manga.toMangaInfo())
-                .map { it.toSChapter() }
+            try {
+                val chapters = source.getChapterList(manga.toMangaInfo())
+                    .map { it.toSChapter() }
+
+                migrateMangaInternal(source, chapters, prevManga, manga, replace)
+            } catch (e: Throwable) {
+                withUIContext { view?.applicationContext?.toast(e.message) }
+            }
 
-            migrateMangaInternal(source, chapters, prevManga, manga, replace)
-        }.invokeOnCompletion {
             presenterScope.launchUI { replacingMangaRelay.call(false) }
         }
     }