Show error toast when extensions list fails to load

This commit is contained in:
arkon 2020-04-03 22:54:52 -04:00
parent 06c3f57f62
commit 022c0746c0
2 changed files with 26 additions and 29 deletions

View File

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

View File

@ -31,21 +31,21 @@ internal class ExtensionGithubApi {
val call = GET(EXT_URL) val call = GET(EXT_URL)
return withContext(Dispatchers.IO) { 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> { suspend fun checkForUpdates(context: Context): List<Extension.Installed> {
val call = GET(EXT_URL) val extensions = findExtensions()
return withContext(Dispatchers.IO) {
val response = network.client.newCall(call).await()
preferences.lastExtCheck().set(Date().time) preferences.lastExtCheck().set(Date().time)
if (response.isSuccessful) {
val extensions = parseResponse(response)
val installedExtensions = ExtensionLoader.loadExtensions(context) val installedExtensions = ExtensionLoader.loadExtensions(context)
.filterIsInstance<LoadResult.Success>() .filterIsInstance<LoadResult.Success>()
.map { it.extension } .map { it.extension }
@ -61,12 +61,7 @@ internal class ExtensionGithubApi {
} }
} }
extensionsWithUpdate return extensionsWithUpdate
} else {
response.close()
throw Exception("Failed to get extensions")
}
}
} }
private fun parseResponse(response: Response): List<Extension.Available> { private fun parseResponse(response: Response): List<Extension.Available> {