Browse Source

Prompt Extension update if ext-lib is updated

Co-authored-by: arkon <[email protected]>
AntsyLich 2 years ago
parent
commit
e1ab1fdb65

+ 12 - 6
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() {

+ 6 - 1
app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt

@@ -100,7 +100,7 @@ internal class ExtensionGithubApi {
     private fun List<ExtensionJsonObject>.toExtensions(): List<Extension.Available> {
         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/"

+ 4 - 0
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,

+ 10 - 9
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,