fix: auto check app update

This commit is contained in:
二刺螈
2026-04-17 18:15:29 +08:00
parent 4830e1f42e
commit 4cd0209507
2 changed files with 8 additions and 2 deletions

View File

@@ -368,7 +368,7 @@ class MainViewModel : BaseViewModel(), OnSimpleLife {
clearCache()
}
if (updateStatus != null && termsAcceptedFlow.value) {
if (termsAcceptedFlow.value && updateStatus?.canRecheck == true) {
updateStatus.checkUpdate()
}

View File

@@ -34,6 +34,7 @@ import li.songe.gkd.store.createAnyFlow
import li.songe.gkd.store.storeFlow
import java.io.File
import java.net.URI
import kotlin.time.Duration.Companion.days
private val UPDATE_URL: String
@@ -56,6 +57,8 @@ data class VersionLog(
val desc: String,
)
private var lastCheckTime = 0L
class UpdateStatus(val scope: CoroutineScope) {
private val checkUpdatingMutex = MutexState()
val checkUpdatingFlow
@@ -73,9 +76,12 @@ class UpdateStatus(val scope: CoroutineScope) {
}
private var lastManual = false
fun checkUpdate(manual: Boolean = false) = scope.launchTry(Dispatchers.IO, silent = manual) {
val canRecheck get() = System.currentTimeMillis() - lastCheckTime > 1.days.inWholeMilliseconds
fun checkUpdate(manual: Boolean = false) = scope.launchTry(Dispatchers.IO, silent = !manual) {
lastManual = manual
checkUpdatingMutex.whenUnLock {
lastCheckTime = System.currentTimeMillis()
if (!NetworkUtils.isAvailable()) {
error("网络不可用")
}