mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
feat(dev): preview states for the Library and the in-game menu (#2899)
* Developer tools: preview states for the Library and the in-game menu Settings › Developer gets a Preview states group (shown with developer tools on): - Library: nothing installed, signed out of every store, or sample games in every store (each store's storefront games passed off as owned, a few as installed). A pill on the Library says which preview is on and ends it. Nothing is installed, removed or signed out, and the preview is never saved, so a restart always turns it off. - In-game menu: opens the session menu over the launcher for Steam, Desktop or a game, without starting a session. Its switches change only the preview. LB/RB switch pages and B or Back closes it, as in a session. * Preview states: Back closes the menu preview; signed-out preview covers expired stores The launcher's exit gesture no longer takes Back while the in-game menu preview is open, so Back closes the preview. The signed-out Library preview shows the sign-in card for an expired store with cached games too. * Developer tools: a UI zoo sheet for previews; previews are read-only The Developer tab keeps one UI zoo row instead of the preview pickers. It opens a side sheet listing the in-game menu (Steam, Desktop, game) and the Library states; nothing shows until one is picked, and picking one closes the sheet. A Library preview switches to the Library on All games. While a Library preview is on, opening a game shows a short note instead of its page, which would act on the real install behind the preview. Size sorting uses the size a card shows, so a real install shown as not installed sorts by its catalog size. * Developer tools: preview shortcuts, a Library toolbar button for preview states An opt-in Preview shortcuts switch (off by default) puts a flask button in the Library's toolbar that picks the real library or a preview state in place, so a state is a tap away while using the launcher normally. The UI zoo stays the catalog of every preview. * Preview states: no real sign-in or sign-out from a Library preview The toolbar's sign-out button is hidden while a Library preview is on, and the sign-in card's button only says previews are read-only, so a preview never signs a real account in or out.
This commit is contained in:
1 parent
fc9ad2447d
commit
00557703da
9 files changed
+354
-20
No files matched your search
@@ -280,6 +280,12 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("developerTools", on).apply()
|
||||
}
|
||||
|
||||
fun previewShortcuts(context: Context): Boolean = prefs(context).getBoolean("previewShortcuts", false)
|
||||
|
||||
fun setPreviewShortcuts(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("previewShortcuts", on).apply()
|
||||
}
|
||||
|
||||
fun fpsLimitKey(mode: String?, game: String?): String? = when (mode) {
|
||||
SessionService.MODE_RUN -> game?.trim()?.takeIf(com.droiddeck.launcher.frontend.GameLaunchLink::validId)?.let { "fpsLimit.game.$it" }
|
||||
SessionService.MODE_DESKTOP -> "fpsLimit.desktop"
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.outlined.Science
|
||||
import androidx.compose.material.icons.outlined.Visibility
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.layout.boundsInRoot
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.key.KeyEventType
|
||||
import androidx.compose.ui.input.key.onKeyEvent
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import androidx.compose.ui.input.key.type
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.gpu.FrameGen
|
||||
import com.droiddeck.launcher.gpu.Lossless
|
||||
import com.droiddeck.launcher.input.SecondScreenDisplay
|
||||
import com.droiddeck.launcher.input.SecondScreenMode
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import com.droiddeck.launcher.stores.StoresState
|
||||
|
||||
/** What the Library pretends while a developer previews it. Nothing here is saved: a restart always comes back to [OFF]. */
|
||||
internal enum class LibraryPreview { OFF, NOTHING_INSTALLED, SIGNED_OUT, SAMPLE }
|
||||
|
||||
internal enum class DrawerPreview { STEAM, DESKTOP, GAME }
|
||||
|
||||
/** Developer tools' preview states: screens that are otherwise hard to reach, shown without changing anything real. */
|
||||
internal object DevPreview {
|
||||
var library by mutableStateOf(LibraryPreview.OFF)
|
||||
var drawer by mutableStateOf<DrawerPreview?>(null)
|
||||
/** The UI zoo sheet: where previews are picked, one at a time, only when asked for. */
|
||||
var zoo by mutableStateOf(false)
|
||||
/** Opt-in: a preview button where its state lives (the Library's toolbar), for switching states without the zoo. */
|
||||
var shortcuts by mutableStateOf(false)
|
||||
|
||||
fun setShortcuts(context: android.content.Context, on: Boolean) {
|
||||
shortcuts = on
|
||||
SessionPrefs.setPreviewShortcuts(context, on)
|
||||
}
|
||||
|
||||
/** Set when a Library preview is picked, so the launcher switches to the Library to show it. */
|
||||
var openLibrary by mutableStateOf(false)
|
||||
}
|
||||
|
||||
/** How many of each store's sample games look installed. */
|
||||
private const val SAMPLE_INSTALLED = 3
|
||||
|
||||
/** A store's storefront games, passed off as owned, for the sample library. Empty until the store's shelves have loaded. */
|
||||
internal fun sampleOwned(store: Store): List<CatalogItem> =
|
||||
StoresState.shelves[store]?.all.orEmpty().filter { !it.mature }.distinctBy { it.id }.take(24).map { it.copy(owned = true) }
|
||||
|
||||
internal fun sampleInstalled(owned: Map<Store, List<CatalogItem>>): Set<String> =
|
||||
owned.values.flatMap { items -> items.take(SAMPLE_INSTALLED).map { it.key } }.toSet()
|
||||
|
||||
/** The pill a previewed Library shows, so the fake state is never mistaken for the real one. */
|
||||
@Composable
|
||||
internal fun LibraryPreviewPill(modifier: Modifier = Modifier) {
|
||||
val preview = DevPreview.library
|
||||
if (preview == LibraryPreview.OFF) return
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val label = stringResource(
|
||||
when (preview) {
|
||||
LibraryPreview.NOTHING_INSTALLED -> R.string.dev_preview_library_nothing_installed
|
||||
LibraryPreview.SIGNED_OUT -> R.string.dev_preview_library_signed_out
|
||||
else -> R.string.dev_preview_library_sample
|
||||
},
|
||||
)
|
||||
val end = stringResource(R.string.dev_preview_end)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
modifier = modifier.background(colors.surface, CircleShape).border(1.dp, pal.signal, CircleShape)
|
||||
.clickable(role = Role.Button, onClickLabel = end) { DevPreview.library = LibraryPreview.OFF }
|
||||
.padding(start = 14.dp, end = 10.dp, top = 8.dp, bottom = 8.dp).testTag("dev-preview-end"),
|
||||
) {
|
||||
Icon(Icons.Outlined.Visibility, null, tint = pal.signal, modifier = Modifier.size(18.dp))
|
||||
Text(stringResource(R.string.dev_preview_banner, label), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground)
|
||||
Icon(Icons.Filled.Close, end, tint = colors.onSurfaceVariant, modifier = Modifier.size(18.dp))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The in-game menu over the launcher, for looking at without starting a session. Its switches change only this preview: nothing
|
||||
* is saved and no session is told. Back or Close ends it.
|
||||
*/
|
||||
@Composable
|
||||
internal fun SessionDrawerPreview(secondScreens: List<SecondScreenDisplay>) {
|
||||
val mode = DevPreview.drawer ?: return
|
||||
val ctx = LocalContext.current
|
||||
val close = { DevPreview.drawer = null }
|
||||
var page by remember { mutableStateOf(SessionDrawerPage.CONTROLLER) }
|
||||
// A session's activity routes these keys to its menu; the launcher has no such routing, so the preview does it.
|
||||
var layerOpen by remember { mutableStateOf(false) }
|
||||
var backRequests by remember { mutableStateOf(0) }
|
||||
val back = { if (layerOpen) backRequests++ else close() }
|
||||
BackHandler { back() }
|
||||
var hud by remember { mutableStateOf(SessionPrefs.hudEnabled(ctx)) }
|
||||
var touch by remember { mutableStateOf(SessionPrefs.touchMode(ctx)) }
|
||||
var osc by remember { mutableStateOf(SessionPrefs.oscMode(ctx)) }
|
||||
var fex by remember { mutableStateOf(SessionPrefs.fexPreset(ctx)) }
|
||||
var inverted by remember { mutableStateOf(SessionPrefs.backActionsInverted(ctx)) }
|
||||
var suspend by remember { mutableStateOf(SessionPrefs.SUSPEND_MANUAL) }
|
||||
var frameGen by remember { mutableStateOf(FrameGen.Mode.OFF) }
|
||||
var second by remember { mutableStateOf(SecondScreenMode.NONE) }
|
||||
var fps by remember { mutableStateOf(0) }
|
||||
val steam = mode == DrawerPreview.STEAM
|
||||
val actions = DrawerActions(
|
||||
steam = steam,
|
||||
desktop = mode == DrawerPreview.DESKTOP,
|
||||
title = if (mode == DrawerPreview.GAME) stringResource(R.string.session_title_game) else null,
|
||||
isHomeApp = false,
|
||||
androidApps = emptyList(),
|
||||
hudOn = hud, onHud = { hud = it },
|
||||
frameGen = frameGen, onFrameGenPick = { frameGen = it },
|
||||
lossless = Lossless.State.NONE,
|
||||
oscMode = osc, onOsc = { osc = it },
|
||||
suspendPolicy = suspend, onSuspendPolicy = { suspend = it },
|
||||
backActionsInverted = inverted, onBackActionsInverted = { inverted = it },
|
||||
touchMode = touch, onTouch = { touch = it },
|
||||
touchAuto = stringResource(R.string.session_touch_auto_direct),
|
||||
fexPreset = fex, onFexPreset = { fex = it },
|
||||
fpsLimit = fps, onFpsLimit = { fps = it },
|
||||
secondScreenMode = second, onSecondScreenMode = { second = it },
|
||||
secondScreenDisplays = secondScreens,
|
||||
selectedSecondScreenDisplay = secondScreens.firstOrNull()?.id ?: -1,
|
||||
onSecondScreenDisplay = {},
|
||||
onImportLossless = {},
|
||||
onKeyboard = {}, onHardwareKeyboard = {},
|
||||
onSteamMenu = if (steam) ({}) else null,
|
||||
onQam = if (steam) ({}) else null,
|
||||
onLaunchAndroidApp = { _, _ -> },
|
||||
onBackground = close,
|
||||
onShareLogs = {},
|
||||
onStop = close,
|
||||
onClose = close,
|
||||
)
|
||||
Box(
|
||||
Modifier.fillMaxSize().testTag("dev-preview-drawer")
|
||||
.onPreviewKeyEvent { e ->
|
||||
val code = e.nativeKeyEvent.keyCode
|
||||
if (code != android.view.KeyEvent.KEYCODE_BUTTON_L1 && code != android.view.KeyEvent.KEYCODE_BUTTON_R1) return@onPreviewKeyEvent false
|
||||
if (e.type == KeyEventType.KeyDown && e.nativeKeyEvent.repeatCount == 0) {
|
||||
page = sessionDrawerPages(secondScreens.isNotEmpty()).step(page, if (code == android.view.KeyEvent.KEYCODE_BUTTON_R1) 1 else -1)
|
||||
}
|
||||
true
|
||||
}
|
||||
.onKeyEvent { e ->
|
||||
if (e.nativeKeyEvent.keyCode != android.view.KeyEvent.KEYCODE_BUTTON_B) return@onKeyEvent false
|
||||
if (e.type == KeyEventType.KeyDown && e.nativeKeyEvent.repeatCount == 0) back()
|
||||
true
|
||||
}
|
||||
.background(Brush.linearGradient(listOf(Color(0xFF1B2A3A), Color(0xFF0B0F14), Color(0xFF2A1B2E)))),
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.dev_preview_drawer_backdrop), fontSize = 13.sp, color = Color.White.copy(alpha = 0.5f),
|
||||
modifier = Modifier.align(Alignment.BottomStart).padding(24.dp),
|
||||
)
|
||||
SessionDrawer(
|
||||
true, page, controllerActive = true, onPageChange = { page = it }, a = actions,
|
||||
backRequest = backRequests, onLayerChange = { layerOpen = it },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Developer tools' UI zoo: a sheet listing the previews. Nothing shows until one is picked, and picking one closes the sheet. */
|
||||
@Composable
|
||||
internal fun UiZooSheet() {
|
||||
val close = { DevPreview.zoo = false }
|
||||
SideSheet(DevPreview.zoo, onClose = close, returnFocus = null, tag = "ui-zoo-sheet") {
|
||||
PageHeader(stringResource(R.string.dev_ui_zoo)) {
|
||||
androidx.compose.foundation.layout.Spacer(Modifier.weight(1f))
|
||||
SmallIconButton(Icons.Filled.Close, stringResource(R.string.common_close), tint = MaterialTheme.colorScheme.onSurfaceVariant) { close() }
|
||||
}
|
||||
androidx.compose.foundation.layout.Column(Modifier.weight(1f).verticalScroll(rememberScrollState())) {
|
||||
val show = stringResource(R.string.dev_ui_zoo_show)
|
||||
SettingsGroup(stringResource(R.string.dev_preview_drawer)) {
|
||||
for ((mode, label) in listOf(
|
||||
DrawerPreview.STEAM to R.string.source_steam,
|
||||
DrawerPreview.DESKTOP to R.string.rail_desktop,
|
||||
DrawerPreview.GAME to R.string.session_title_game,
|
||||
)) ActionRow(stringResource(label), null, show, onClick = { close(); DevPreview.drawer = mode }, modifier = Modifier.testTag("zoo-drawer-${mode.name.lowercase()}"))
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.dev_preview_library)) {
|
||||
for ((mode, label) in listOf(
|
||||
LibraryPreview.NOTHING_INSTALLED to R.string.dev_preview_library_nothing_installed,
|
||||
LibraryPreview.SIGNED_OUT to R.string.dev_preview_library_signed_out,
|
||||
LibraryPreview.SAMPLE to R.string.dev_preview_library_sample,
|
||||
)) ActionRow(
|
||||
stringResource(label), null, show,
|
||||
onClick = { close(); DevPreview.library = mode; DevPreview.openLibrary = true },
|
||||
modifier = Modifier.testTag("zoo-library-${mode.name.lowercase()}"),
|
||||
)
|
||||
}
|
||||
Text(
|
||||
stringResource(R.string.dev_ui_zoo_note), fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The Library toolbar's preview button, shown only with preview shortcuts on: picks the Library state in place. */
|
||||
@Composable
|
||||
internal fun LibraryPreviewButton() {
|
||||
val pal = LocalPalette.current
|
||||
val title = stringResource(R.string.dev_preview_library)
|
||||
var at by remember { mutableStateOf<androidx.compose.ui.geometry.Rect?>(null) }
|
||||
val states = listOf(
|
||||
LibraryPreview.OFF to R.string.dev_preview_real,
|
||||
LibraryPreview.NOTHING_INSTALLED to R.string.dev_preview_library_nothing_installed,
|
||||
LibraryPreview.SIGNED_OUT to R.string.dev_preview_library_signed_out,
|
||||
LibraryPreview.SAMPLE to R.string.dev_preview_library_sample,
|
||||
)
|
||||
Box(Modifier.onGloballyPositioned { at = it.boundsInRoot() }) {
|
||||
HeaderIconButton(stringResource(R.string.dev_preview_shortcut), Icons.Outlined.Science, "library-preview") {
|
||||
val from = at ?: return@HeaderIconButton
|
||||
Steps.ask(StepAsk(
|
||||
anchor = from, side = StepSide.Left, accent = pal.signal, pillCorner = 8.dp, items = states.size,
|
||||
handle = { Icon(Icons.Outlined.Science, null, tint = pal.signal, modifier = Modifier.size(18.dp)) },
|
||||
) {
|
||||
StepTitle(title)
|
||||
StepList {
|
||||
states.forEachIndexed { i, (state, label) ->
|
||||
StepChoice(
|
||||
stringResource(label), selected = DevPreview.library == state, enabled = open,
|
||||
modifier = Modifier.fillMaxWidth().stepItem(i).let { if (i == 0) it.focusRequester(first) else it },
|
||||
) { DevPreview.library = state; Steps.fold() }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,6 +285,7 @@ private fun Content(
|
||||
if (selected == "games" || selected.startsWith("app:") || selected == "soundtracks" || selected.startsWith("sound:")) {
|
||||
Box(modifier) {
|
||||
LibraryPage(s, a, selected, onSelect, Modifier.fillMaxSize())
|
||||
if (selected == "games") LibraryPreviewPill(Modifier.align(androidx.compose.ui.Alignment.BottomCenter).padding(bottom = 20.dp))
|
||||
ManageStoresSheet()
|
||||
}
|
||||
return
|
||||
|
||||
@@ -650,6 +650,12 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
LaunchedEffect(SetupTabs.openSection) {
|
||||
if (SetupTabs.openSection != null && (railSelection != "setup" || s.pageKey != null)) showRailPage("setup", true)
|
||||
}
|
||||
LaunchedEffect(DevPreview.openLibrary) {
|
||||
if (!DevPreview.openLibrary) return@LaunchedEffect
|
||||
DevPreview.openLibrary = false
|
||||
LibraryView.source = LIBRARY_ALL
|
||||
showRailPage("games", true)
|
||||
}
|
||||
val onRailFocus: (String) -> Unit = { key ->
|
||||
if (key != railSelection) showRailPage(key, false)
|
||||
}
|
||||
@@ -806,6 +812,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
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 } } }
|
||||
StepsLayer(screenAt)
|
||||
UiZooSheet()
|
||||
SessionDrawerPreview(s.secondScreenDisplays)
|
||||
|
||||
appToChooseDisplay?.let { app ->
|
||||
val secondaryDisplay = s.secondScreenDisplays.firstOrNull()
|
||||
@@ -876,7 +884,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
(selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:") || selected == "store"))
|
||||
val exitArmed = !processSettingsPageVisible && !hasBackTarget
|
||||
LaunchedEffect(exitArmed, selected) { ExitGesture.reset() }
|
||||
BackHandler(enabled = exitArmed) {
|
||||
BackHandler(enabled = exitArmed && DevPreview.drawer == null) {
|
||||
when (ExitGesture.back()) {
|
||||
2 -> android.widget.Toast.makeText(ctx, R.string.exit_hint_back, android.widget.Toast.LENGTH_SHORT).show()
|
||||
3 -> {
|
||||
|
||||
@@ -59,6 +59,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -595,6 +596,14 @@ internal fun SetupPanel(
|
||||
ToggleRow(host, "developer-tools", stringResource(R.string.dev_tools_title), stringResource(R.string.dev_tools_hint), DeveloperTools.on) {
|
||||
DeveloperTools.set(devContext, it)
|
||||
}
|
||||
if (DeveloperTools.on) ActionRow(
|
||||
stringResource(R.string.dev_ui_zoo), stringResource(R.string.dev_ui_zoo_hint), stringResource(R.string.dev_ui_zoo_open),
|
||||
onClick = { DevPreview.zoo = true }, modifier = Modifier.testTag("dev-ui-zoo"),
|
||||
)
|
||||
if (DeveloperTools.on) ToggleRow(
|
||||
host, "preview-shortcuts", stringResource(R.string.dev_preview_shortcuts), stringResource(R.string.dev_preview_shortcuts_hint),
|
||||
DevPreview.shortcuts,
|
||||
) { DevPreview.setShortcuts(devContext, it) }
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.dev_group_logs)) {
|
||||
ToggleRow(host, "logs", stringResource(R.string.setup_logs), stringResource(R.string.setup_logs_hint), s.logsEnabled) { a.onLogs() }
|
||||
|
||||
@@ -326,20 +326,33 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
|
||||
val favorites = if (soundMode) emptySet() else LibraryFavorites.keys
|
||||
val concealed: (LibraryEntry) -> Boolean = { !soundMode && LibraryHidden.isHidden(it) }
|
||||
val stores = !s.shortcutPicker && !soundMode
|
||||
val signedIn = Store.entries.filter { StoresState.isSignedIn(it) }
|
||||
LaunchedEffect(stores, signedIn) { if (stores) signedIn.forEach { StoresState.loadLibrary(ctx, it) } }
|
||||
val owned = if (stores) signedIn.associateWith { StoresState.library[it].orEmpty() } else emptyMap()
|
||||
val installedStore = StoresState.installed.map { it.key }.toSet()
|
||||
val syncing = if (stores) signedIn.mapNotNull { st -> StoresState.status[st]?.let { st to it } } else emptyList()
|
||||
val preview = if (stores) DevPreview.library else LibraryPreview.OFF
|
||||
val signedIn = when (preview) {
|
||||
LibraryPreview.SAMPLE -> Store.entries.filter { StoresState.backend(it) != null }
|
||||
LibraryPreview.SIGNED_OUT -> emptyList()
|
||||
else -> Store.entries.filter { StoresState.isSignedIn(it) }
|
||||
}
|
||||
LaunchedEffect(stores, signedIn, preview) {
|
||||
if (stores) signedIn.forEach { if (preview == LibraryPreview.SAMPLE) StoresState.preview(ctx, it) else StoresState.loadLibrary(ctx, it) }
|
||||
}
|
||||
val owned = when {
|
||||
!stores -> emptyMap()
|
||||
preview == LibraryPreview.SAMPLE -> signedIn.associateWith { sampleOwned(it) }
|
||||
else -> signedIn.associateWith { StoresState.library[it].orEmpty() }
|
||||
}
|
||||
val reallyInstalled = StoresState.installed.map { it.key }.toSet()
|
||||
val installedStore = reallyInstalled + if (preview == LibraryPreview.SAMPLE) sampleInstalled(owned) else emptySet()
|
||||
val syncing = if (stores && preview == LibraryPreview.OFF) signedIn.mapNotNull { st -> StoresState.status[st]?.let { st to it } } else emptyList()
|
||||
val cloudRows = rememberXboxCloudRows(s)
|
||||
remember { SoundtrackCollections.load(ctx) }
|
||||
val savedSnapshot = SoundtrackCollections.snapshot
|
||||
val favoritesLabel = stringResource(R.string.soundtracks_favorites)
|
||||
val all = remember(soundMode, s.steamGames, s.soundtracks, s.soundtracksEnabled, cloudRows, owned, installedStore, savedSnapshot, favoritesLabel) {
|
||||
val all = remember(soundMode, s.steamGames, s.soundtracks, s.soundtracksEnabled, cloudRows, owned, installedStore, savedSnapshot, favoritesLabel, preview) {
|
||||
if (soundMode) s.soundtracks.map { LibraryEntry("sound:${it.appId}", it.source, it.name, it, null, true) } +
|
||||
(if (s.soundtracks.isEmpty() && savedSnapshot.favorites.isEmpty() && savedSnapshot.collections.isEmpty()) emptyList() else SoundtrackCollections.games(ctx, favoritesLabel, skipEmptyFavorites = true))
|
||||
.map { LibraryEntry("sound:${it.appId}", it.source, it.name, it, null, true) }
|
||||
else libraryEntries(s.steamGames + cloudRows + if (s.soundtracksEnabled) emptyList() else s.soundtracks.filter { it.library != Library.ADDED }, owned, installedStore)
|
||||
.let { rows -> if (preview == LibraryPreview.NOTHING_INSTALLED) rows.map { LibraryEntry(it.key, it.source, it.title, it.game, it.item, false) } else rows }
|
||||
}
|
||||
var addingSoundtrack by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(Unit) { XboxLibraryFilter.load(ctx) }
|
||||
@@ -361,8 +374,8 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
|
||||
val gameJoltSignedIn = owned.containsKey(Store.GAMEJOLT)
|
||||
remember { StoreTabsState.load(ctx) }
|
||||
val storeTabs = StoreTabsState.tabs
|
||||
val signInChips = if (!stores || !StoresState.accountsLoaded) emptySet() else storeTabs
|
||||
.filter { it.shown && StoresState.backend(it.store) != null && storeAccount(it.store) != StoreAccount.SIGNED_IN }
|
||||
val signInChips = if (!stores || !StoresState.accountsLoaded || preview == LibraryPreview.SAMPLE) emptySet() else storeTabs
|
||||
.filter { it.shown && StoresState.backend(it.store) != null && (preview == LibraryPreview.SIGNED_OUT || storeAccount(it.store) != StoreAccount.SIGNED_IN) }
|
||||
.map { it.store.id }.toSet()
|
||||
val sources = librarySources(
|
||||
all, storeTabs.map { it.store.id },
|
||||
@@ -429,7 +442,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
|
||||
fun sizeOf(e: LibraryEntry): Long? {
|
||||
val key = e.storeKey
|
||||
return when {
|
||||
key != null && key in installedStore -> StoreSizes.onDisk[key]
|
||||
key != null && e.installed && key in installedStore -> StoreSizes.onDisk[key]
|
||||
e.game?.gameFiles != null -> FolderSizes.known[e.game.gameFiles.path]
|
||||
e.item != null -> StoreSizes.size(e.item).takeIf { it > 0 }
|
||||
else -> 0L
|
||||
@@ -450,7 +463,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
|
||||
var sizesWaited by remember(sizeSort) { mutableStateOf(false) }
|
||||
LaunchedEffect(sizeSort) { if (sizeSort) { kotlinx.coroutines.delay(8_000); sizesWaited = true } }
|
||||
fun sizeComing(e: LibraryEntry): Boolean = when {
|
||||
e.storeKey != null && e.storeKey in installedStore -> true
|
||||
e.storeKey != null && e.storeKey in installedStore -> e.storeKey in reallyInstalled // a sample install has no size to wait for
|
||||
e.game?.gameFiles != null -> true
|
||||
e.item != null -> StoreSizes.coming(e.item)
|
||||
else -> false
|
||||
@@ -545,7 +558,11 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
|
||||
LibraryView.source = ids[(ids.indexOf(source).coerceAtLeast(0) + step + ids.size) % ids.size]
|
||||
cycled++
|
||||
},
|
||||
onOpen = { focusManager.clearFocus(force = true); onSelect(it) },
|
||||
onOpen = {
|
||||
// A preview is read-only: a game's page would act on the real install behind the pretend one.
|
||||
if (preview != LibraryPreview.OFF) android.widget.Toast.makeText(ctx, R.string.dev_preview_read_only, android.widget.Toast.LENGTH_SHORT).show()
|
||||
else { focusManager.clearFocus(force = true); onSelect(it) }
|
||||
},
|
||||
searchCleared = open != null,
|
||||
onFocus = { gridFocused = it },
|
||||
soundMode = soundMode,
|
||||
@@ -560,7 +577,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
|
||||
onCollections = { savedDialog = true },
|
||||
trackHits = shownHits, onPlayHit = playHit,
|
||||
// An expired account keeps showing its cached games; with none cached it asks to sign in again, like a signed-out store.
|
||||
signInStore = Store.byId(source)?.takeIf { st -> st.id in signInChips && (storeAccount(st) != StoreAccount.EXPIRED || all.none { it.source == st.id }) },
|
||||
signInStore = Store.byId(source)?.takeIf { st -> st.id in signInChips && (preview == LibraryPreview.SIGNED_OUT || storeAccount(st) != StoreAccount.EXPIRED || all.none { it.source == st.id }) },
|
||||
) }
|
||||
},
|
||||
) { key ->
|
||||
@@ -774,7 +791,7 @@ private fun LibraryGrid(
|
||||
Box(Modifier.padding(top = 4.dp, bottom = 16.dp)) { CustomGamesCard(splashHeight, art) }
|
||||
}
|
||||
else if (signInStore != null) item(key = "sign-in:${signInStore.id}", span = { GridItemSpan(maxLineSpan) }) {
|
||||
StoreTheme(signInStore) { Box(Modifier.padding(top = 4.dp, bottom = 16.dp)) { SignInCard(signInStore, splashHeight) } }
|
||||
StoreTheme(signInStore) { Box(Modifier.padding(top = 4.dp, bottom = 16.dp)) { SignInCard(signInStore, splashHeight, inert = DevPreview.library != LibraryPreview.OFF) } }
|
||||
}
|
||||
else if (split == 0) {
|
||||
if (toggleAt == ToggleAt.TOP) item(key = NOT_INSTALLED_ROW, span = { GridItemSpan(maxLineSpan) }) { toggleRow() }
|
||||
@@ -871,13 +888,15 @@ private fun LibraryHeader(
|
||||
lead = soundLead,
|
||||
) {
|
||||
if (soundMode) HeaderIconButton(stringResource(R.string.soundtracks_saved), Icons.Filled.BookmarkBorder, "collections", onClick = onCollections)
|
||||
if (!soundMode && DeveloperTools.on && DevPreview.shortcuts) LibraryPreviewButton()
|
||||
DisplayButton()
|
||||
if (!soundMode && xbox) LibraryFilterButton(null, onShowUninstalled, xbox)
|
||||
if (collections != null) CollectionsButton(collections)
|
||||
SortButton(s, a)
|
||||
ViewButton(s, a)
|
||||
if (!soundMode) GameFileFolderActions(s, a)
|
||||
Store.byId(source)?.takeIf { !soundMode && StoresState.isSignedIn(it) }?.let { StoreAccountButton(it) }
|
||||
// No sign-out in a preview: it would sign the real account out.
|
||||
Store.byId(source)?.takeIf { !soundMode && DevPreview.library == LibraryPreview.OFF && StoresState.isSignedIn(it) }?.let { StoreAccountButton(it) }
|
||||
if (!s.shortcutPicker && (soundMode || (source == Library.ADDED && total > 0))) AddGameButton { if (soundMode) onAddSoundtrack() else GamesDialogState.adding = true }
|
||||
}
|
||||
if (s.steamGamesX64 && narrow) Box(Modifier.padding(top = 4.dp)) { ClientTag() }
|
||||
@@ -988,7 +1007,9 @@ private fun CustomGamesCard(height: androidx.compose.ui.unit.Dp, art: List<Any>)
|
||||
private fun sourceDot(src: String): Color? {
|
||||
val store = Store.byId(src)
|
||||
return when {
|
||||
store != null -> sourceColours(src).dot.copy(alpha = if (StoresState.isSignedIn(store) && StoresState.expired[store] != true) 1f else 0.35f)
|
||||
store != null -> sourceColours(src).dot.copy(
|
||||
alpha = if (DevPreview.library == LibraryPreview.SAMPLE || (DevPreview.library != LibraryPreview.SIGNED_OUT && StoresState.isSignedIn(store) && StoresState.expired[store] != true)) 1f else 0.35f,
|
||||
)
|
||||
src == LIBRARY_FAVORITES -> FavoritesColours.dot
|
||||
src == LIBRARY_HIDDEN -> Color(0xFF9AA0A6)
|
||||
src == Library.SOURCE_STEAM || src == Library.ADDED || src == Library.SOURCE_COLLECTION -> sourceColours(src).dot
|
||||
|
||||
@@ -15,6 +15,7 @@ internal object DeveloperTools {
|
||||
|
||||
fun load(context: Context) {
|
||||
on = SessionPrefs.developerTools(context)
|
||||
DevPreview.shortcuts = SessionPrefs.previewShortcuts(context)
|
||||
}
|
||||
|
||||
fun set(context: Context, enabled: Boolean) {
|
||||
|
||||
@@ -571,7 +571,8 @@ internal fun CountPill(count: Int) {
|
||||
|
||||
|
||||
@Composable
|
||||
internal fun SignInCard(store: Store, height: Dp) {
|
||||
/** [inert]: shown in a Library preview, where signing in would act on the real account; the button only says so. */
|
||||
internal fun SignInCard(store: Store, height: Dp, inert: Boolean = false) {
|
||||
val ctx = LocalContext.current
|
||||
LaunchedEffect(store) { StoresState.preview(ctx, store) }
|
||||
val art = remember(StoresState.shelves[store]) {
|
||||
@@ -581,7 +582,7 @@ internal fun SignInCard(store: Store, height: Dp) {
|
||||
?: shelves?.all.orEmpty().filter { !it.mature && !it.owned }.mapNotNull { it.tallImageUrl ?: it.imageUrl },
|
||||
)
|
||||
}
|
||||
HeroWallCard(store.label, art, sourceColours(store.id), height) { SignInButton(store, large = true) }
|
||||
HeroWallCard(store.label, art, sourceColours(store.id), height) { SignInButton(store, large = true, inert = inert) }
|
||||
}
|
||||
|
||||
/** Repeats a short cover list so the wall has enough tiles to drift; too few covers leave it to the blank capsules. */
|
||||
@@ -629,7 +630,7 @@ internal fun HeroWallCard(title: String, art: List<Any>, c: SourceColours, heigh
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SignInButton(store: Store, large: Boolean = false) {
|
||||
private fun SignInButton(store: Store, large: Boolean = false, inert: Boolean = false) {
|
||||
val ctx = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val placed = remember { arrayOfNulls<androidx.compose.ui.layout.LayoutCoordinates>(1) }
|
||||
@@ -637,7 +638,8 @@ private fun SignInButton(store: Store, large: Boolean = false) {
|
||||
if (askKey) ItchKeyDialog { askKey = false }
|
||||
Box(Modifier.onGloballyPositioned { placed[0] = it }) {
|
||||
PrimaryButton(stringResource(R.string.stores_signin), main = true, large = large, icon = if (large) Icons.AutoMirrored.Filled.Login else null) {
|
||||
startStoreSignIn(ctx, store, placed[0]?.takeIf { it.isAttached }?.boundsInRoot(), colors.primary) { askKey = true }
|
||||
if (inert) android.widget.Toast.makeText(ctx, R.string.dev_preview_read_only, android.widget.Toast.LENGTH_SHORT).show()
|
||||
else startStoreSignIn(ctx, store, placed[0]?.takeIf { it.isAttached }?.boundsInRoot(), colors.primary) { askKey = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4288,6 +4288,24 @@
|
||||
<string name="settings_place_sheet">Steam or Desktop options (swipe up)</string>
|
||||
<string name="settings_place_steam_qam">Steam quick menu (•••)</string>
|
||||
<string name="dev_group_logs">Logs</string>
|
||||
<string name="dev_ui_zoo">UI zoo</string>
|
||||
<string name="dev_ui_zoo_hint">Screens that are hard to reach, shown only when you pick one</string>
|
||||
<string name="dev_ui_zoo_open">Open</string>
|
||||
<string name="dev_ui_zoo_show">Show</string>
|
||||
<string name="dev_ui_zoo_note">Previews change nothing real: nothing is installed, removed or signed out, and the menu\'s switches save nothing. A Library preview stays until you end it from its pill or restart.</string>
|
||||
<string name="dev_preview_library">Library</string>
|
||||
<string name="dev_preview_library_nothing_installed">Nothing installed</string>
|
||||
<string name="dev_preview_library_signed_out">Signed out of every store</string>
|
||||
<string name="dev_preview_library_sample">Sample games in every store</string>
|
||||
<string name="dev_preview_banner">Preview: %1$s</string>
|
||||
<string name="dev_preview_end">End preview</string>
|
||||
<string name="dev_preview_real">Real library</string>
|
||||
<string name="dev_preview_shortcut">Preview a state</string>
|
||||
<string name="dev_preview_shortcuts">Preview shortcuts</string>
|
||||
<string name="dev_preview_shortcuts_hint">Adds a preview button where a state lives, such as the Library\'s toolbar, to switch states in place</string>
|
||||
<string name="dev_preview_read_only">Previews are read-only. End the preview to open games.</string>
|
||||
<string name="dev_preview_drawer">In-game menu</string>
|
||||
<string name="dev_preview_drawer_backdrop">In-game menu preview · Back to close</string>
|
||||
<string name="settings_place_tab">Tabs</string>
|
||||
<string name="rail_storage">Storage</string>
|
||||
<string name="rail_sync">Syncthing</string>
|
||||
|
||||
Reference in new issue
Block a user