Save the store order only once the user arranges it (#2812)

* fix(stores): save the store order only once the user arranges it

* test(stores): exercise the tab save the hide toggle uses
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-18 01:33:11 -05:00
1 parent bf0260de61
commit ecd74fce79
3 files changed
+19 -3

No files matched your search

@@ -315,6 +315,13 @@ object SessionPrefs {
fun storesTabOrder(context: Context): List<String> = idList(prefs(context).getString("storesTabOrder", null))
/** An order nobody arranged stays unsaved, so it keeps following the default. */
fun saveStoresTabs(context: Context, order: List<String>, hidden: Set<String>, arranged: Boolean) {
if (arranged) setStoresTabOrderCustomized(context, true)
if (storesTabOrderCustomized(context)) setStoresTabOrder(context, order)
setStoresTabHidden(context, hidden)
}
private val LEGACY_STORES_TAB_ORDER = listOf("gog", "epic", "amazon", "xbox", "itch", "gamejolt", "battlenet", "ubisoft", "ea", "rockstar")
/**
@@ -163,9 +163,7 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
var arranging by remember { mutableStateOf(false) }
val shownStores = tabs.filter { it.shown }.map { it.store }
fun commitTabs(markCustomized: Boolean = false) {
SessionPrefs.setStoresTabOrder(ctx, tabs.map { it.store.id })
SessionPrefs.setStoresTabHidden(ctx, tabs.filterNot { it.shown }.map { it.store.id }.toSet())
if (markCustomized) SessionPrefs.setStoresTabOrderCustomized(ctx, true)
SessionPrefs.saveStoresTabs(ctx, tabs.map { it.store.id }, tabs.filterNot { it.shown }.map { it.store.id }.toSet(), markCustomized)
}
fun shiftTab(store: Store, delta: Int) {
val from = tabs.indexOfFirst { it.store == store }
@@ -42,4 +42,15 @@ class StoresTabOrderTest {
assertTrue(SessionPrefs.storesTabOrderCustomized(app))
assertEquals(mine, shown())
}
@Test
fun hidingAStoreLeavesTheOrderFollowingTheDefault() {
SessionPrefs.saveStoresTabs(app, defaults, setOf("itch"), arranged = false)
assertTrue(SessionPrefs.storesTabOrder(app).isEmpty())
val later = defaults.reversed()
SessionPrefs.settleStoresTabOrder(app, later)
assertFalse(SessionPrefs.storesTabOrderCustomized(app))
assertTrue(SessionPrefs.storesTabOrder(app).isEmpty())
assertEquals(setOf("itch"), SessionPrefs.storesTabHidden(app))
}
}