feat: AppUpdater can handle splits

This commit is contained in:
rebelonion 2024-04-05 19:21:00 -05:00
parent 8bde831794
commit cf7ccaebd1

View file

@ -8,6 +8,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Environment import android.os.Environment
import android.widget.TextView import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -85,13 +86,17 @@ object AppUpdater {
setPositiveButton(currContext()!!.getString(R.string.lets_go)) { setPositiveButton(currContext()!!.getString(R.string.lets_go)) {
MainScope().launch(Dispatchers.IO) { MainScope().launch(Dispatchers.IO) {
try { try {
client.get("https://api.github.com/repos/$repo/releases/tags/v$version") val apks =
.parsed<GithubResponse>().assets?.find { client.get("https://api.github.com/repos/$repo/releases/tags/v$version")
it.browserDownloadURL.endsWith("apk") .parsed<GithubResponse>().assets?.filter { it.browserDownloadURL.endsWith(".apk") }
}?.browserDownloadURL.apply { val apkToDownload =
if (this != null) activity.downloadUpdate(version, this) apks?.find { it.browserDownloadURL.contains(getCurrentABI()) }
else openLinkInBrowser("https://github.com/repos/$repo/releases/tag/v$version") ?: apks?.find { it.browserDownloadURL.contains("universal") }
} ?: apks?.first()
apkToDownload?.browserDownloadURL.apply {
if (this != null) activity.downloadUpdate(version, this)
else openLinkInBrowser("https://github.com/repos/$repo/releases/tag/v$version")
}
} catch (e: Exception) { } catch (e: Exception) {
logError(e) logError(e)
} }
@ -110,6 +115,16 @@ object AppUpdater {
} }
} }
/**
* Returns the ABI that the app is most likely running on.
* @return The primary ABI for the device.
*/
private fun getCurrentABI(): String {
return if (Build.SUPPORTED_ABIS.isNotEmpty()) {
Build.SUPPORTED_ABIS[0]
} else "Unknown"
}
private fun compareVersion(version: String): Boolean { private fun compareVersion(version: String): Boolean {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {