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.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()
}

View File

@ -30,38 +30,10 @@ internal class ExtensionGithubApi {
suspend fun findExtensions(): List<Extension.Available> {
val call = GET(EXT_URL)
return withContext(Dispatchers.IO) {
parseResponse(network.client.newCall(call).await())
}
}
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)
if (response.isSuccessful) {
val extensions = parseResponse(response)
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)
}
}
extensionsWithUpdate
parseResponse(response)
} else {
response.close()
throw Exception("Failed to get extensions")
@ -69,6 +41,29 @@ internal class ExtensionGithubApi {
}
}
suspend fun checkForUpdates(context: Context): List<Extension.Installed> {
val extensions = findExtensions()
preferences.lastExtCheck().set(Date().time)
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)
}
}
return extensionsWithUpdate
}
private fun parseResponse(response: Response): List<Extension.Available> {
val text = response.body?.use { it.string() } ?: return emptyList()