mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
fix(stores): restore store capabilities in Library (#1586)
This commit is contained in:
1 parent
c71ba6da96
commit
5978a13f09
7 files changed
+284
-47
No files matched your search
@@ -569,6 +569,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
}
|
||||
FlightsLayer(screenAt)
|
||||
GamesDialogs(a, s.steamGames)
|
||||
StoreTheme(com.droiddeck.launcher.stores.Store.XBOX) { XboxStoreDialogs() }
|
||||
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 } } }
|
||||
StepsLayer(screenAt)
|
||||
|
||||
@@ -319,7 +319,7 @@ private fun GameTitle(title: String, logo: Any?, titleSize: TextUnit) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GameActions(
|
||||
internal fun GameActions(
|
||||
store: Store?, id: String?, game: Library.SteamGame?, item: CatalogItem?, installed: InstalledStoreGame?,
|
||||
s: FrontEndState, a: FrontEndActions, leadOn: Modifier,
|
||||
) {
|
||||
@@ -328,22 +328,14 @@ private fun GameActions(
|
||||
val rawDownload = storeKey?.let { StoresState.download(it) }
|
||||
val download = rawDownload?.takeIf { it.isActive }
|
||||
val failed = rawDownload?.takeIf { it.state == DownloadState.FAILED }
|
||||
val cloud = game?.library == Library.XBOX_CLOUD && installed == null
|
||||
Actions {
|
||||
when {
|
||||
s.shortcutPicker && game != null -> {
|
||||
PrimaryButton(stringResource(R.string.game_shortcut_choose), enabled = !s.busy, main = true, icon = Icons.Filled.PlayArrow, modifier = leadOn) { a.onSteamGame(game) }
|
||||
FileButtons(game, a)
|
||||
}
|
||||
game?.library == Library.XBOX_CLOUD -> {
|
||||
val cloudId = game.storeId.orEmpty()
|
||||
XboxStreamButton(cloudId, game.name, main = true, modifier = leadOn)
|
||||
if (download != null) ActionChip(downloadLabel(download), ok = false)
|
||||
else if (item?.installable == true) SecondaryButton(
|
||||
if (item.sizeBytes > 0) stringResource(R.string.stores_install_size, formatBytes(item.sizeBytes)) else stringResource(R.string.stores_install),
|
||||
) { StoresState.requestInstall(ctx, item) }
|
||||
XboxLibraryButton(cloudId, item)
|
||||
}
|
||||
game != null || installed != null -> {
|
||||
!cloud && (game != null || installed != null) -> {
|
||||
val gone = storeKey?.let { StoresState.uninstalling[it] }
|
||||
val xboxBusy = store == Store.XBOX && id != null && XboxContent.busy(id)
|
||||
PrimaryButton(
|
||||
@@ -381,6 +373,19 @@ private fun GameActions(
|
||||
}
|
||||
ConfirmButton(stringResource(R.string.stores_dl_clear), stringResource(R.string.stores_dl_cancel_confirm), compact = true) { DownloadQueue.clear(ctx, failed.key) }
|
||||
}
|
||||
cloud -> {
|
||||
val cloudId = game.storeId.orEmpty()
|
||||
XboxStreamButton(cloudId, game.name, main = true, modifier = leadOn)
|
||||
if (item?.installable == true && item.xboxPc) {
|
||||
SecondaryButton(
|
||||
if (StoresState.isUnfinished(item)) stringResource(R.string.stores_resume_install)
|
||||
else if (item.sizeBytes > 0) stringResource(R.string.stores_install_size, formatBytes(item.sizeBytes))
|
||||
else stringResource(R.string.stores_install),
|
||||
) { StoresState.requestInstall(ctx, item) }
|
||||
}
|
||||
if (item != null && StoresState.isUnfinished(item)) ConfirmButton(stringResource(R.string.stores_dl_clear), stringResource(R.string.stores_dl_cancel_confirm), compact = true) { StoresState.clearUnfinished(ctx, item) }
|
||||
XboxLibraryButton(cloudId, item)
|
||||
}
|
||||
store == Store.BATTLENET && item != null -> InstallButton(stringResource(R.string.stores_install), leadOn) { StoresState.requestInstall(ctx, item) }
|
||||
store == Store.XBOX && item != null && !item.xboxPc && item.xboxCloud -> {
|
||||
XboxStreamButton(item.id, item.title, main = true, modifier = leadOn)
|
||||
@@ -408,6 +413,10 @@ private fun GameActions(
|
||||
item != null && item.isFree -> PrimaryButton(stringResource(R.string.stores_get_free), main = true, modifier = leadOn) { openStoreUrl(ctx, item) }
|
||||
item != null -> PrimaryButton(buyLabel(item), main = true, modifier = leadOn) { openStoreUrl(ctx, item) }
|
||||
}
|
||||
if (cloud && (download != null || failed != null)) {
|
||||
XboxStreamButton(game.storeId.orEmpty(), game.name)
|
||||
XboxLibraryButton(game.storeId.orEmpty(), item)
|
||||
}
|
||||
BusyChip(s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,12 +108,16 @@ internal fun libraryEntries(
|
||||
): List<LibraryEntry> {
|
||||
val claimed = HashSet<String>()
|
||||
val out = ArrayList<LibraryEntry>()
|
||||
for (g in games) {
|
||||
for (g in games.sortedBy { it.library == Library.XBOX_CLOUD }) {
|
||||
if (g.library == Library.EPIC_LAUNCHER) continue
|
||||
val storeKey = g.storeId?.let { "${g.source}:$it" }
|
||||
val item = storeKey?.let { k -> Store.byId(g.source)?.let { st -> owned[st]?.firstOrNull { it.key == k } } }
|
||||
if (storeKey != null) claimed += storeKey
|
||||
out += LibraryEntry(GameRef.key(g), g.source, g.name, g, item, installed = true)
|
||||
if (storeKey != null) {
|
||||
if (g.library == Library.XBOX_CLOUD && storeKey in claimed) continue
|
||||
claimed.add(storeKey)
|
||||
}
|
||||
out += LibraryEntry(GameRef.key(g), g.source, g.name, g, item,
|
||||
installed = g.library != Library.XBOX_CLOUD || storeKey in installedStore)
|
||||
}
|
||||
for (store in Store.entries) for (item in owned[store].orEmpty()) {
|
||||
if (!claimed.add(item.key)) continue
|
||||
@@ -506,18 +510,31 @@ private fun LibraryTile(e: LibraryEntry, capsule: Boolean, first: Boolean, navig
|
||||
@Composable
|
||||
private fun RequestSize(e: LibraryEntry) {
|
||||
val ctx = LocalContext.current
|
||||
if (e.installed) {
|
||||
val inst = e.storeKey?.let { k -> StoresState.installed.firstOrNull { it.key == k } }
|
||||
LaunchedEffect(e.key, inst) {
|
||||
if (inst != null) StoreSizes.requestDisk(ctx, inst.key, inst)
|
||||
else e.game?.gameFiles?.let { FolderSizes.request(it) }
|
||||
}
|
||||
return
|
||||
}
|
||||
val item = e.item?.takeIf { !e.installed && it.accessible && it.sizeBytes <= 0 } ?: return
|
||||
LaunchedEffect(item.key) { StoreSizes.request(ctx, item) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LibraryMarker(e: LibraryEntry, download: DownloadEntry?) {
|
||||
internal fun LibraryMarker(e: LibraryEntry, download: DownloadEntry?) {
|
||||
val pal = LocalPalette.current
|
||||
val size = if (e.installed) e.storeKey?.let { StoreSizes.onDisk[it] }
|
||||
?: e.game?.gameFiles?.let { FolderSizes.known[it.path] }
|
||||
else e.item?.let { StoreSizes.size(it) }?.takeIf { it > 0 }
|
||||
when {
|
||||
download != null -> Text("${download.percent}%", fontSize = 10.sp, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
e.installed -> Unit
|
||||
e.item != null && StoresState.isUnfinished(e.item) -> Text(stringResource(R.string.stores_resume), fontSize = 10.sp, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1)
|
||||
else -> Icon(Icons.Outlined.Download, stringResource(R.string.stores_section_not_installed), tint = Color.White, modifier = Modifier.size(12.dp))
|
||||
else -> Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(3.dp)) {
|
||||
if (size != null && size > 0) Text(formatBytes(size), fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Color.White, maxLines = 1)
|
||||
if (!e.installed) Icon(Icons.Outlined.Download, stringResource(R.string.stores_section_not_installed), tint = Color.White, modifier = Modifier.size(12.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,7 +616,7 @@ private fun Modifier.paneEntry(): Modifier {
|
||||
|
||||
internal fun keepsXbox(filter: String, e: LibraryEntry): Boolean = when {
|
||||
filter == XboxLibraryFilter.ALL || e.source != Store.XBOX.id -> true
|
||||
e.game?.library == Library.XBOX_CLOUD -> filter == XboxLibraryFilter.CLOUD
|
||||
e.game?.library == Library.XBOX_CLOUD && e.item == null -> filter == XboxLibraryFilter.CLOUD
|
||||
else -> e.item?.let { XboxLibraryFilter.keeps(filter, it) } == true
|
||||
}
|
||||
|
||||
|
||||
@@ -150,35 +150,6 @@ private data class PaneKey(val chip: String, val signedIn: Boolean, val accounts
|
||||
internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier) {
|
||||
val ctx = LocalContext.current
|
||||
val focusManager = LocalFocusManager.current
|
||||
com.droiddeck.launcher.stores.xbox.XboxContent.plan?.let { content ->
|
||||
androidx.compose.material3.AlertDialog(
|
||||
onDismissRequest = { com.droiddeck.launcher.stores.xbox.XboxContent.dismiss() },
|
||||
title = { Text(stringResource(R.string.stores_xbox_content_title)) },
|
||||
text = { Column {
|
||||
if (content.error != null) Text(content.error)
|
||||
else if (content.offers.isEmpty()) Text(stringResource(R.string.stores_xbox_content_none))
|
||||
content.offers.forEach { offer ->
|
||||
androidx.compose.material3.TextButton(onClick = { com.droiddeck.launcher.stores.xbox.XboxContent.install(ctx, offer.item) }) {
|
||||
Text(stringResource(if (offer.installed) R.string.stores_xbox_content_update else R.string.stores_xbox_content_install, offer.item.title))
|
||||
}
|
||||
}
|
||||
} },
|
||||
confirmButton = { androidx.compose.material3.TextButton(onClick = { com.droiddeck.launcher.stores.xbox.XboxContent.dismiss() }) { Text(stringResource(android.R.string.ok)) } },
|
||||
)
|
||||
}
|
||||
com.droiddeck.launcher.stores.xbox.XboxBackend.packageChoice?.let { pending ->
|
||||
androidx.compose.material3.AlertDialog(
|
||||
onDismissRequest = { com.droiddeck.launcher.stores.xbox.XboxBackend.dismissPackages() },
|
||||
title = { Text(stringResource(R.string.stores_xbox_choose_content)) },
|
||||
text = { Column { pending.choices.forEach { choice ->
|
||||
androidx.compose.material3.TextButton(onClick = { com.droiddeck.launcher.stores.xbox.XboxBackend.selectPackage(ctx, choice) }) {
|
||||
Text(stringResource(R.string.stores_xbox_choice, choice.getString("title"), choice.getString("kind")))
|
||||
}
|
||||
} } },
|
||||
confirmButton = {},
|
||||
dismissButton = { androidx.compose.material3.TextButton(onClick = { com.droiddeck.launcher.stores.xbox.XboxBackend.dismissPackages() }) { Text(stringResource(android.R.string.cancel)) } },
|
||||
)
|
||||
}
|
||||
val narrow = LocalNarrowPane.current
|
||||
val padH = if (narrow) 14.dp else 22.dp
|
||||
val tabs = remember {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.stores.xbox.XboxBackend
|
||||
import com.droiddeck.launcher.stores.xbox.XboxContent
|
||||
|
||||
@Composable
|
||||
internal fun XboxStoreDialogs(
|
||||
content: XboxContent.Plan? = XboxContent.plan,
|
||||
pending: XboxBackend.PackageChoice? = XboxBackend.packageChoice,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
content?.let {
|
||||
AlertDialog(
|
||||
onDismissRequest = { XboxContent.dismiss() },
|
||||
title = { Text(stringResource(R.string.stores_xbox_content_title)) },
|
||||
text = { Column(Modifier.verticalScroll(rememberScrollState())) {
|
||||
if (content.error != null) Text(content.error)
|
||||
else if (content.offers.isEmpty()) Text(stringResource(R.string.stores_xbox_content_none))
|
||||
content.offers.forEach { offer ->
|
||||
TextButton(onClick = { XboxContent.install(ctx, offer.item) }) {
|
||||
Text(stringResource(if (offer.installed) R.string.stores_xbox_content_update else R.string.stores_xbox_content_install, offer.item.title))
|
||||
}
|
||||
}
|
||||
} },
|
||||
confirmButton = { TextButton(onClick = { XboxContent.dismiss() }) { Text(stringResource(android.R.string.ok)) } },
|
||||
)
|
||||
}
|
||||
pending?.let {
|
||||
AlertDialog(
|
||||
onDismissRequest = { XboxBackend.dismissPackages() },
|
||||
title = { Text(stringResource(R.string.stores_xbox_choose_content)) },
|
||||
text = { Column(Modifier.verticalScroll(rememberScrollState())) { pending.choices.forEach { choice ->
|
||||
TextButton(onClick = { XboxBackend.selectPackage(ctx, choice) }) {
|
||||
Text(stringResource(R.string.stores_xbox_choice, choice.getString("title"), choice.getString("kind")))
|
||||
}
|
||||
} } },
|
||||
confirmButton = {},
|
||||
dismissButton = { TextButton(onClick = { XboxBackend.dismissPackages() }) { Text(stringResource(android.R.string.cancel)) } },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.ui
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.xbox.XboxLibraryFilter
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
@@ -36,6 +37,41 @@ class LibraryEntriesTest {
|
||||
assertTrue(entries.single().installed)
|
||||
}
|
||||
|
||||
@Test fun aSavedCloudGameStaysNotInstalledAndKeepsItsLicenseFilters() {
|
||||
val game = Library.SteamGame(-20, "Cloud game", null, Library.XBOX_CLOUD, source = "xbox", storeId = "cloud")
|
||||
val product = owned(Store.XBOX, "cloud").copy(subscription = true, extra = mapOf("cloud" to "1"))
|
||||
val entries = libraryEntries(listOf(game), mapOf(Store.XBOX to listOf(product)), emptySet())
|
||||
val entry = entries.single()
|
||||
assertFalse(entry.installed)
|
||||
for (filter in XboxLibraryFilter.ALL_FILTERS) assertTrue(filter, keepsXbox(filter, entry))
|
||||
assertEquals(listOf("local", entry.key), installedFirst(listOf(entry, LibraryEntry("local", "steam", "Local", null, null, true))).map { it.key })
|
||||
}
|
||||
|
||||
@Test fun anInstalledPcCopyTakesPrecedenceOverTheSavedCloudRow() {
|
||||
val local = Library.SteamGame(-5, "PC game", null, Library.ADDED, source = "xbox", storeId = "same")
|
||||
val cloud = Library.SteamGame(-20, "PC game", null, Library.XBOX_CLOUD, source = "xbox", storeId = "same")
|
||||
val entries = libraryEntries(listOf(cloud, local), mapOf(Store.XBOX to listOf(owned(Store.XBOX, "same"))), setOf("xbox:same"))
|
||||
assertEquals(1, entries.size)
|
||||
assertEquals(local, entries.single().game)
|
||||
assertTrue(entries.single().installed)
|
||||
}
|
||||
|
||||
@Test fun aSavedCloudGameWithoutACatalogStillAppearsInTheCloudFilter() {
|
||||
val cloud = Library.SteamGame(-20, "Cloud game", null, Library.XBOX_CLOUD, source = "xbox", storeId = "cloud")
|
||||
val entry = libraryEntries(listOf(cloud), emptyMap(), emptySet()).single()
|
||||
assertFalse(entry.installed)
|
||||
assertTrue(keepsXbox(XboxLibraryFilter.CLOUD, entry))
|
||||
assertFalse(keepsXbox(XboxLibraryFilter.OWNED, entry))
|
||||
}
|
||||
|
||||
@Test fun distinctLocalShortcutsForTheSameProductArePreserved() {
|
||||
val first = Library.SteamGame(-5, "First install", null, Library.ADDED, source = "xbox", storeId = "same")
|
||||
val second = Library.SteamGame(-6, "Second install", null, Library.ADDED, source = "xbox", storeId = "same")
|
||||
val cloud = Library.SteamGame(-20, "Cloud game", null, Library.XBOX_CLOUD, source = "xbox", storeId = "same")
|
||||
val entries = libraryEntries(listOf(cloud, first, second), mapOf(Store.XBOX to listOf(owned(Store.XBOX, "same"))), setOf("xbox:same"))
|
||||
assertEquals(listOf(first, second), entries.map { it.game })
|
||||
}
|
||||
|
||||
@Test fun installedGamesComeFirstKeepingTheirSortedOrder() {
|
||||
val entries = listOf("a", "b", "c", "d").map { LibraryEntry(it, "steam", it, null, null, installed = it == "b" || it == "d") }
|
||||
assertEquals(listOf("b", "d", "a", "c"), installedFirst(entries).map { it.key })
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performScrollTo
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.InstalledStoreGame
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoreGameSidecar
|
||||
import com.droiddeck.launcher.stores.StoreInstallRoot
|
||||
import com.droiddeck.launcher.stores.StoreSizes
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
import com.droiddeck.launcher.stores.download.DownloadEntry
|
||||
import com.droiddeck.launcher.stores.download.DownloadState
|
||||
import com.droiddeck.launcher.stores.xbox.XboxBackend
|
||||
import com.droiddeck.launcher.stores.xbox.XboxContent
|
||||
import org.json.JSONObject
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34], qualifiers = "w1200dp-h752dp-land", application = android.app.Application::class)
|
||||
class StoreRestorationTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
private val ctx get() = RuntimeEnvironment.getApplication()
|
||||
private val product = CatalogItem(Store.XBOX, "9NBLGGH4R315", "Test game", null, owned = true, sizeBytes = 10_485_760L, extra = mapOf("cloud" to "1"))
|
||||
private val cloud = Library.SteamGame(-20, product.title, null, Library.XBOX_CLOUD, source = "xbox", storeId = product.id)
|
||||
|
||||
@After fun clear() {
|
||||
StoresState.publishDownloads(emptyList())
|
||||
StoresState.unfinished = emptyList()
|
||||
StoreSizes.onDisk.clear()
|
||||
XboxContent.dismiss()
|
||||
}
|
||||
|
||||
@Test fun manageContentReportsItsResultWithoutComposingTheStoresPage() {
|
||||
val base = InstalledStoreGame(StoreGameSidecar(Store.XBOX, product.id, product.title, "game.exe"), File(ctx.cacheDir, "missing-xbox-manifest"))
|
||||
compose.mainClock.autoAdvance = false
|
||||
compose.setContent {
|
||||
DroidDeckTheme { FrontEndScreen(state(), actions(), page = { Text("Library game page") }) }
|
||||
}
|
||||
compose.mainClock.advanceTimeBy(2_000)
|
||||
compose.runOnIdle { XboxContent.manage(ctx, base) }
|
||||
compose.waitUntil(5_000) {
|
||||
shadowOf(android.os.Looper.getMainLooper()).idle()
|
||||
XboxContent.plan != null
|
||||
}
|
||||
compose.mainClock.advanceTimeBy(100)
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_xbox_content_title)).assertExists()
|
||||
compose.onNodeWithText("Missing or ambiguous MicrosoftGame.config.").assertExists()
|
||||
compose.onNodeWithText(ctx.getString(android.R.string.ok)).performClick()
|
||||
compose.runOnIdle { assertNull(XboxContent.plan) }
|
||||
}
|
||||
|
||||
@Test fun packageChoicesRenderOutsideTheStoresPage() {
|
||||
val choices = (1..24).map { JSONObject().put("title", "Package $it").put("kind", "Game") }
|
||||
val pending = XboxBackend.PackageChoice(product, ctx.cacheDir, choices)
|
||||
compose.setContent { DroidDeckTheme { XboxStoreDialogs(content = null, pending = pending) } }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_xbox_choose_content)).assertExists()
|
||||
choices.forEach { compose.onNodeWithText(ctx.getString(R.string.stores_xbox_choice, it.getString("title"), "Game")).performScrollTo().assertIsDisplayed() }
|
||||
compose.onNodeWithText(ctx.getString(android.R.string.cancel)).assertExists()
|
||||
}
|
||||
|
||||
@Test fun everyContentOfferCanBeReachedInALandscapeDialog() {
|
||||
val base = InstalledStoreGame(StoreGameSidecar(Store.XBOX, product.id, product.title, "game.exe"), ctx.cacheDir)
|
||||
val offers = (1..24).map { XboxContent.Offer(product.copy(id = "dlc-$it", title = "Content $it"), installed = false) }
|
||||
val plan = XboxContent.Plan(base, offers)
|
||||
compose.setContent { DroidDeckTheme { XboxStoreDialogs(content = plan, pending = null) } }
|
||||
offers.forEach { compose.onNodeWithText(ctx.getString(R.string.stores_xbox_content_install, it.item.title)).performScrollTo().assertIsDisplayed() }
|
||||
}
|
||||
|
||||
@Test fun libraryCardsShowDownloadAndInstalledSizes() {
|
||||
val owned = LibraryEntry("owned", "xbox", product.title, null, product, false)
|
||||
val installed = LibraryEntry("installed", "xbox", product.title, null, product.copy(id = "installed"), true)
|
||||
StoreSizes.onDisk["xbox:installed"] = 20_971_520L
|
||||
compose.setContent { DroidDeckTheme { Column {
|
||||
LibraryMarker(owned, null)
|
||||
LibraryMarker(installed, null)
|
||||
} } }
|
||||
compose.onNodeWithText("10.0 MB").assertExists()
|
||||
compose.onNodeWithText("20.0 MB").assertExists()
|
||||
}
|
||||
|
||||
@Test fun aSavedCloudGamesDownloadKeepsPauseResumeCancelAndFailureRecovery() {
|
||||
val entry = DownloadEntry(Store.XBOX, product.id, product.title, state = DownloadState.RUNNING)
|
||||
StoresState.publishDownloads(listOf(entry))
|
||||
compose.setContent { DroidDeckTheme { GameActions(Store.XBOX, product.id, cloud, product, null, state(), actions(), Modifier) } }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_pause)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_cancel)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.game_stream)).assertExists()
|
||||
compose.runOnIdle { StoresState.publishDownloads(listOf(entry.copy(state = DownloadState.PAUSED))) }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_resume)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_cancel)).assertExists()
|
||||
compose.runOnIdle { StoresState.publishDownloads(listOf(entry.copy(state = DownloadState.FAILED))) }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_resume)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_clear)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.game_stream)).assertExists()
|
||||
}
|
||||
|
||||
@Test fun aConsoleOnlyCloudGameDoesNotOfferAPcInstall() {
|
||||
compose.setContent { DroidDeckTheme { GameActions(Store.XBOX, product.id, cloud, product.copy(sizeBytes = 0, extra = mapOf("pc" to "0", "cloud" to "1")), null, state(), actions(), Modifier) } }
|
||||
compose.onNodeWithText(ctx.getString(R.string.game_stream)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_install)).assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test fun anInterruptedCloudDownloadCanBeClearedAfterItsLicenseOrPcMetadataChanges() {
|
||||
StoresState.unfinished = listOf(StoreInstallRoot.Unfinished(Store.XBOX, product.id, File(ctx.cacheDir, "partial")))
|
||||
var item by mutableStateOf(product)
|
||||
compose.setContent { DroidDeckTheme { GameActions(Store.XBOX, product.id, cloud, item, null, state(), actions(), Modifier) } }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_resume_install)).assertExists()
|
||||
for (changed in listOf(product.copy(owned = false), product.copy(extra = mapOf("pc" to "0", "cloud" to "1")))) {
|
||||
compose.runOnIdle { item = changed }
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_dl_clear)).assertExists()
|
||||
compose.onNodeWithText(ctx.getString(R.string.stores_resume_install)).assertDoesNotExist()
|
||||
}
|
||||
}
|
||||
|
||||
private fun state() = FrontEndState(
|
||||
installed = "r9", ready = true, available = null, busy = false, stage = "", percent = -1,
|
||||
desktopInstalled = true, offlineAccount = null, offline = false, frameGenLabel = "",
|
||||
romsDir = null, logsEnabled = false, steamGames = emptyList(), emulators = emptyList(), running = null,
|
||||
pageKey = "test-game", navigate = "games",
|
||||
)
|
||||
|
||||
private fun actions() = FrontEndActions(
|
||||
onPlay = {}, onPlayDesktopUi = {}, onSteamGame = {}, onDesktop = {}, onEmulator = {},
|
||||
onRom = {}, onResume = {}, onSteamSettings = {}, onDesktopSettings = {},
|
||||
onInstallPackage = {}, onRemovePackage = {}, onRuntime = {}, onFrameGenPick = {},
|
||||
onImportLossless = {}, onProtons = {}, onComponents = {}, onPerformance = {},
|
||||
onRoms = {}, onFiles = {}, onLogs = {}, onOffline = {},
|
||||
onWirelessAdbPair = { _, _, _, _ -> }, onWirelessAdbApply = { _, _, _, _ -> },
|
||||
onSetPhantomProcessLimit = { _, _ -> },
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user