Tweak the app updater logic and add FOSS build support (#1843)

This commit is contained in:
AntsyLich
2025-03-18 19:36:16 +06:00
committed by GitHub
parent 7028b8673a
commit 28093935d8
11 changed files with 85 additions and 75 deletions

View File

@@ -25,7 +25,7 @@ class GetApplicationRelease(
return Result.NoNewUpdate
}
val release = service.latest(arguments.repository)
val release = service.latest(arguments) ?: return Result.NoNewUpdate
lastChecked.set(now.toEpochMilli())
@@ -73,6 +73,7 @@ class GetApplicationRelease(
}
data class Arguments(
val isFoss: Boolean,
val isPreview: Boolean,
val commitCount: Int,
val versionName: String,

View File

@@ -1,7 +1,5 @@
package tachiyomi.domain.release.model
import android.os.Build
/**
* Contains information about the latest release.
*/
@@ -9,27 +7,5 @@ data class Release(
val version: String,
val info: String,
val releaseLink: String,
private val assets: List<String>,
) {
/**
* Get download link of latest release from the assets.
* @return download link of latest release.
*/
fun getDownloadLink(): String {
val apkVariant = when (Build.SUPPORTED_ABIS[0]) {
"arm64-v8a" -> "-arm64-v8a"
"armeabi-v7a" -> "-armeabi-v7a"
"x86" -> "-x86"
"x86_64" -> "-x86_64"
else -> ""
}
return assets.find { it.contains("mihon$apkVariant-") } ?: assets[0]
}
/**
* Assets class containing download url.
*/
data class Assets(val downloadLink: String)
}
val downloadLink: String,
)

View File

@@ -1,8 +1,9 @@
package tachiyomi.domain.release.service
import tachiyomi.domain.release.interactor.GetApplicationRelease
import tachiyomi.domain.release.model.Release
interface ReleaseService {
suspend fun latest(repository: String): Release
suspend fun latest(arguments: GetApplicationRelease.Arguments): Release?
}

View File

@@ -16,9 +16,9 @@ import java.time.Instant
class GetApplicationReleaseTest {
lateinit var getApplicationRelease: GetApplicationRelease
lateinit var releaseService: ReleaseService
lateinit var preference: Preference<Long>
private lateinit var getApplicationRelease: GetApplicationRelease
private lateinit var releaseService: ReleaseService
private lateinit var preference: Preference<Long>
@BeforeEach
fun beforeEach() {
@@ -39,13 +39,14 @@ class GetApplicationReleaseTest {
"r2000",
"info",
"http://example.com/release_link",
listOf("http://example.com/assets"),
"http://example.com/release_link.apk",
)
coEvery { releaseService.latest(any()) } returns release
val result = getApplicationRelease.await(
GetApplicationRelease.Arguments(
isFoss = false,
isPreview = true,
commitCount = 1000,
versionName = "",
@@ -67,13 +68,14 @@ class GetApplicationReleaseTest {
"v2.0.0",
"info",
"http://example.com/release_link",
listOf("http://example.com/assets"),
"http://example.com/release_link.apk",
)
coEvery { releaseService.latest(any()) } returns release
val result = getApplicationRelease.await(
GetApplicationRelease.Arguments(
isFoss = false,
isPreview = false,
commitCount = 0,
versionName = "v1.0.0",
@@ -95,13 +97,14 @@ class GetApplicationReleaseTest {
"v1.0.0",
"info",
"http://example.com/release_link",
listOf("http://example.com/assets"),
"http://example.com/release_link.apk",
)
coEvery { releaseService.latest(any()) } returns release
val result = getApplicationRelease.await(
GetApplicationRelease.Arguments(
isFoss = false,
isPreview = false,
commitCount = 0,
versionName = "v2.0.0",
@@ -121,13 +124,14 @@ class GetApplicationReleaseTest {
"v1.0.0",
"info",
"http://example.com/release_link",
listOf("http://example.com/assets"),
"http://example.com/release_link.apk",
)
coEvery { releaseService.latest(any()) } returns release
val result = getApplicationRelease.await(
GetApplicationRelease.Arguments(
isFoss = false,
isPreview = false,
commitCount = 0,
versionName = "v2.0.0",