Prompt Extension update if ext-lib is updated

Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
AntsyLich 2022-10-28 16:37:59 +06:00 committed by arkon
parent 3e86cb094b
commit e1ab1fdb65
4 changed files with 32 additions and 16 deletions

View File

@ -180,8 +180,7 @@ class ExtensionManager(
mutInstalledExtensions[index] = installedExt.copy(isObsolete = true) mutInstalledExtensions[index] = installedExt.copy(isObsolete = true)
changed = true changed = true
} else if (availableExt != null) { } else if (availableExt != null) {
val hasUpdate = !installedExt.isUnofficial && val hasUpdate = installedExt.updateExists(availableExt)
availableExt.versionCode > installedExt.versionCode
if (installedExt.hasUpdate != hasUpdate) { if (installedExt.hasUpdate != hasUpdate) {
mutInstalledExtensions[index] = installedExt.copy(hasUpdate = hasUpdate) mutInstalledExtensions[index] = installedExt.copy(hasUpdate = hasUpdate)
@ -347,11 +346,18 @@ class ExtensionManager(
* Extension method to set the update field of an installed extension. * Extension method to set the update field of an installed extension.
*/ */
private fun Extension.Installed.withUpdateCheck(): Extension.Installed { private fun Extension.Installed.withUpdateCheck(): Extension.Installed {
val availableExt = _availableExtensionsFlow.value.find { it.pkgName == pkgName } return if (updateExists()) {
if (!isUnofficial && availableExt != null && availableExt.versionCode > versionCode) { copy(hasUpdate = true)
return copy(hasUpdate = true) } else {
this
} }
return this }
private fun Extension.Installed.updateExists(availableExtension: Extension.Available? = null): Boolean {
val availableExt = availableExtension ?: _availableExtensionsFlow.value.find { it.pkgName == pkgName }
if (isUnofficial || availableExt == null) return false
return (availableExt.versionCode > versionCode || availableExt.libVersion > libVersion)
} }
private fun updatePendingUpdatesCount() { private fun updatePendingUpdatesCount() {

View File

@ -100,7 +100,7 @@ internal class ExtensionGithubApi {
private fun List<ExtensionJsonObject>.toExtensions(): List<Extension.Available> { private fun List<ExtensionJsonObject>.toExtensions(): List<Extension.Available> {
return this return this
.filter { .filter {
val libVersion = it.version.substringBeforeLast('.').toDouble() val libVersion = it.extractLibVersion()
libVersion >= ExtensionLoader.LIB_VERSION_MIN && libVersion <= ExtensionLoader.LIB_VERSION_MAX libVersion >= ExtensionLoader.LIB_VERSION_MIN && libVersion <= ExtensionLoader.LIB_VERSION_MAX
} }
.map { .map {
@ -109,6 +109,7 @@ internal class ExtensionGithubApi {
pkgName = it.pkg, pkgName = it.pkg,
versionName = it.version, versionName = it.version,
versionCode = it.code, versionCode = it.code,
libVersion = it.extractLibVersion(),
lang = it.lang, lang = it.lang,
isNsfw = it.nsfw == 1, isNsfw = it.nsfw == 1,
hasReadme = it.hasReadme == 1, hasReadme = it.hasReadme == 1,
@ -142,6 +143,10 @@ internal class ExtensionGithubApi {
REPO_URL_PREFIX REPO_URL_PREFIX
} }
} }
private fun ExtensionJsonObject.extractLibVersion(): Double {
return version.substringBeforeLast('.').toDouble()
}
} }
private const val REPO_URL_PREFIX = "https://raw.githubusercontent.com/tachiyomiorg/tachiyomi-extensions/repo/" private const val REPO_URL_PREFIX = "https://raw.githubusercontent.com/tachiyomiorg/tachiyomi-extensions/repo/"

View File

@ -10,6 +10,7 @@ sealed class Extension {
abstract val pkgName: String abstract val pkgName: String
abstract val versionName: String abstract val versionName: String
abstract val versionCode: Long abstract val versionCode: Long
abstract val libVersion: Double
abstract val lang: String? abstract val lang: String?
abstract val isNsfw: Boolean abstract val isNsfw: Boolean
abstract val hasReadme: Boolean abstract val hasReadme: Boolean
@ -20,6 +21,7 @@ sealed class Extension {
override val pkgName: String, override val pkgName: String,
override val versionName: String, override val versionName: String,
override val versionCode: Long, override val versionCode: Long,
override val libVersion: Double,
override val lang: String, override val lang: String,
override val isNsfw: Boolean, override val isNsfw: Boolean,
override val hasReadme: Boolean, override val hasReadme: Boolean,
@ -37,6 +39,7 @@ sealed class Extension {
override val pkgName: String, override val pkgName: String,
override val versionName: String, override val versionName: String,
override val versionCode: Long, override val versionCode: Long,
override val libVersion: Double,
override val lang: String, override val lang: String,
override val isNsfw: Boolean, override val isNsfw: Boolean,
override val hasReadme: Boolean, override val hasReadme: Boolean,
@ -51,6 +54,7 @@ sealed class Extension {
override val pkgName: String, override val pkgName: String,
override val versionName: String, override val versionName: String,
override val versionCode: Long, override val versionCode: Long,
override val libVersion: Double,
val signatureHash: String, val signatureHash: String,
override val lang: String? = null, override val lang: String? = null,
override val isNsfw: Boolean = false, override val isNsfw: Boolean = false,

View File

@ -141,7 +141,7 @@ internal object ExtensionLoader {
logcat(LogPriority.WARN) { "Package $pkgName isn't signed" } logcat(LogPriority.WARN) { "Package $pkgName isn't signed" }
return LoadResult.Error return LoadResult.Error
} else if (signatureHash !in trustedSignatures) { } else if (signatureHash !in trustedSignatures) {
val extension = Extension.Untrusted(extName, pkgName, versionName, versionCode, signatureHash) val extension = Extension.Untrusted(extName, pkgName, versionName, versionCode, libVersion, signatureHash)
logcat(LogPriority.WARN) { "Extension $pkgName isn't trusted" } logcat(LogPriority.WARN) { "Extension $pkgName isn't trusted" }
return LoadResult.Untrusted(extension) return LoadResult.Untrusted(extension)
} }
@ -190,14 +190,15 @@ internal object ExtensionLoader {
} }
val extension = Extension.Installed( val extension = Extension.Installed(
extName, name = extName,
pkgName, pkgName = pkgName,
versionName, versionName = versionName,
versionCode, versionCode = versionCode,
lang, libVersion = libVersion,
isNsfw, lang = lang,
hasReadme, isNsfw = isNsfw,
hasChangelog, hasReadme = hasReadme,
hasChangelog = hasChangelog,
sources = sources, sources = sources,
pkgFactory = appInfo.metaData.getString(METADATA_SOURCE_FACTORY), pkgFactory = appInfo.metaData.getString(METADATA_SOURCE_FACTORY),
isUnofficial = signatureHash != officialSignature, isUnofficial = signatureHash != officialSignature,