mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
Check itch updates per game from the game page instead of from the Library header
This commit is contained in:
5 files changed
+61
-34
No files matched your search
@@ -3,7 +3,6 @@ package com.droiddeck.launcher.stores.itch
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
@@ -25,11 +24,7 @@ internal object ItchUpdates {
|
||||
private const val GAP_MS = 1_000L
|
||||
|
||||
val available = mutableStateMapOf<String, ItchUpdate>()
|
||||
var checking by mutableStateOf(false)
|
||||
private set
|
||||
var done by mutableIntStateOf(0)
|
||||
private set
|
||||
var total by mutableIntStateOf(0)
|
||||
var checkingKey by mutableStateOf<String?>(null)
|
||||
private set
|
||||
|
||||
private val running = AtomicBoolean(false)
|
||||
@@ -79,7 +74,7 @@ internal object ItchUpdates {
|
||||
ItchPrefs.get(app).edit().putString(KEY_FOUND, encode(available.toMap())).apply()
|
||||
}
|
||||
|
||||
fun check(context: Context, force: Boolean) {
|
||||
fun check(context: Context) {
|
||||
val app = context.applicationContext
|
||||
if (!running.compareAndSet(false, true)) return
|
||||
val started = generation
|
||||
@@ -87,11 +82,10 @@ internal object ItchUpdates {
|
||||
try {
|
||||
restore(app)
|
||||
val prefs = ItchPrefs.get(app)
|
||||
if (!force && System.currentTimeMillis() - prefs.getLong(KEY_AT, 0L) < THROTTLE_MS) return@Thread
|
||||
if (System.currentTimeMillis() - prefs.getLong(KEY_AT, 0L) < THROTTLE_MS) return@Thread
|
||||
val key = ItchAuth.key(app)
|
||||
if (key.isBlank()) return@Thread
|
||||
val games = StoresState.installed.toList().filter { it.sidecar.store == Store.ITCH && it.sidecar.isInstalled }
|
||||
StoresState.post { total = games.size; done = 0; checking = true }
|
||||
val found = LinkedHashMap<String, ItchUpdate>()
|
||||
val answered = HashSet<String>()
|
||||
val snapshot = HashMap<String, Pair<String, String>>()
|
||||
@@ -109,7 +103,6 @@ internal object ItchUpdates {
|
||||
evaluate(uploads, extra["uploadId"].orEmpty(), game.sidecar.installVersion)?.let { found[game.key] = it }
|
||||
}
|
||||
} else failed = true
|
||||
StoresState.post { done = i + 1 }
|
||||
}
|
||||
if (started != generation) return@Thread
|
||||
StoresState.post {
|
||||
@@ -124,17 +117,47 @@ internal object ItchUpdates {
|
||||
}
|
||||
if (!failed && started == generation) prefs.edit().putLong(KEY_AT, System.currentTimeMillis()).apply()
|
||||
StoresState.logLine("itch.io: checked ${games.size} installed games, ${found.size} with updates")
|
||||
if (force) StoresState.post {
|
||||
val text = if (found.isNotEmpty()) app.getString(R.string.stores_itch_updates_found, found.size) else app.getString(R.string.upd_current_status)
|
||||
Toast.makeText(app, text, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
} finally {
|
||||
running.set(false)
|
||||
StoresState.post { checking = false }
|
||||
}
|
||||
}, "itch-updates").start()
|
||||
}
|
||||
|
||||
fun checkGame(context: Context, game: InstalledStoreGame) {
|
||||
val app = context.applicationContext
|
||||
if (checkingKey != null) return
|
||||
checkingKey = game.key
|
||||
val started = generation
|
||||
val version = game.sidecar.installVersion
|
||||
val uploadId = game.sidecar.extra["uploadId"].orEmpty()
|
||||
Thread({
|
||||
try {
|
||||
val key = ItchAuth.key(app)
|
||||
val extra = game.sidecar.extra
|
||||
val gameId = extra["gameId"].orEmpty()
|
||||
val uploads = if (key.isBlank() || gameId.isEmpty()) null else ItchApi.uploads(key, gameId, extra["downloadKeyId"].orEmpty())
|
||||
val found = evaluate(uploads, uploadId, version)
|
||||
StoresState.post {
|
||||
if (started != generation) return@post
|
||||
val now = StoresState.installed.firstOrNull { it.key == game.key }
|
||||
if (uploads != null && now != null && now.sidecar.installVersion == version && now.sidecar.extra["uploadId"].orEmpty() == uploadId) {
|
||||
if (found != null) available[game.key] = found else available.remove(game.key)
|
||||
save(app)
|
||||
}
|
||||
val text = when {
|
||||
uploads == null -> app.getString(R.string.stores_sync_failed)
|
||||
found != null -> app.getString(R.string.stores_itch_updates_found, 1)
|
||||
else -> app.getString(R.string.upd_current_status)
|
||||
}
|
||||
Toast.makeText(app, text, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
StoresState.logLine("itch.io: checked ${game.sidecar.title}, ${if (found != null) "update available" else "up to date"}")
|
||||
} finally {
|
||||
StoresState.post { checkingKey = null }
|
||||
}
|
||||
}, "itch-update-check").start()
|
||||
}
|
||||
|
||||
fun start(context: Context, game: InstalledStoreGame, update: ItchUpdate) {
|
||||
val app = context.applicationContext
|
||||
val root = game.folder.parentFile?.parentFile ?: return
|
||||
|
||||
@@ -205,7 +205,12 @@ internal fun GameDetail(
|
||||
GameHero(
|
||||
title, item, installed, game,
|
||||
Modifier.fillMaxWidth().heightIn(min = if (narrow) 170.dp else 210.dp).onGloballyPositioned { StoresMotion.heroAt = it.boundsInRoot() },
|
||||
corner = { if (!s.shortcutPicker) RemoveButton(title, game, installed, a) },
|
||||
corner = {
|
||||
if (!s.shortcutPicker) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (installed != null && installed.sidecar.store == Store.ITCH) ItchCheckButton(installed)
|
||||
RemoveButton(title, game, installed, a)
|
||||
}
|
||||
},
|
||||
scores = scores.takeIf { !stacked },
|
||||
) {
|
||||
HeroEyebrow(source, game, item, installed, download?.location ?: failed?.location)
|
||||
@@ -530,7 +535,7 @@ private fun EditArtButton(g: Library.SteamGame) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun IconAction(icon: androidx.compose.ui.graphics.vector.ImageVector, label: String, id: String, danger: Boolean = false, enabled: Boolean = true, onClick: () -> Unit) {
|
||||
internal fun IconAction(icon: androidx.compose.ui.graphics.vector.ImageVector, label: String, id: String, danger: Boolean = false, enabled: Boolean = true, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Refresh
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -18,6 +20,14 @@ import com.droiddeck.launcher.stores.InstalledStoreGame
|
||||
import com.droiddeck.launcher.stores.itch.ItchUpdate
|
||||
import com.droiddeck.launcher.stores.itch.ItchUpdates
|
||||
|
||||
@Composable
|
||||
internal fun ItchCheckButton(installed: InstalledStoreGame) {
|
||||
val ctx = LocalContext.current
|
||||
IconAction(Icons.Filled.Refresh, stringResource(R.string.store_check_updates), "game:check-updates", enabled = ItchUpdates.checkingKey == null) {
|
||||
ItchUpdates.checkGame(ctx, installed)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun ItchUpdateButton(installed: InstalledStoreGame, enabled: Boolean) {
|
||||
val ctx = LocalContext.current
|
||||
|
||||
@@ -38,7 +38,6 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.FilterAlt
|
||||
import androidx.compose.material.icons.filled.GridView
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Refresh
|
||||
import androidx.compose.material.icons.filled.Sort
|
||||
import androidx.compose.material.icons.filled.ViewList
|
||||
import androidx.compose.material.icons.filled.ViewModule
|
||||
@@ -198,7 +197,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
|
||||
val xboxFilter = if (source == Store.XBOX.id) XboxLibraryFilter.current else XboxLibraryFilter.ALL
|
||||
LaunchedEffect(source, itchSignedIn) { if (source == Store.ITCH.id && itchSignedIn) {
|
||||
ItchCollections.load(ctx)
|
||||
ItchUpdates.check(ctx, false)
|
||||
ItchUpdates.check(ctx)
|
||||
} }
|
||||
val collection = if (source == Store.ITCH.id) ItchCollections.chosen() else null
|
||||
val pool = if (collection == null) all else collectionEntries(all, ItchCollections.gamesOf(collection.id).orEmpty())
|
||||
@@ -473,10 +472,7 @@ private fun LibraryHeader(
|
||||
},
|
||||
) {
|
||||
if (showUninstalled != null || xbox) LibraryFilterButton(showUninstalled, onShowUninstalled, xbox)
|
||||
if (collections) {
|
||||
CollectionsButton()
|
||||
UpdatesButton()
|
||||
}
|
||||
if (collections) CollectionsButton()
|
||||
SortButton(s, a)
|
||||
ViewButton(s, a)
|
||||
GameFileFolderActions(s, a)
|
||||
@@ -731,14 +727,6 @@ private fun LibraryFilterButton(showUninstalled: Boolean?, onShowUninstalled: (B
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun UpdatesButton() {
|
||||
val ctx = LocalContext.current
|
||||
val title = stringResource(R.string.store_check_updates)
|
||||
val description = if (ItchUpdates.checking) title + " · " + ItchUpdates.done + "/" + ItchUpdates.total else title
|
||||
HeaderIconButton(description, Icons.Filled.Refresh, "itch-updates") { ItchUpdates.check(ctx, true) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CollectionsButton() {
|
||||
val pal = LocalPalette.current
|
||||
|
||||
Reference in new issue
Block a user