From e7907d0c7414e418a4ab87fcce470d7c23343b67 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Wed, 28 Oct 2026 01:08:33 +0300 Subject: [PATCH] Check itch updates per game from the game page instead of from the Library header --- .../launcher/stores/itch/ItchUpdates.kt | 53 +++++++++++++------ .../com/droiddeck/launcher/ui/GameDetail.kt | 9 +++- .../droiddeck/launcher/ui/ItchUpdateButton.kt | 10 ++++ .../com/droiddeck/launcher/ui/LibraryPage.kt | 16 +----- docs/development/itch-updates.md | 7 +-- 5 files changed, 61 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt index e178ed5a24..a23195780c 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt @@ -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() - var checking by mutableStateOf(false) - private set - var done by mutableIntStateOf(0) - private set - var total by mutableIntStateOf(0) + var checkingKey by mutableStateOf(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() val answered = HashSet() val snapshot = HashMap>() @@ -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 diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt index e46a15b239..8cd08db1a4 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt @@ -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() } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt b/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt index 37151db81a..2e254a5b9d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt @@ -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 diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt index 1353e38228..a180e25113 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt @@ -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 diff --git a/docs/development/itch-updates.md b/docs/development/itch-updates.md index f2f4e49ce1..a9dfabaea1 100644 --- a/docs/development/itch-updates.md +++ b/docs/development/itch-updates.md @@ -2,7 +2,7 @@ An installed itch game is checked against the uploads itch lists for it. A game with an update shows an Update label on its Library tile and an Update button on its game page. A Check for updates button sits -in the Library header while the itch chip is selected. +in the top right of an installed itch game's page, next to the delete button, and checks that game only. ## Detection @@ -15,9 +15,10 @@ The install record (`.droiddeck-store.json`) keeps three things from the install - an install without an `uploadId` compares the newest Windows upload's stamp; - an unknown installed version or no answer from itch never reports an update. -The check walks the installed itch games one at a time, one second apart, and logs +The automatic check walks the installed itch games one at a time, one second apart, and logs `itch.io: checked installed games, with updates`. It runs when the itch tab opens, at most every -six hours, and whenever the header button is pressed. A game itch did not answer for keeps its last +six hours. The button on a game page checks only that game, at any time, answers with a toast ("Update +available", "Up to date" or "Sync failed") and logs `itch.io: checked , ...`. A game itch did not answer for keeps its last result, and the six-hour clock only advances after a fully answered pass. Results are kept in the itch preferences until the update is installed or the account signs out.