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