diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index 48284ed44a..c85919ad6a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/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 = try { api.findExtensions() } catch (e: Exception) { + context.toast(e.message) emptyList() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt index cf8d448f5c..2ad7de9a55 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt @@ -30,38 +30,10 @@ internal class ExtensionGithubApi { suspend fun findExtensions(): List { val call = GET(EXT_URL) - return withContext(Dispatchers.IO) { - parseResponse(network.client.newCall(call).await()) - } - } - - suspend fun checkForUpdates(context: Context): List { - 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() - .map { it.extension } - - val extensionsWithUpdate = mutableListOf() - 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 { + val extensions = findExtensions() + + preferences.lastExtCheck().set(Date().time) + + val installedExtensions = ExtensionLoader.loadExtensions(context) + .filterIsInstance() + .map { it.extension } + + val extensionsWithUpdate = mutableListOf() + 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 { val text = response.body?.use { it.string() } ?: return emptyList()