|
|
|
@ -1,6 +1,5 @@ |
|
|
|
|
package io.legado.app.help |
|
|
|
|
|
|
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
|
import io.legado.app.help.http.newCallStrResponse |
|
|
|
|
import io.legado.app.help.http.okHttpClient |
|
|
|
@ -13,10 +12,10 @@ import splitties.init.appCtx |
|
|
|
|
|
|
|
|
|
object AppUpdate { |
|
|
|
|
|
|
|
|
|
fun checkUpdate( |
|
|
|
|
fun checkFromGitHub( |
|
|
|
|
scope: CoroutineScope, |
|
|
|
|
showErrorMsg: Boolean = true, |
|
|
|
|
callback: (newVersion: String, updateBody: String, url: String) -> Unit |
|
|
|
|
callback: (newVersion: String, updateBody: String, url: String, fileName: String) -> Unit |
|
|
|
|
) { |
|
|
|
|
Coroutine.async(scope) { |
|
|
|
|
val lastReleaseUrl = "https://api.github.com/repos/gedoor/legado/releases/latest" |
|
|
|
@ -29,17 +28,19 @@ object AppUpdate { |
|
|
|
|
val rootDoc = jsonPath.parse(body) |
|
|
|
|
val tagName = rootDoc.readString("$.tag_name") |
|
|
|
|
?: throw NoStackTraceException("获取新版本出错") |
|
|
|
|
if (tagName > AppConst.appInfo.versionName) { |
|
|
|
|
if (tagName > "3.20.092208") { |
|
|
|
|
val updateBody = rootDoc.readString("$.body") |
|
|
|
|
?: throw NoStackTraceException("获取新版本出错") |
|
|
|
|
val downloadUrl = rootDoc.readString("$.assets[0].browser_download_url") |
|
|
|
|
?: throw NoStackTraceException("获取新版本出错") |
|
|
|
|
return@async Triple(tagName, updateBody, downloadUrl) |
|
|
|
|
val fileName = rootDoc.readString("$.assets[0].name") |
|
|
|
|
?: throw NoStackTraceException("获取新版本出错") |
|
|
|
|
return@async arrayOf(tagName, updateBody, downloadUrl, fileName) |
|
|
|
|
} else { |
|
|
|
|
throw NoStackTraceException("已是最新版本") |
|
|
|
|
} |
|
|
|
|
}.onSuccess { |
|
|
|
|
callback.invoke(it.first, it.second, it.third) |
|
|
|
|
callback.invoke(it[0], it[1], it[2], it[3]) |
|
|
|
|
}.onError { |
|
|
|
|
appCtx.toastOnUi("检测更新\n${it.localizedMessage}") |
|
|
|
|
} |
|
|
|
|