真的修了测试版获取吗
This commit is contained in:
@@ -61,7 +61,6 @@ object AppConst {
|
|||||||
?.let {
|
?.let {
|
||||||
appInfo.versionName = it.versionName!!
|
appInfo.versionName = it.versionName!!
|
||||||
appInfo.appVariant = when {
|
appInfo.appVariant = when {
|
||||||
it.packageName.contains("releaseA") -> AppVariant.BETA_RELEASEA
|
|
||||||
isBeta -> AppVariant.BETA_RELEASE
|
isBeta -> AppVariant.BETA_RELEASE
|
||||||
isOfficial -> AppVariant.OFFICIAL
|
isOfficial -> AppVariant.OFFICIAL
|
||||||
else -> AppVariant.UNKNOWN
|
else -> AppVariant.UNKNOWN
|
||||||
|
|||||||
@@ -21,12 +21,11 @@ data class AppReleaseInfo(
|
|||||||
|
|
||||||
enum class AppVariant {
|
enum class AppVariant {
|
||||||
OFFICIAL,
|
OFFICIAL,
|
||||||
BETA_RELEASEA,
|
|
||||||
BETA_RELEASE,
|
BETA_RELEASE,
|
||||||
UNKNOWN;
|
UNKNOWN;
|
||||||
|
|
||||||
fun isBeta(): Boolean {
|
fun isBeta(): Boolean {
|
||||||
return this == BETA_RELEASE || this == BETA_RELEASEA
|
return this == BETA_RELEASE
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -69,7 +68,6 @@ data class Asset(
|
|||||||
val timestamp: Long = instant.toEpochMilli()
|
val timestamp: Long = instant.toEpochMilli()
|
||||||
|
|
||||||
val appVariant = when {
|
val appVariant = when {
|
||||||
preRelease && name.contains("releaseA") -> AppVariant.BETA_RELEASEA
|
|
||||||
preRelease && name.contains("release") -> AppVariant.BETA_RELEASE
|
preRelease && name.contains("release") -> AppVariant.BETA_RELEASE
|
||||||
else -> AppVariant.OFFICIAL
|
else -> AppVariant.OFFICIAL
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import io.legato.kazusa.help.http.newCallResponse
|
|||||||
import io.legato.kazusa.help.http.okHttpClient
|
import io.legato.kazusa.help.http.okHttpClient
|
||||||
import io.legato.kazusa.help.http.text
|
import io.legato.kazusa.help.http.text
|
||||||
import io.legato.kazusa.utils.GSON
|
import io.legato.kazusa.utils.GSON
|
||||||
|
import io.legato.kazusa.utils.fromJsonArray
|
||||||
import io.legato.kazusa.utils.fromJsonObject
|
import io.legato.kazusa.utils.fromJsonObject
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
|
||||||
@@ -20,41 +21,48 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
|
|||||||
get() = when (AppConfig.updateToVariant) {
|
get() = when (AppConfig.updateToVariant) {
|
||||||
"official_version" -> AppVariant.OFFICIAL
|
"official_version" -> AppVariant.OFFICIAL
|
||||||
"beta_release_version" -> AppVariant.BETA_RELEASE
|
"beta_release_version" -> AppVariant.BETA_RELEASE
|
||||||
"beta_releaseA_version" -> AppVariant.BETA_RELEASEA
|
|
||||||
else -> AppConst.appInfo.appVariant
|
else -> AppConst.appInfo.appVariant
|
||||||
}
|
}
|
||||||
private suspend fun getLatestRelease(): List<AppReleaseInfo> {
|
|
||||||
val url = "https://api.github.com/repos/HapeLee/legado-with-MD3/releases"
|
|
||||||
val res = okHttpClient.newCallResponse { url(url) }
|
|
||||||
|
|
||||||
|
private suspend fun getLatestRelease(): List<AppReleaseInfo> {
|
||||||
|
val lastReleaseUrl = if (checkVariant.isBeta()) {
|
||||||
|
"https://api.github.com/repos/HapeLee/legado-with-MD3/releases"
|
||||||
|
} else {
|
||||||
|
"https://api.github.com/repos/HapeLee/legado-with-MD3/releases/latest"
|
||||||
|
}
|
||||||
|
|
||||||
|
val res = okHttpClient.newCallResponse {
|
||||||
|
url(lastReleaseUrl)
|
||||||
|
}
|
||||||
if (!res.isSuccessful) {
|
if (!res.isSuccessful) {
|
||||||
throw NoStackTraceException("获取新版本出错(${res.code})")
|
throw NoStackTraceException("获取新版本出错(${res.code})")
|
||||||
}
|
}
|
||||||
|
|
||||||
val body = res.body.text()
|
val body = res.body.text()
|
||||||
if (body.isBlank()) {
|
if (body.isBlank()) {
|
||||||
throw NoStackTraceException("获取新版本出错:返回为空")
|
throw NoStackTraceException("获取新版本出错")
|
||||||
|
}
|
||||||
|
return if (checkVariant.isBeta()) {
|
||||||
|
GSON.fromJsonArray<GithubRelease>(body)
|
||||||
|
.getOrElse { throw NoStackTraceException("获取新版本出错 ${it.localizedMessage}") }
|
||||||
|
.filter { it.isPreRelease }
|
||||||
|
.flatMap { it.gitReleaseToAppReleaseInfo() }
|
||||||
|
.sortedByDescending { it.createdAt }
|
||||||
|
} else {
|
||||||
|
listOf(
|
||||||
|
GSON.fromJsonObject<GithubRelease>(body)
|
||||||
|
.getOrElse { throw NoStackTraceException("获取新版本出错 ${it.localizedMessage}") }
|
||||||
|
.gitReleaseToAppReleaseInfo()
|
||||||
|
).flatten()
|
||||||
|
.sortedByDescending { it.createdAt }
|
||||||
}
|
}
|
||||||
val allReleases = GSON.fromJsonObject<List<GithubRelease>>(body)
|
|
||||||
.getOrElse { throw NoStackTraceException("解析版本信息出错:${it.localizedMessage}") }
|
|
||||||
|
|
||||||
val releases = allReleases
|
|
||||||
.flatMap { it.gitReleaseToAppReleaseInfo() }
|
|
||||||
.filter { it.appVariant == checkVariant }
|
|
||||||
.sortedByDescending { it.createdAt }
|
|
||||||
|
|
||||||
return releases
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查更新
|
|
||||||
*/
|
|
||||||
override fun check(scope: CoroutineScope): Coroutine<AppUpdate.UpdateInfo> {
|
override fun check(scope: CoroutineScope): Coroutine<AppUpdate.UpdateInfo> {
|
||||||
return Coroutine.async(scope) {
|
return Coroutine.async(scope) {
|
||||||
val currentVersion = AppConst.appInfo.versionName
|
val currentVersion = AppConst.appInfo.versionName
|
||||||
val releases = getLatestRelease()
|
val releases = getLatestRelease()
|
||||||
|
.filter { it.appVariant == checkVariant }
|
||||||
|
|
||||||
// 找出比当前版本高的最新 release
|
|
||||||
val latest = releases
|
val latest = releases
|
||||||
.firstOrNull { it.versionName > currentVersion }
|
.firstOrNull { it.versionName > currentVersion }
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ class UpdateDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_update) {
|
|||||||
get() = when (AppConfig.updateToVariant) {
|
get() = when (AppConfig.updateToVariant) {
|
||||||
"official_version" -> AppVariant.OFFICIAL
|
"official_version" -> AppVariant.OFFICIAL
|
||||||
"beta_release_version" -> AppVariant.BETA_RELEASE
|
"beta_release_version" -> AppVariant.BETA_RELEASE
|
||||||
"beta_releaseA_version" -> AppVariant.BETA_RELEASEA
|
|
||||||
else -> AppConst.appInfo.appVariant
|
else -> AppConst.appInfo.appVariant
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user