mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 21:15:43 +00:00
Show the cached Steam library while the store engine signs in (#3814)
The Steam store's owned-game list lived only in memory, so after every app start or update the uninstalled Steam games stayed missing until the engine had signed in and listed them. The list is now saved after each sync and shown at once on the next start; an account change, rejected sign-in or sign-out drops it.
This commit is contained in:
1 parent
4136f6b945
commit
4958dc4c93
1 file changed
+26
-4
@@ -17,6 +17,7 @@ import com.droiddeck.launcher.stores.StoreAccounts
|
||||
import com.droiddeck.launcher.stores.StoreBackend
|
||||
import com.droiddeck.launcher.stores.StoreInstallRoot
|
||||
import com.droiddeck.launcher.stores.StoreInstalls
|
||||
import com.droiddeck.launcher.stores.StoreLibraryCache
|
||||
import com.droiddeck.launcher.stores.StoreSizes
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
import com.droiddeck.launcher.stores.download.DownloadEntry
|
||||
@@ -29,6 +30,7 @@ import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/** Games land in the active client's own libraries, registered as the client does, and only while no session can run the client. */
|
||||
internal object SteamStore {
|
||||
@@ -59,6 +61,13 @@ internal object SteamStore {
|
||||
private val plans = ConcurrentHashMap<Int, Pair<String, Plan>>()
|
||||
private val work = Executors.newSingleThreadExecutor { r -> Thread(r, "steam-store") }
|
||||
@Volatile private var rejectedThisRun: String? = null
|
||||
/** Bumped when the account changes, so a library fetched for the previous one is neither shown nor cached. */
|
||||
private val accountGeneration = AtomicInteger()
|
||||
|
||||
internal fun forgetLibrary(context: Context) {
|
||||
accountGeneration.incrementAndGet()
|
||||
StoreLibraryCache.clear(context, Store.STEAM)
|
||||
}
|
||||
|
||||
fun key(appId: Int): String = "${Store.STEAM.id}:$appId"
|
||||
|
||||
@@ -115,6 +124,7 @@ internal object SteamStore {
|
||||
else StoreAccounts.write(context, Store.STEAM, JSONObject().put("display_name", saved.name).put("steam_id", saved.id))
|
||||
plans.clear()
|
||||
SteamEngine.forget()
|
||||
forgetLibrary(context)
|
||||
StoresState.post {
|
||||
StoresState.library.remove(Store.STEAM)
|
||||
StoresState.problems.remove(Store.STEAM)
|
||||
@@ -130,6 +140,7 @@ internal object SteamStore {
|
||||
rejectedThisRun = print
|
||||
if (error in SIGNED_OUT) prefs(context).edit().putString("rejected", print).apply()
|
||||
StoreAccounts.clear(context, Store.STEAM)
|
||||
forgetLibrary(context)
|
||||
StoresState.logLine("Steam: the saved sign-in was not accepted ($error)")
|
||||
StoresState.post {
|
||||
StoresState.accounts.remove(Store.STEAM)
|
||||
@@ -151,26 +162,34 @@ internal object SteamStore {
|
||||
val app = context.applicationContext
|
||||
if (force) plans.clear()
|
||||
work.execute {
|
||||
val gen = accountGeneration.get()
|
||||
// The engine signs in to Steam before it lists the games, which takes seconds; the last list shows meanwhile.
|
||||
StoreLibraryCache.load(app, Store.STEAM)?.let { cached ->
|
||||
post(gen) { if (StoresState.library[Store.STEAM] == null) StoresState.library[Store.STEAM] = cached }
|
||||
}
|
||||
val answer = SteamEngine.library(app)
|
||||
if (!answer.optBoolean("ok")) {
|
||||
val error = answer.optString("error")
|
||||
if (isSignInError(error)) signInFailed(app, error)
|
||||
else StoresState.post {
|
||||
else post(gen) {
|
||||
StoresState.problems[Store.STEAM] = errorText(app, answer)
|
||||
StoresState.library[Store.STEAM] = emptyList()
|
||||
if (StoresState.library[Store.STEAM] == null) StoresState.library[Store.STEAM] = emptyList()
|
||||
}
|
||||
return@execute
|
||||
}
|
||||
val art = runCatching { Library.steamLibraryArt(app).toMap() }.getOrDefault(emptyMap())
|
||||
val items = items(answer.optJSONArray("games"), art)
|
||||
StoresState.logLine("Steam: library has ${items.size} games")
|
||||
StoresState.post {
|
||||
post(gen) {
|
||||
StoresState.problems.remove(Store.STEAM)
|
||||
StoresState.library[Store.STEAM] = items
|
||||
}
|
||||
StoreLibraryCache.save(app, Store.STEAM, items) { accountGeneration.get() == gen }
|
||||
}
|
||||
}
|
||||
|
||||
private fun post(gen: Int, block: () -> Unit) = StoresState.post { if (accountGeneration.get() == gen) block() }
|
||||
|
||||
private fun items(games: JSONArray?, art: Map<Int, File>): List<CatalogItem> {
|
||||
val out = ArrayList<CatalogItem>()
|
||||
for (i in 0 until (games?.length() ?: 0)) {
|
||||
@@ -379,7 +398,10 @@ internal object SteamBackend : StoreBackend {
|
||||
StoresState.logLine("Steam: sign in from the Steam client")
|
||||
}
|
||||
|
||||
override fun signOut(context: Context) = SteamEngine.forget()
|
||||
override fun signOut(context: Context) {
|
||||
SteamEngine.forget()
|
||||
SteamStore.forgetLibrary(context)
|
||||
}
|
||||
|
||||
override fun syncLibrary(context: Context, force: Boolean) = SteamStore.syncLibrary(context, force)
|
||||
|
||||
|
||||
Reference in new issue
Block a user