From a4515ad2511c6dfb073582efefdf3ec7e2bb1915 Mon Sep 17 00:00:00 2001 From: nicki <72807749+curche@users.noreply.github.com> Date: Wed, 11 May 2022 02:34:40 +0530 Subject: [PATCH] Check for app updates by comparing semver (#7100) Instead of just checking whether the current app version *matches* with latest app version in GitHub Releases, compare the semver from the tag names to check whether the latter is greater and the app needs an update Reference: semver spec #11 https://semver.org/#spec-item-11 Co-authored-by: Andreas <6576096+ghostbear@users.noreply.github.com> Co-authored-by: Andreas <6576096+ghostbear@users.noreply.github.com> (cherry picked from commit e7ed130f2a4fcd7452737476189687fbd130c80d) --- .../kanade/tachiyomi/data/updater/AppUpdateChecker.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt index 9b1b317c9..60460dc98 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt @@ -56,6 +56,7 @@ class AppUpdateChecker { private fun isNewVersion(versionTag: String): Boolean { // Removes prefixes like "r" or "v" val newVersion = versionTag.replace("[^\\d.]".toRegex(), "") + val oldVersion = BuildConfig.VERSION_NAME.replace("[^\\d.]".toRegex(), "") return if (BuildConfig.PREVIEW) { // Preview builds: based on releases in "tachiyomiorg/tachiyomi-preview" repo @@ -64,7 +65,15 @@ class AppUpdateChecker { } else { // Release builds: based on releases in "tachiyomiorg/tachiyomi" repo // tagged as something like "v0.1.2" - newVersion != BuildConfig.VERSION_NAME + val newSemVer = newVersion.split(".").map { it.toInt() } + val oldSemVer = oldVersion.split(".").map { it.toInt() } + + oldSemVer.mapIndexed { index, i -> + if (newSemVer[index] > i) { + return true + } + } + false } } }