From e1ab1fdb656bea90bdf6990523c857e0434fbc0c Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Fri, 28 Oct 2022 16:37:59 +0600 Subject: [PATCH] Prompt Extension update if ext-lib is updated Co-authored-by: arkon --- .../tachiyomi/extension/ExtensionManager.kt | 18 ++++++++++++------ .../extension/api/ExtensionGithubApi.kt | 7 ++++++- .../tachiyomi/extension/model/Extension.kt | 4 ++++ .../extension/util/ExtensionLoader.kt | 19 ++++++++++--------- 4 files changed, 32 insertions(+), 16 deletions(-) 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 52e27bf8bf..4d216ca7fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -180,8 +180,7 @@ class ExtensionManager( mutInstalledExtensions[index] = installedExt.copy(isObsolete = true) changed = true } else if (availableExt != null) { - val hasUpdate = !installedExt.isUnofficial && - availableExt.versionCode > installedExt.versionCode + val hasUpdate = installedExt.updateExists(availableExt) if (installedExt.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. */ private fun Extension.Installed.withUpdateCheck(): Extension.Installed { - val availableExt = _availableExtensionsFlow.value.find { it.pkgName == pkgName } - if (!isUnofficial && availableExt != null && availableExt.versionCode > versionCode) { - return copy(hasUpdate = true) + return if (updateExists()) { + 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() { 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 6ccc969a19..43c2a2088f 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 @@ -100,7 +100,7 @@ internal class ExtensionGithubApi { private fun List.toExtensions(): List { return this .filter { - val libVersion = it.version.substringBeforeLast('.').toDouble() + val libVersion = it.extractLibVersion() libVersion >= ExtensionLoader.LIB_VERSION_MIN && libVersion <= ExtensionLoader.LIB_VERSION_MAX } .map { @@ -109,6 +109,7 @@ internal class ExtensionGithubApi { pkgName = it.pkg, versionName = it.version, versionCode = it.code, + libVersion = it.extractLibVersion(), lang = it.lang, isNsfw = it.nsfw == 1, hasReadme = it.hasReadme == 1, @@ -142,6 +143,10 @@ internal class ExtensionGithubApi { 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/" diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt index 5157175a44..2dcd1a0c3d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt @@ -10,6 +10,7 @@ sealed class Extension { abstract val pkgName: String abstract val versionName: String abstract val versionCode: Long + abstract val libVersion: Double abstract val lang: String? abstract val isNsfw: Boolean abstract val hasReadme: Boolean @@ -20,6 +21,7 @@ sealed class Extension { override val pkgName: String, override val versionName: String, override val versionCode: Long, + override val libVersion: Double, override val lang: String, override val isNsfw: Boolean, override val hasReadme: Boolean, @@ -37,6 +39,7 @@ sealed class Extension { override val pkgName: String, override val versionName: String, override val versionCode: Long, + override val libVersion: Double, override val lang: String, override val isNsfw: Boolean, override val hasReadme: Boolean, @@ -51,6 +54,7 @@ sealed class Extension { override val pkgName: String, override val versionName: String, override val versionCode: Long, + override val libVersion: Double, val signatureHash: String, override val lang: String? = null, override val isNsfw: Boolean = false, diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt index 14cc0762a6..dcf04dbf6c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt @@ -141,7 +141,7 @@ internal object ExtensionLoader { logcat(LogPriority.WARN) { "Package $pkgName isn't signed" } return LoadResult.Error } 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" } return LoadResult.Untrusted(extension) } @@ -190,14 +190,15 @@ internal object ExtensionLoader { } val extension = Extension.Installed( - extName, - pkgName, - versionName, - versionCode, - lang, - isNsfw, - hasReadme, - hasChangelog, + name = extName, + pkgName = pkgName, + versionName = versionName, + versionCode = versionCode, + libVersion = libVersion, + lang = lang, + isNsfw = isNsfw, + hasReadme = hasReadme, + hasChangelog = hasChangelog, sources = sources, pkgFactory = appInfo.metaData.getString(METADATA_SOURCE_FACTORY), isUnofficial = signatureHash != officialSignature,