fix: respect update channel selection when checking for updates
This commit is contained in:
@@ -124,7 +124,7 @@ fun UpdatePage(onNavigateBack: () -> Unit) {
|
||||
isLoading = true
|
||||
withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
UpdateUtil.checkForUpdate(context)?.let {
|
||||
UpdateUtil.checkForUpdate(context, updateChannel == PRE_RELEASE)?.let {
|
||||
latestRelease = it
|
||||
showUpdateDialog = true
|
||||
} ?: run {
|
||||
|
||||
@@ -16,22 +16,31 @@ object UpdateUtil {
|
||||
private const val REPO = "Astronia"
|
||||
|
||||
private val client = OkHttpClient()
|
||||
private val requestForReleases =
|
||||
Request.Builder().url("https://api.github.com/repos/${OWNER}/${REPO}/releases/latest")
|
||||
.build()
|
||||
|
||||
private val jsonFormat = Json { ignoreUnknownKeys = true }
|
||||
|
||||
private fun getLatestRelease(): LatestRelease =
|
||||
client.newCall(requestForReleases).execute().run {
|
||||
val latestRelease = jsonFormat.decodeFromString<LatestRelease>(this.body.string())
|
||||
body.close()
|
||||
latestRelease
|
||||
private fun getLatestRelease(includePreRelease: Boolean): LatestRelease? {
|
||||
val url = if (includePreRelease) {
|
||||
"https://api.github.com/repos/${OWNER}/${REPO}/releases"
|
||||
} else {
|
||||
"https://api.github.com/repos/${OWNER}/${REPO}/releases/latest"
|
||||
}
|
||||
|
||||
val request = Request.Builder().url(url).build()
|
||||
return client.newCall(request).execute().run {
|
||||
val result = if (includePreRelease) {
|
||||
val releases = jsonFormat.decodeFromString<List<LatestRelease>>(body.string())
|
||||
releases.firstOrNull { it.preRelease }
|
||||
} else {
|
||||
jsonFormat.decodeFromString<LatestRelease>(body.string())
|
||||
}
|
||||
body.close()
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
fun checkForUpdate(context: Context): LatestRelease? {
|
||||
fun checkForUpdate(context: Context, includePreRelease: Boolean = false): LatestRelease? {
|
||||
val currentVersion = context.getCurrentVersion()
|
||||
val latestRelease = getLatestRelease()
|
||||
val latestRelease = getLatestRelease(includePreRelease) ?: return null
|
||||
val latestVersion = latestRelease.name.toVersion()
|
||||
return if (currentVersion < latestVersion) latestRelease
|
||||
else null
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
Astronia is a lightweight and modern M3U8 video player for Android, built with Material Design 3. It provides a clean and intuitive interface for streaming video content.
|
||||
|
||||
<b>Features</b>
|
||||
|
||||
- 🎬 M3U8 video streaming playback
|
||||
- 📱 Material Design 3 UI
|
||||
- 🌙 Dark mode support
|
||||
|
||||
Reference in New Issue
Block a user