浏览代码

Show error toast when extensions list fails to load

arkon 5 年之前
父节点
当前提交
022c0746c0

+ 2 - 0
app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt

@@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.extension.util.ExtensionLoader
 import eu.kanade.tachiyomi.source.Source
 import eu.kanade.tachiyomi.source.SourceManager
 import eu.kanade.tachiyomi.util.lang.launchNow
+import eu.kanade.tachiyomi.util.system.toast
 import kotlinx.coroutines.async
 import rx.Observable
 import uy.kohesive.injekt.Injekt
@@ -160,6 +161,7 @@ class ExtensionManager(
             val extensions: List<Extension.Available> = try {
                 api.findExtensions()
             } catch (e: Exception) {
+                context.toast(e.message)
                 emptyList()
             }
 

+ 21 - 26
app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt

@@ -31,42 +31,37 @@ internal class ExtensionGithubApi {
         val call = GET(EXT_URL)
 
         return withContext(Dispatchers.IO) {
-            parseResponse(network.client.newCall(call).await())
+            val response = network.client.newCall(call).await()
+            if (response.isSuccessful) {
+                parseResponse(response)
+            } else {
+                response.close()
+                throw Exception("Failed to get extensions")
+            }
         }
     }
 
     suspend fun checkForUpdates(context: Context): List<Extension.Installed> {
-        val call = GET(EXT_URL)
-
-        return withContext(Dispatchers.IO) {
-            val response = network.client.newCall(call).await()
-
-            preferences.lastExtCheck().set(Date().time)
+        val extensions = findExtensions()
 
-            if (response.isSuccessful) {
-                val extensions = parseResponse(response)
+        preferences.lastExtCheck().set(Date().time)
 
-                val installedExtensions = ExtensionLoader.loadExtensions(context)
-                    .filterIsInstance<LoadResult.Success>()
-                    .map { it.extension }
+        val installedExtensions = ExtensionLoader.loadExtensions(context)
+            .filterIsInstance<LoadResult.Success>()
+            .map { it.extension }
 
-                val extensionsWithUpdate = mutableListOf<Extension.Installed>()
-                for (installedExt in installedExtensions) {
-                    val pkgName = installedExt.pkgName
-                    val availableExt = extensions.find { it.pkgName == pkgName } ?: continue
-
-                    val hasUpdate = availableExt.versionCode > installedExt.versionCode
-                    if (hasUpdate) {
-                        extensionsWithUpdate.add(installedExt)
-                    }
-                }
+        val extensionsWithUpdate = mutableListOf<Extension.Installed>()
+        for (installedExt in installedExtensions) {
+            val pkgName = installedExt.pkgName
+            val availableExt = extensions.find { it.pkgName == pkgName } ?: continue
 
-                extensionsWithUpdate
-            } else {
-                response.close()
-                throw Exception("Failed to get extensions")
+            val hasUpdate = availableExt.versionCode > installedExt.versionCode
+            if (hasUpdate) {
+                extensionsWithUpdate.add(installedExt)
             }
         }
+
+        return extensionsWithUpdate
     }
 
     private fun parseResponse(response: Response): List<Extension.Available> {