修复测试版获取
This commit is contained in:
@@ -23,38 +23,38 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
|
|||||||
"beta_releaseA_version" -> AppVariant.BETA_RELEASEA
|
"beta_releaseA_version" -> AppVariant.BETA_RELEASEA
|
||||||
else -> AppConst.appInfo.appVariant
|
else -> AppConst.appInfo.appVariant
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getLatestRelease(): List<AppReleaseInfo> {
|
private suspend fun getLatestRelease(): List<AppReleaseInfo> {
|
||||||
val lastReleaseUrl = if (checkVariant.isBeta()) {
|
val url = "https://api.github.com/repos/HapeLee/legado-with-MD3/releases"
|
||||||
"https://api.github.com/repos/HapeLee/legado-with-MD3/releases/tags/beta"
|
val res = okHttpClient.newCallResponse { url(url) }
|
||||||
} 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()
|
|
||||||
if (body.isNullOrBlank()) {
|
val body = res.body.text()
|
||||||
throw NoStackTraceException("获取新版本出错")
|
if (body.isBlank()) {
|
||||||
|
throw NoStackTraceException("获取新版本出错:返回为空")
|
||||||
}
|
}
|
||||||
return GSON.fromJsonObject<GithubRelease>(body)
|
val allReleases = GSON.fromJsonObject<List<GithubRelease>>(body)
|
||||||
.getOrElse {
|
.getOrElse { throw NoStackTraceException("解析版本信息出错:${it.localizedMessage}") }
|
||||||
throw NoStackTraceException("获取新版本出错 " + it.localizedMessage)
|
|
||||||
}
|
val releases = allReleases
|
||||||
.gitReleaseToAppReleaseInfo()
|
.flatMap { it.gitReleaseToAppReleaseInfo() }
|
||||||
|
.filter { it.appVariant == checkVariant }
|
||||||
.sortedByDescending { it.createdAt }
|
.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 }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user