mirror of
https://mirror.skon.top/github.com/gkd-kit/gkd
synced 2026-04-20 21:00:12 +08:00
fix: auto check app update
This commit is contained in:
@@ -368,7 +368,7 @@ class MainViewModel : BaseViewModel(), OnSimpleLife {
|
||||
clearCache()
|
||||
}
|
||||
|
||||
if (updateStatus != null && termsAcceptedFlow.value) {
|
||||
if (termsAcceptedFlow.value && updateStatus?.canRecheck == true) {
|
||||
updateStatus.checkUpdate()
|
||||
}
|
||||
|
||||
|
||||
@@ -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("网络不可用")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user