Merge pull request #7143 from Bnyro/master

fix: update checker doesn't detect new releases properly
This commit is contained in:
Bnyro 2025-03-01 12:57:16 +01:00 committed by GitHub
commit 924098b135
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,14 +18,14 @@ import java.util.Locale
class UpdateChecker(private val context: Context) {
suspend fun checkUpdate(isManualCheck: Boolean = false) {
val currentAppVersion = BuildConfig.VERSION_NAME.replace(".", "").toInt()
val currentAppVersion = BuildConfig.VERSION_NAME.filter { it.isDigit() }.toInt()
try {
val response = RetrofitInstance.externalApi.getLatestRelease()
// version would be in the format "0.21.1"
val update = response.name.replace(".", "").toIntOrNull()
val update = response.name.filter { it.isDigit() }.toInt()
if (update != null && currentAppVersion < update) {
if (currentAppVersion != update) {
withContext(Dispatchers.Main) {
showUpdateAvailableDialog(response.body, response.htmlUrl)
}
@ -56,15 +56,15 @@ class UpdateChecker(private val context: Context) {
}
private fun sanitizeChangelog(changelog: String): String {
val removeBloat = changelog.substringBeforeLast("**Full Changelog**")
val removeLinks = removeBloat.replace(Regex("in https://github\\.com/\\S+"), "")
val uppercaseChangeType =
removeLinks.lines().joinToString("\n") { line ->
return changelog.substringBeforeLast("**Full Changelog**")
.replace(Regex("in https://github\\.com/\\S+"), "")
.lines().joinToString("\n") { line ->
if (line.startsWith("##")) line.uppercase(Locale.ROOT) + " :" else line
}
val removeHashes = uppercaseChangeType.replace("## ", "")
val cleanPrefix = removeHashes.replace("*", "")
return cleanPrefix.trim()
.replace("## ", "")
.replace(">", "")
.replace("*", "")
.lines()
.joinToString("\n") { it.trim() }
}
}