Skip to content

Commit bb0d389

Browse files
committed
feat: check Aliuhook version when determining if installation up-to-date
1 parent 534ee3c commit bb0d389

File tree

1 file changed

+20
-7
lines changed
  • app/src/main/kotlin/com/aliucord/manager/ui/screens/home

1 file changed

+20
-7
lines changed

app/src/main/kotlin/com/aliucord/manager/ui/screens/home/HomeModel.kt

+20-7
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import cafe.adriel.voyager.core.model.screenModelScope
1616
import cafe.adriel.voyager.navigator.Navigator
1717
import com.aliucord.manager.BuildConfig
1818
import com.aliucord.manager.R
19+
import com.aliucord.manager.domain.repository.AliucordMavenRepository
1920
import com.aliucord.manager.domain.repository.GithubRepository
2021
import com.aliucord.manager.network.dto.BuildInfo
22+
import com.aliucord.manager.network.utils.SemVer
2123
import com.aliucord.manager.network.utils.fold
2224
import com.aliucord.manager.patcher.InstallMetadata
2325
import com.aliucord.manager.ui.screens.patchopts.PatchOptions
@@ -35,6 +37,7 @@ import kotlinx.serialization.json.decodeFromStream
3537
class HomeModel(
3638
private val application: Application,
3739
private val github: GithubRepository,
40+
private val maven: AliucordMavenRepository,
3841
private val json: Json,
3942
) : ScreenModel {
4043
var supportedVersion by mutableStateOf<DiscordVersion>(DiscordVersion.None)
@@ -44,12 +47,13 @@ class HomeModel(
4447
private set
4548

4649
private var remoteDataJson: BuildInfo? = null
50+
private var latestAliuhookVersion: SemVer? = null
4751

4852
init {
4953
// fetchInstallations() is also called from UI first to ensure fast TTI
5054

5155
screenModelScope.launch {
52-
fetchSupportedVersion()
56+
fetchRemoteData()
5357
fetchInstallations() // Re-fetch installations to set the up-to-date statuses
5458
}
5559
}
@@ -152,7 +156,7 @@ class HomeModel(
152156
)
153157
}
154158

155-
suspend fun fetchSupportedVersion() {
159+
suspend fun fetchRemoteData() {
156160
github.getDataJson().fold(
157161
success = {
158162
val versionCode = it.discordVersionCode.toIntOrNull()
@@ -169,15 +173,24 @@ class HomeModel(
169173
)
170174
},
171175
fail = {
172-
Log.e(BuildConfig.TAG, Log.getStackTraceString(it))
176+
Log.w(BuildConfig.TAG, "Failed to fetch remote build data", it)
173177
supportedVersion = DiscordVersion.Error
174-
}
178+
},
179+
)
180+
181+
maven.getAliuhookVersion().fold(
182+
success = { latestAliuhookVersion = it },
183+
fail = {
184+
Log.w(BuildConfig.TAG, "Failed to fetch latest Aliuhook version", it)
185+
supportedVersion = DiscordVersion.Error
186+
},
175187
)
176188
}
177189

178190
private fun isInstallationUpToDate(pkg: PackageInfo): Boolean {
179191
// Assume up-to-date when remote data hasn't been fetched yet
180192
val remoteBuildData = remoteDataJson ?: return true
193+
val latestAliuhookVersion = latestAliuhookVersion ?: return true
181194

182195
// `longVersionCode` is unnecessary since Discord doesn't use `versionCodeMajor`
183196
@Suppress("DEPRECATION")
@@ -200,8 +213,8 @@ class HomeModel(
200213
}
201214

202215
// Check that all the installation components are up-to-date
203-
// TODO: check for aliuhook version too once aliuhook starts using semver
204-
return remoteBuildData.injectorVersion == installMetadata.injectorVersion &&
205-
remoteBuildData.patchesVersion == installMetadata.patchesVersion
216+
return remoteBuildData.injectorVersion == installMetadata.injectorVersion
217+
&& remoteBuildData.patchesVersion == installMetadata.patchesVersion
218+
&& latestAliuhookVersion == installMetadata.aliuhookVersion
206219
}
207220
}

0 commit comments

Comments
 (0)