mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Hopefully fixed crash when github checks updates at launch
which has the oh so slightly possibility of fixing the crash on library (doubt again)
This commit is contained in:
parent
858d7725c7
commit
2f1457954c
2 changed files with 30 additions and 12 deletions
|
@ -13,6 +13,8 @@ import eu.kanade.tachiyomi.util.system.withIOContext
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
internal class ExtensionGithubApi {
|
internal class ExtensionGithubApi {
|
||||||
|
@ -64,9 +66,12 @@ internal class ExtensionGithubApi {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val extensions = prefetchedExtensions ?: findExtensions()
|
val extensions = prefetchedExtensions ?: findExtensions()
|
||||||
|
|
||||||
val installedExtensions = ExtensionLoader.loadExtensions(context)
|
val extensionManager: ExtensionManager = Injekt.get()
|
||||||
.filterIsInstance<LoadResult.Success>()
|
val installedExtensions = extensionManager.installedExtensionsFlow.value.ifEmpty {
|
||||||
.map { it.extension }
|
ExtensionLoader.loadExtensionAsync(context)
|
||||||
|
.filterIsInstance<LoadResult.Success>()
|
||||||
|
.map { it.extension }
|
||||||
|
}
|
||||||
|
|
||||||
val extensionsWithUpdate = mutableListOf<Extension.Available>()
|
val extensionsWithUpdate = mutableListOf<Extension.Available>()
|
||||||
for (installedExt in installedExtensions) {
|
for (installedExt in installedExtensions) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import eu.kanade.tachiyomi.source.CatalogueSource
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceFactory
|
import eu.kanade.tachiyomi.source.SourceFactory
|
||||||
import eu.kanade.tachiyomi.util.lang.Hash
|
import eu.kanade.tachiyomi.util.lang.Hash
|
||||||
|
import eu.kanade.tachiyomi.util.system.withIOContext
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
@ -108,12 +109,7 @@ internal object ExtensionLoader {
|
||||||
File(getPrivateExtensionDir(context), "$pkgName.$PRIVATE_EXTENSION_EXTENSION").delete()
|
File(getPrivateExtensionDir(context), "$pkgName.$PRIVATE_EXTENSION_EXTENSION").delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private fun getExtensionsPackages(context: Context): List<ExtensionInfo> {
|
||||||
* Return a list of all the installed extensions initialized concurrently.
|
|
||||||
*
|
|
||||||
* @param context The application context.
|
|
||||||
*/
|
|
||||||
fun loadExtensions(context: Context): List<LoadResult> {
|
|
||||||
val pkgManager = context.packageManager
|
val pkgManager = context.packageManager
|
||||||
|
|
||||||
val installedPkgs = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
val installedPkgs = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
@ -141,7 +137,7 @@ internal object ExtensionLoader {
|
||||||
?.map { ExtensionInfo(packageInfo = it, isShared = false) }
|
?.map { ExtensionInfo(packageInfo = it, isShared = false) }
|
||||||
?: emptySequence()
|
?: emptySequence()
|
||||||
|
|
||||||
val extPkgs = (sharedExtPkgs + privateExtPkgs)
|
return (sharedExtPkgs + privateExtPkgs)
|
||||||
// Remove duplicates. Shared takes priority than private by default
|
// Remove duplicates. Shared takes priority than private by default
|
||||||
.distinctBy { it.packageInfo.packageName }
|
.distinctBy { it.packageInfo.packageName }
|
||||||
// Compare version number
|
// Compare version number
|
||||||
|
@ -151,9 +147,15 @@ internal object ExtensionLoader {
|
||||||
selectExtensionPackage(sharedPkg, privatePkg)
|
selectExtensionPackage(sharedPkg, privatePkg)
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
|
}
|
||||||
|
|
||||||
if (extPkgs.isEmpty()) return emptyList()
|
/**
|
||||||
|
* Return a list of all the installed extensions initialized concurrently.
|
||||||
|
*
|
||||||
|
* @param context The application context.
|
||||||
|
*/
|
||||||
|
fun loadExtensions(context: Context): List<LoadResult> {
|
||||||
|
val extPkgs = getExtensionsPackages(context)
|
||||||
// Load each extension concurrently and wait for completion
|
// Load each extension concurrently and wait for completion
|
||||||
return runBlocking {
|
return runBlocking {
|
||||||
val deferred = extPkgs.map {
|
val deferred = extPkgs.map {
|
||||||
|
@ -163,6 +165,17 @@ internal object ExtensionLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun loadExtensionAsync(context: Context): List<LoadResult> {
|
||||||
|
val extPkgs = getExtensionsPackages(context)
|
||||||
|
// Load each extension concurrently and wait for completion
|
||||||
|
return withIOContext {
|
||||||
|
val deferred = extPkgs.map {
|
||||||
|
async { loadExtension(context, it) }
|
||||||
|
}
|
||||||
|
deferred.awaitAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to load an extension from the given package name. It checks if the extension
|
* Attempts to load an extension from the given package name. It checks if the extension
|
||||||
* contains the required feature flag before trying to load it.
|
* contains the required feature flag before trying to load it.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue