mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 03:07:25 +01:00
Show error toast when extensions list fails to load
This commit is contained in:
parent
06c3f57f62
commit
022c0746c0
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,38 +30,10 @@ internal class ExtensionGithubApi {
|
|||||||
suspend fun findExtensions(): List<Extension.Available> {
|
suspend fun findExtensions(): List<Extension.Available> {
|
||||||
val call = GET(EXT_URL)
|
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) {
|
return withContext(Dispatchers.IO) {
|
||||||
val response = network.client.newCall(call).await()
|
val response = network.client.newCall(call).await()
|
||||||
|
|
||||||
preferences.lastExtCheck().set(Date().time)
|
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val extensions = parseResponse(response)
|
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
|
|
||||||
} else {
|
} else {
|
||||||
response.close()
|
response.close()
|
||||||
throw Exception("Failed to get extensions")
|
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> {
|
private fun parseResponse(response: Response): List<Extension.Available> {
|
||||||
val text = response.body?.use { it.string() } ?: return emptyList()
|
val text = response.body?.use { it.string() } ?: return emptyList()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user