mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-16 14:17:09 +02:00
fix(app): update checker crash on release builds
This commit is contained in:
parent
39525c9dca
commit
b2587593cd
@ -2,6 +2,7 @@ package me.rhunk.snapenhance.ui.manager.data
|
||||
|
||||
import com.google.gson.JsonParser
|
||||
import me.rhunk.snapenhance.common.BuildConfig
|
||||
import me.rhunk.snapenhance.common.logger.AbstractLogger
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
|
||||
@ -12,7 +13,7 @@ object Updater {
|
||||
val releaseUrl: String
|
||||
)
|
||||
|
||||
fun checkForLatestRelease(): LatestRelease? {
|
||||
private fun fetchLatestRelease() = runCatching {
|
||||
val endpoint = Request.Builder().url("https://api.github.com/repos/rhunk/SnapEnhance/releases").build()
|
||||
val response = OkHttpClient().newCall(endpoint).execute()
|
||||
|
||||
@ -24,8 +25,14 @@ object Updater {
|
||||
|
||||
val latestRelease = releases.get(0).asJsonObject
|
||||
val latestVersion = latestRelease.getAsJsonPrimitive("tag_name").asString
|
||||
if (latestVersion.removePrefix("v") == BuildConfig.VERSION_NAME) return null
|
||||
if (latestVersion.removePrefix("v") == BuildConfig.VERSION_NAME) return@runCatching null
|
||||
|
||||
return LatestRelease(latestVersion, endpoint.url.toString().replace("api.", "").replace("repos/", ""))
|
||||
LatestRelease(latestVersion, endpoint.url.toString().replace("api.", "").replace("repos/", ""))
|
||||
}.onFailure {
|
||||
AbstractLogger.directError("Failed to fetch latest release", it)
|
||||
}.getOrNull()
|
||||
|
||||
val latestRelease by lazy {
|
||||
fetchLatestRelease()
|
||||
}
|
||||
}
|
@ -201,7 +201,7 @@ class HomeRootSection : Routes.Route() {
|
||||
}
|
||||
|
||||
val latestUpdate by rememberAsyncMutableState(defaultValue = null) {
|
||||
if (!BuildConfig.DEBUG) Updater.checkForLatestRelease() else null
|
||||
if (!BuildConfig.DEBUG) Updater.latestRelease else null
|
||||
}
|
||||
|
||||
if (latestUpdate != null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user