Compare commits

..
Author SHA1 Message Date
maxjivi05 51001847b6 Keep the Steam install picker state out of the Steam engine object
The picker state lived on SteamStore, which is first touched from the
background stores refresh thread. On the Compose runtime in use, a state
object created outside a snapshot while the composition holds an open
snapshot is unreadable inside it, so the front end crashed on startup
with "Reading a state that was created after the snapshot was taken".
The state now lives on StoresState next to the other UI-facing store
state, and SteamStore holds no Compose state.
2026-11-29 23:31:02 -05:00
4 changed files with 41 additions and 7 deletions

No files matched your search

@@ -121,6 +121,8 @@ object StoresState {
var unfinished by mutableStateOf<List<StoreInstallRoot.Unfinished>>(emptyList())
internal set
var steamPicking by mutableStateOf<CatalogItem?>(null)
fun isUnfinished(item: CatalogItem): Boolean = unfinished.any {
it.store == item.store && (it.id == item.id || (it.id == null && it.folder.name == StoreInstallRoot.folderName(item.title, item.id)))
}
@@ -6,9 +6,6 @@ import android.net.Uri
import android.util.Log
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.droiddeck.launcher.R
import com.droiddeck.launcher.frontend.Library
import com.droiddeck.launcher.session.SessionService
@@ -46,8 +43,6 @@ internal object SteamStore {
/** InvalidPassword, AccessDenied, AccountNotFound, Revoked, Expired, AccountLogonDenied. */
private val REFUSALS = setOf(5, 15, 18, 26, 27, 63)
var picking by mutableStateOf<CatalogItem?>(null)
class Plan(val installDir: String, val downloadBytes: Long, val installBytes: Long, val buildId: String, val linuxBuild: Boolean) {
companion object {
fun of(json: JSONObject): Plan? {
@@ -222,7 +217,7 @@ internal object SteamStore {
toast(context, R.string.steam_store_close_steam)
return
}
picking = item
StoresState.steamPicking = item
}
fun install(context: Context, item: CatalogItem, target: SteamClient.Target) {
@@ -847,7 +847,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
com.droiddeck.launcher.stores.StoresState.pendingInstall?.let { item -> StoreTheme(item.store) { InstallWhere(item) } }
com.droiddeck.launcher.stores.StoresState.itchPicking?.let { item -> StoreTheme(item.store) { ItchBuildPicker(item) { com.droiddeck.launcher.stores.StoresState.itchPicking = null } } }
com.droiddeck.launcher.stores.StoresState.gameJoltPicking?.let { item -> StoreTheme(item.store) { GameJoltBuildPicker(item) { com.droiddeck.launcher.stores.StoresState.gameJoltPicking = null } } }
com.droiddeck.launcher.stores.steam.SteamStore.picking?.let { item -> StoreTheme(item.store) { SteamInstallWhereDialog(item) { com.droiddeck.launcher.stores.steam.SteamStore.picking = null } } }
com.droiddeck.launcher.stores.StoresState.steamPicking?.let { item -> StoreTheme(item.store) { SteamInstallWhereDialog(item) { com.droiddeck.launcher.stores.StoresState.steamPicking = null } } }
StepsLayer(screenAt)
UiZooSheet()
SessionDrawerPreview(s.secondScreenDisplays)
@@ -0,0 +1,37 @@
package com.droiddeck.launcher.stores.steam
import androidx.compose.runtime.State
import androidx.compose.runtime.snapshots.Snapshot
import androidx.compose.runtime.snapshots.StateObject
import com.droiddeck.launcher.stores.StoresState
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import kotlin.concurrent.thread
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33], manifest = Config.NONE)
class SteamPickingSnapshotTest {
@Test
fun theInstallPickerIsReadableInASnapshotOpenedBeforeTheSteamEngineStarts() {
StoresState.steamPicking = null
val snapshot = Snapshot.takeMutableSnapshot()
try {
thread { SteamStore.hashCode() }.join()
assertNull(snapshot.enter { StoresState.steamPicking })
} finally {
snapshot.dispose()
}
}
@Test
fun theSteamEngineHoldsNoComposeState() {
val stateFields = SteamStore::class.java.declaredFields.filter {
StateObject::class.java.isAssignableFrom(it.type) || State::class.java.isAssignableFrom(it.type)
}
assertTrue(stateFields.joinToString { it.name }, stateFields.isEmpty())
}
}