@@ -16,8 +16,10 @@ import cafe.adriel.voyager.core.model.screenModelScope
16
16
import cafe.adriel.voyager.navigator.Navigator
17
17
import com.aliucord.manager.BuildConfig
18
18
import com.aliucord.manager.R
19
+ import com.aliucord.manager.domain.repository.AliucordMavenRepository
19
20
import com.aliucord.manager.domain.repository.GithubRepository
20
21
import com.aliucord.manager.network.dto.BuildInfo
22
+ import com.aliucord.manager.network.utils.SemVer
21
23
import com.aliucord.manager.network.utils.fold
22
24
import com.aliucord.manager.patcher.InstallMetadata
23
25
import com.aliucord.manager.ui.screens.patchopts.PatchOptions
@@ -35,6 +37,7 @@ import kotlinx.serialization.json.decodeFromStream
35
37
class HomeModel (
36
38
private val application : Application ,
37
39
private val github : GithubRepository ,
40
+ private val maven : AliucordMavenRepository ,
38
41
private val json : Json ,
39
42
) : ScreenModel {
40
43
var supportedVersion by mutableStateOf<DiscordVersion >(DiscordVersion .None )
@@ -44,12 +47,13 @@ class HomeModel(
44
47
private set
45
48
46
49
private var remoteDataJson: BuildInfo ? = null
50
+ private var latestAliuhookVersion: SemVer ? = null
47
51
48
52
init {
49
53
// fetchInstallations() is also called from UI first to ensure fast TTI
50
54
51
55
screenModelScope.launch {
52
- fetchSupportedVersion ()
56
+ fetchRemoteData ()
53
57
fetchInstallations() // Re-fetch installations to set the up-to-date statuses
54
58
}
55
59
}
@@ -152,7 +156,7 @@ class HomeModel(
152
156
)
153
157
}
154
158
155
- suspend fun fetchSupportedVersion () {
159
+ suspend fun fetchRemoteData () {
156
160
github.getDataJson().fold(
157
161
success = {
158
162
val versionCode = it.discordVersionCode.toIntOrNull()
@@ -169,15 +173,24 @@ class HomeModel(
169
173
)
170
174
},
171
175
fail = {
172
- Log .e (BuildConfig .TAG , Log .getStackTraceString(it) )
176
+ Log .w (BuildConfig .TAG , " Failed to fetch remote build data " , it )
173
177
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
+ },
175
187
)
176
188
}
177
189
178
190
private fun isInstallationUpToDate (pkg : PackageInfo ): Boolean {
179
191
// Assume up-to-date when remote data hasn't been fetched yet
180
192
val remoteBuildData = remoteDataJson ? : return true
193
+ val latestAliuhookVersion = latestAliuhookVersion ? : return true
181
194
182
195
// `longVersionCode` is unnecessary since Discord doesn't use `versionCodeMajor`
183
196
@Suppress(" DEPRECATION" )
@@ -200,8 +213,8 @@ class HomeModel(
200
213
}
201
214
202
215
// 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
206
219
}
207
220
}
0 commit comments