fix: proper install up-to-date checks

This commit is contained in:
rushiiMachine 2025-02-07 19:43:28 -08:00
parent 39c3ed7da2
commit 8214d6baa0
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420
2 changed files with 22 additions and 12 deletions

View file

@ -27,6 +27,7 @@ import com.aliucord.manager.util.launchBlock
import com.aliucord.manager.util.showToast
import com.github.diamondminer88.zip.ZipReader
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.launch
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
@ -45,8 +46,12 @@ class HomeModel(
private var remoteDataJson: BuildInfo? = null
init {
// fetchInstallations() is called from UI
fetchSupportedVersion()
// fetchInstallations() is also called from UI first to ensure fast TTI
screenModelScope.launch {
fetchSupportedVersion()
fetchInstallations() // Re-fetch installations to set the up-to-date statuses
}
}
fun launchApp(packageName: String) {
@ -147,11 +152,16 @@ class HomeModel(
)
}
private fun fetchSupportedVersion() = screenModelScope.launchBlock {
suspend fun fetchSupportedVersion() {
github.getDataJson().fold(
success = {
val versionCode = it.discordVersionCode.toIntOrNull() ?: return@fold
val versionCode = it.discordVersionCode.toIntOrNull()
if (versionCode == null) {
supportedVersion = DiscordVersion.Error
return
}
remoteDataJson = it
supportedVersion = DiscordVersion.Existing(
type = DiscordVersion.parseVersionType(versionCode),
name = it.discordVersionName.split("-")[0].trim(),
@ -166,13 +176,14 @@ class HomeModel(
}
private fun isInstallationUpToDate(pkg: PackageInfo): Boolean {
val remoteBuildData = remoteDataJson ?: return true
// `longVersionCode` is unnecessary since Discord doesn't use `versionCodeMajor`
@Suppress("DEPRECATION")
val versionCode = pkg.versionCode
// Check if the base APK version is a mismatch
val supportedVersion = (supportedVersion as? DiscordVersion.Existing) ?: return true
if (supportedVersion.rawCode != versionCode) return false
if (remoteBuildData.discordVersionCode.toIntOrNull() != versionCode) return false
// Try to parse install metadata. If none present, install was made via legacy installer.
val apkPath = pkg.applicationInfo?.publicSourceDir ?: return false
@ -188,10 +199,8 @@ class HomeModel(
}
// Check that all the installation components are up-to-date
val remoteBuildData = remoteDataJson ?: return true
// TODO: check for aliuhook version too once aliuhook starts using semver
return remoteBuildData.injectorVersion > installMetadata.injectorVersion ||
remoteBuildData.patchesVersion > installMetadata.patchesVersion
return remoteBuildData.injectorVersion == installMetadata.injectorVersion &&
remoteBuildData.patchesVersion == installMetadata.patchesVersion
}
}

View file

@ -22,7 +22,8 @@ sealed interface DiscordVersion : Comparable<DiscordVersion>, Parcelable {
val name: String,
val code: Int,
) : DiscordVersion {
val rawCode: Int
/** The code without the release type. (ie. 126021 -> 12621) */
val typelessCode: Int
get() = (code / 1000 * 100) + code % 100
}
@ -32,7 +33,7 @@ sealed interface DiscordVersion : Comparable<DiscordVersion>, Parcelable {
is None -> 0
is Existing -> {
if (other is Existing) {
other.rawCode.compareTo(rawCode)
other.typelessCode.compareTo(typelessCode)
} else {
0
}