mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 22:05:59 +00:00
fix: check a Battle.net game for updates again when the last check failed
This commit is contained in:
1 parent
24f0b97c08
commit
db56cff880
2 files changed
+19
-4
No files matched your search
@@ -45,8 +45,8 @@ object BattleNetInstall {
|
||||
"zhTW", "zhCN", "thTH", "arSA",
|
||||
)
|
||||
|
||||
private val checks = Executors.newSingleThreadExecutor { r -> Thread(r, "battlenet-updates") }
|
||||
private val checkedAt = HashMap<String, Long>()
|
||||
internal val checks = Executors.newSingleThreadExecutor { r -> Thread(r, "battlenet-updates") }
|
||||
internal val checkedAt = HashMap<String, Long>()
|
||||
|
||||
val updates = mutableStateMapOf<String, Boolean>()
|
||||
|
||||
@@ -177,10 +177,13 @@ object BattleNetInstall {
|
||||
if (!force && now - (checkedAt[id] ?: 0L) < CHECK_AGAIN_MS) return
|
||||
checkedAt[id] = now
|
||||
}
|
||||
fun retryLater() = synchronized(checkedAt) { if (checkedAt[id] == now) checkedAt.remove(id) }
|
||||
checks.execute {
|
||||
val local = runCatching { buildKey(File(folder, BUILD_INFO).readText()) }.getOrNull() ?: return@execute
|
||||
val local = runCatching { buildKey(File(folder, BUILD_INFO).readText()) }.getOrNull()
|
||||
?: return@execute retryLater()
|
||||
val latest = runCatching { latestBuild(fetch(VERSIONS.format(Locale.ROOT, local.first, product)), local.first) }
|
||||
.onFailure { Log.w(TAG, "versions of $product: ${it.javaClass.simpleName}") }.getOrNull() ?: return@execute
|
||||
.onFailure { Log.w(TAG, "versions of $product: ${it.javaClass.simpleName}") }.getOrNull()
|
||||
?: return@execute retryLater()
|
||||
val behind = latest != local.second
|
||||
Log.i(TAG, "$id: ${if (behind) "update available" else "up to date"}")
|
||||
StoresState.post { if (behind) updates[id] = true else updates.remove(id) }
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.nio.file.Files
|
||||
import java.util.Locale
|
||||
|
||||
class BattleNetInstallTest {
|
||||
@@ -64,6 +65,17 @@ class BattleNetInstallTest {
|
||||
assertFalse(BattleNetInstall.headless(CatalogItem(Store.EPIC, "gryphon", "Warcraft Rumble", null)))
|
||||
}
|
||||
|
||||
@Test fun aCheckThatCouldNotRunIsTriedAgainNextTime() {
|
||||
val folder = Files.createTempDirectory("bnet").toFile()
|
||||
try {
|
||||
BattleNetInstall.check("gryphon", folder, false)
|
||||
BattleNetInstall.checks.submit {}.get()
|
||||
assertFalse(synchronized(BattleNetInstall.checkedAt) { "gryphon" in BattleNetInstall.checkedAt })
|
||||
} finally {
|
||||
folder.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theAgentStatusPicksTheDownloadStep() {
|
||||
assertEquals(BattleNetInstall.Step.PREPARING, BattleNetInstall.step(1008, 0, 0, 0))
|
||||
assertEquals(BattleNetInstall.Step.PREPARING, BattleNetInstall.step(1003, 500, 0, 0))
|
||||
|
||||
Reference in new issue
Block a user