Skip to content

Commit 4cd0209

Browse files
committed
fix: auto check app update
1 parent 4830e1f commit 4cd0209

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

app/src/main/kotlin/li/songe/gkd/MainViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class MainViewModel : BaseViewModel(), OnSimpleLife {
368368
clearCache()
369369
}
370370

371-
if (updateStatus != null && termsAcceptedFlow.value) {
371+
if (termsAcceptedFlow.value && updateStatus?.canRecheck == true) {
372372
updateStatus.checkUpdate()
373373
}
374374

app/src/main/kotlin/li/songe/gkd/util/Upgrade.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import li.songe.gkd.store.createAnyFlow
3434
import li.songe.gkd.store.storeFlow
3535
import java.io.File
3636
import java.net.URI
37+
import kotlin.time.Duration.Companion.days
3738

3839

3940
private val UPDATE_URL: String
@@ -56,6 +57,8 @@ data class VersionLog(
5657
val desc: String,
5758
)
5859

60+
private var lastCheckTime = 0L
61+
5962
class UpdateStatus(val scope: CoroutineScope) {
6063
private val checkUpdatingMutex = MutexState()
6164
val checkUpdatingFlow
@@ -73,9 +76,12 @@ class UpdateStatus(val scope: CoroutineScope) {
7376
}
7477
private var lastManual = false
7578

76-
fun checkUpdate(manual: Boolean = false) = scope.launchTry(Dispatchers.IO, silent = manual) {
79+
val canRecheck get() = System.currentTimeMillis() - lastCheckTime > 1.days.inWholeMilliseconds
80+
81+
fun checkUpdate(manual: Boolean = false) = scope.launchTry(Dispatchers.IO, silent = !manual) {
7782
lastManual = manual
7883
checkUpdatingMutex.whenUnLock {
84+
lastCheckTime = System.currentTimeMillis()
7985
if (!NetworkUtils.isAvailable()) {
8086
error("网络不可用")
8187
}

0 commit comments

Comments
 (0)