fixes from inspector

This commit is contained in:
Aria Moradi 2021-04-03 20:08:50 +04:30
parent 15bd5b4b7a
commit 884308690f
2 changed files with 13 additions and 19 deletions

View File

@ -47,8 +47,8 @@ object Extension {
private val logger = KotlinLogging.logger {} private val logger = KotlinLogging.logger {}
data class InstallableAPK( data class InstallableAPK(
val apkFilePath: String, val apkFilePath: String,
val pkgName: String val pkgName: String
) )
suspend fun installExtension(pkgName: String): Int { suspend fun installExtension(pkgName: String): Int {
@ -94,8 +94,8 @@ object Extension {
val libVersion = packageInfo.versionName.substringBeforeLast('.').toDouble() val libVersion = packageInfo.versionName.substringBeforeLast('.').toDouble()
if (libVersion < LIB_VERSION_MIN || libVersion > LIB_VERSION_MAX) { if (libVersion < LIB_VERSION_MIN || libVersion > LIB_VERSION_MAX) {
throw Exception( throw Exception(
"Lib version is $libVersion, while only versions " + "Lib version is $libVersion, while only versions " +
"$LIB_VERSION_MIN to $LIB_VERSION_MAX are allowed" "$LIB_VERSION_MIN to $LIB_VERSION_MAX are allowed"
) )
} }
@ -124,10 +124,7 @@ object Extension {
val sources: List<CatalogueSource> = when (val instance = loadExtensionSources(jarFilePath, className)) { val sources: List<CatalogueSource> = when (val instance = loadExtensionSources(jarFilePath, className)) {
is Source -> listOf(instance) is Source -> listOf(instance)
is SourceFactory -> instance.createSources() is SourceFactory -> instance.createSources()
else -> throw RuntimeException("Unknown source class type! ${instance.javaClass}")
else -> {
throw RuntimeException("Unknown source class type! ${instance.javaClass}")
}
}.map { it as CatalogueSource } }.map { it as CatalogueSource }
val langs = sources.map { it.lang }.toSet() val langs = sources.map { it.lang }.toSet()
@ -239,7 +236,7 @@ object Extension {
return getCachedImageResponse(saveDir, apkName) { return getCachedImageResponse(saveDir, apkName) {
network.client.newCall( network.client.newCall(
GET(iconUrl) GET(iconUrl)
).await() ).await()
} }
} }

View File

@ -7,6 +7,7 @@ package ir.armor.tachidesk.impl.util
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceFactory import eu.kanade.tachiyomi.source.SourceFactory
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import ir.armor.tachidesk.impl.util.PackageTools.loadExtensionSources import ir.armor.tachidesk.impl.util.PackageTools.loadExtensionSources
@ -40,16 +41,12 @@ object GetHttpSource {
val jarName = apkName.substringBefore(".apk") + ".jar" val jarName = apkName.substringBefore(".apk") + ".jar"
val jarPath = "${ApplicationDirs.extensionsRoot}/$jarName" val jarPath = "${ApplicationDirs.extensionsRoot}/$jarName"
val extensionInstance = loadExtensionSources(jarPath, className) when (val instance = loadExtensionSources(jarPath, className)) {
is Source -> listOf(instance)
if (sourceRecord[SourceTable.partOfFactorySource]) { is SourceFactory -> instance.createSources()
(extensionInstance as SourceFactory).createSources().forEach { else -> throw Exception("Unknown source class type! ${instance.javaClass}")
sourceCache[it.id] = it as HttpSource }.forEach {
} sourceCache[it.id] = it as HttpSource
} else {
(extensionInstance as HttpSource).also {
sourceCache[it.id] = it
}
} }
return sourceCache[sourceId]!! return sourceCache[sourceId]!!
} }