diff --git a/app/src/main/java/io/legato/kazusa/help/update/AppReleaseInfo.kt b/app/src/main/java/io/legato/kazusa/help/update/AppReleaseInfo.kt index 187aa488f..c9c12f594 100644 --- a/app/src/main/java/io/legato/kazusa/help/update/AppReleaseInfo.kt +++ b/app/src/main/java/io/legato/kazusa/help/update/AppReleaseInfo.kt @@ -1,5 +1,6 @@ package io.legato.kazusa.help.update +import android.os.Build import androidx.annotation.Keep import com.google.gson.annotations.SerializedName import io.legato.kazusa.exception.NoStackTraceException @@ -39,17 +40,25 @@ data class GithubRelease( val createdAt: String? ) { fun gitReleaseToAppReleaseInfo(): List { - val version = tagName // 直接用 release 的 tag_name 作为版本号 assets ?: throw NoStackTraceException("获取新版本出错") + val version = tagName + val abi = Build.SUPPORTED_ABIS.firstOrNull() ?: "" + val abiSuffix = when { + abi.contains("arm64") -> "arm64-v8a" + abi.contains("armeabi") -> "armeabi-v7a" + else -> "" + } + return assets .filter { it.isValid } + .filter { asset -> + abiSuffix.isEmpty() || asset.name.contains(abiSuffix, ignoreCase = true) + } .map { it.assetToAppReleaseInfo(isPreRelease, body, version) } } - } - @Keep data class Asset( @SerializedName("browser_download_url") @@ -71,7 +80,6 @@ data class Asset( fun assetToAppReleaseInfo(preRelease: Boolean, note: String, version: String): AppReleaseInfo { val instant = Instant.parse(createdAt) val timestamp: Long = instant.toEpochMilli() - val appVariant = if (preRelease) AppVariant.BETA_RELEASE else AppVariant.OFFICIAL return AppReleaseInfo( @@ -81,8 +89,7 @@ data class Asset( name = name, downloadUrl = apkUrl, assetUrl = url, - versionName = version // 直接传入 tagName + versionName = version ) } - -} +} \ No newline at end of file diff --git a/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt b/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt index e174a00ea..bf80356e1 100644 --- a/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt +++ b/app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt @@ -41,7 +41,6 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface { releases.filter { it.isPreRelease } .flatMap { it.gitReleaseToAppReleaseInfo() } .sortedByDescending { it.createdAt } - .also { Log.d("AppUpdate", "filtered beta releases.size=${it.size}") } } else { val release = GSON.fromJsonObject(body) .getOrElse { throw NoStackTraceException("获取新版本出错 ${it.localizedMessage}") } @@ -130,5 +129,4 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface { fun String.versionCompare(other: String): Int { return SemVer.parse(this).compareTo(SemVer.parse(other)) } -} - +} \ No newline at end of file diff --git a/app/src/main/java/io/legato/kazusa/ui/about/UpdateDialog.kt b/app/src/main/java/io/legato/kazusa/ui/about/UpdateDialog.kt index 550b77355..64c5e49f4 100644 --- a/app/src/main/java/io/legato/kazusa/ui/about/UpdateDialog.kt +++ b/app/src/main/java/io/legato/kazusa/ui/about/UpdateDialog.kt @@ -69,28 +69,15 @@ class UpdateDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_update) { } binding.btnUpdate.setOnClickListener { - val urlPrefix = arguments?.getString("url") - val baseName = arguments?.getString("name")?.removeSuffix(".apk") + val url = arguments?.getString("url") + val fileName = arguments?.getString("name") - if (urlPrefix == null || baseName == null) { + if (url.isNullOrBlank() || fileName.isNullOrBlank()) { toastOnUi("下载信息不完整") return@setOnClickListener } - // 获取当前 ABI 后缀 - val abi = Build.SUPPORTED_ABIS.firstOrNull() ?: "" - val abiSuffix = when { - abi.contains("arm64") -> "arm64-v8a" - abi.contains("armeabi") -> "armeabi-v7a" - else -> "" - } - - // 拼接文件名和下载链接 - val fileName = "${baseName}_$abiSuffix.apk" - val fullUrl = urlPrefix - .substringBeforeLast("/") + "/" + fileName - - Download.start(requireContext(), fullUrl, fileName) + Download.start(requireContext(), url, fileName) toastOnUi("开始下载: $fileName") }