mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
fix: update checker doesn't detect new releases properly
This commit is contained in:
parent
c710ef8059
commit
8f685ed8ea
@ -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() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user