Games: revamped add games feature (#492)

Adding and managing your own (non-Steam) games moves out of the Steam
settings into the Games tab, and works like Steam's own non-Steam
Properties.

- A + beside "Games N" opens a compact in-app picker: the storage first,
  then that storage's root, every folder, .exe files only. Picking an exe
  adds the game with its name, art, Custom badge and Steam shortcut.
- "Add all games in this folder" adds every game folder inside at once.
  A summary opens immediately and fills in as each game is found, with a
  "?" where the exe was a close call and a red X to remove a game.
- An edit button on each Custom game opens its editor: Name, Target
  (ranked exes, Other exe…), Start in, Launch options, the four pieces of
  art with thumbnails, and Remove. Edits go through the same Steam
  shortcut, so the appid never changes and nothing duplicates.
- Art chooser per piece: images in the game folder, Steam's official art,
  SteamGridDB alternatives, your own image, or back to automatic.
- Finding the exe: up to five folders deep, every exe scored (name match,
  Unreal -Shipping builds, bin folders and size up; launchers, crash
  reporters, installers, redistributables and depth down).
- Real titles from the game's files (Steam manifest, GOG info, the exe's
  version info), keeping the folder's spacing when both spell the same
  title, underscores read as spaces.
- Art: the exact Steam appid when the game names one, strict name
  matches otherwise, Steam's hashed asset paths for newer games,
  SteamGridDB as a fallback (built-in key from the SGDB_API_KEY secret,
  optional own key in Setup, sealed with the Keystore), and a cover made
  from the exe's icon when nothing else has one.
- Removing a game is instant and keeps its files; adding it again brings
  it back. Steam's shortcut list is rewritten once, in the background.
- The Games section is gone from Steam settings; folders added before
  keep listing their games. Artwork switch and SteamGridDB key are in
  Setup.
This commit is contained in:
The412Banner authored and GitHub committed 2026-10-09 19:50:03 -04:00
1 parent d99ed8e00b
commit d250b43eb9
45 files changed
+4175 -295

No files matched your search

@@ -41,6 +41,7 @@ import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -313,12 +314,17 @@ internal fun rememberShown(onDismiss: () -> Unit): MutableTransitionState<Boolea
@Composable
internal fun AppDialog(
shown: MutableTransitionState<Boolean>, close: () -> Unit, label: String, wide: Boolean,
modifier: Modifier = Modifier, maxWidth: Dp? = null, content: @Composable ColumnScope.() -> Unit,
modifier: Modifier = Modifier, maxWidth: Dp? = null,
/** [width] fixed, else as wide as its content when [fitContent], else as wide as it may be. */
width: Dp? = null, fitContent: Boolean = false,
/** What B / Back does, when not [close] (a picker goes up a folder first). */
back: (() -> Unit)? = null,
content: @Composable ColumnScope.() -> Unit,
) {
val pal = LocalPalette.current
// The page's ring stays out of sight behind it.
VeilRing()
Dialog(onDismissRequest = close, properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false)) {
Dialog(onDismissRequest = back ?: close, properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false)) {
// The page's focus memory stays the page's: nothing in here is a place to come back to.
CompositionLocalProvider(LocalFrontFocus provides null) {
Box(
@@ -337,14 +343,20 @@ internal fun AppDialog(
modifier = Modifier
.padding(12.dp)
.widthIn(max = maxWidth ?: if (wide) 860.dp else 560.dp)
.fillMaxWidth()
.then(
when {
width != null -> Modifier.width(width)
fitContent -> Modifier.width(androidx.compose.foundation.layout.IntrinsicSize.Max)
else -> Modifier.fillMaxWidth()
},
)
.heightIn(max = (LocalConfiguration.current.screenHeightDp - 24).dp)
.shadow(24.dp, Shape16, ambientColor = Color.Black, spotColor = Color.Black)
.clip(Shape16)
.background(pal.surfaceVariant.copy(alpha = 0.97f))
.border(1.dp, pal.signal.copy(alpha = 0.22f), Shape16)
.clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) {}
.controllerBack(close)
.controllerBack(back ?: close)
.then(modifier)
.verticalScroll(rememberScrollState())
.padding(horizontal = 18.dp, vertical = 16.dp),
@@ -0,0 +1,555 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.outlined.Image
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.droiddeck.launcher.R
import com.droiddeck.launcher.frontend.AddedGameArt
import com.droiddeck.launcher.frontend.AddedGameEdits
import com.droiddeck.launcher.frontend.AddedGames
import com.droiddeck.launcher.session.SessionPrefs
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
/** Each art slot's thumbnail, in its true shape: width, height, corner. */
private fun AddedGameArt.Slot.shape(): Triple<Dp, Dp, Dp> = when (this) {
AddedGameArt.Slot.COVER -> Triple(28.dp, 41.dp, 5.dp)
AddedGameArt.Slot.BACKGROUND -> Triple(60.dp, 34.dp, 5.dp)
AddedGameArt.Slot.LOGO -> Triple(60.dp, 26.dp, 5.dp)
AddedGameArt.Slot.ICON -> Triple(30.dp, 30.dp, 7.dp)
}
@Composable
private fun AddedGameArt.Slot.label(): String = stringResource(
when (this) {
AddedGameArt.Slot.COVER -> R.string.art_cover
AddedGameArt.Slot.BACKGROUND -> R.string.art_background
AddedGameArt.Slot.LOGO -> R.string.art_logo
AddedGameArt.Slot.ICON -> R.string.art_icon
},
)
@Composable
private fun artSourceLabel(source: String): String = stringResource(
when (source) {
AddedGameArt.FOLDER -> R.string.art_src_folder
AddedGameArt.STEAM -> R.string.art_src_steam
AddedGameArt.SGDB -> R.string.art_src_sgdb
AddedGameArt.FILE -> R.string.art_src_file
AddedGameArt.EXE -> R.string.art_src_exe
else -> R.string.art_src_auto
},
)
/** A thumbnail of [model] (a file or URL) in [slot]'s shape, scaled by [scale]. */
@Composable
private fun SlotThumb(slot: AddedGameArt.Slot, model: Any?, scale: Float = 1f, selected: Boolean = false) {
val pal = LocalPalette.current
val (w, h, r) = slot.shape()
val shape = RoundedCornerShape(r)
Box(
Modifier.size(w * scale, h * scale).clip(shape).background(MaterialTheme.colorScheme.surfaceVariant)
.border(if (selected) 2.dp else 1.dp, if (selected) pal.signal else pal.line, shape),
) {
if (model != null) AsyncImage(
model = model, contentDescription = null,
contentScale = if (slot == AddedGameArt.Slot.LOGO || slot == AddedGameArt.Slot.ICON) ContentScale.Fit else ContentScale.Crop,
modifier = Modifier.matchParentSize(),
)
}
}
/** A row of the editor: a label column, then the value. */
@Composable
private fun FieldRow(label: String, focus: FocusRequester? = null, onClick: () -> Unit, value: @Composable () -> Unit) {
ListRow(focus = focus, onClick = onClick) {
Text(label, fontSize = 14.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.width(110.dp))
Box(Modifier.weight(1f)) { value() }
}
}
/** Where the editor opens: its game's folder, straight on Target, and whether it came from the added-games summary. */
internal class EditRequest(val folder: String, val openTarget: Boolean, val fromSummary: Boolean, val preview: EditPreview)
/**
* What the editor shows on its first frame, from what the page already has (the game's row, or
* the summary's); the rest (the ranked exes, where each piece of art came from) follows.
* [exeName] / [startIn] null = not known yet.
*/
internal class EditPreview(
val name: String, val exeName: String?, val startIn: String?, val launchOptions: String,
val art: Map<AddedGameArt.Slot, File?>,
) {
companion object {
/** From the Games tab's row for [game] and the few preferences the edits keep. */
fun of(context: android.content.Context, game: com.droiddeck.launcher.frontend.Library.SteamGame, folder: String): EditPreview {
val exe = SessionPrefs.addedGameExe(context, folder).ifEmpty {
com.droiddeck.launcher.frontend.AddedExes.list(context).firstOrNull { it.folder == folder && it.picked }?.exe.orEmpty()
}.takeIf { it.isNotEmpty() }?.let { File(it) }
val startIn = SessionPrefs.addedGameStartIn(context, folder).takeIf { it.isNotEmpty() }?.substringAfterLast('/') ?: exe?.parentFile?.name
return EditPreview(
game.name, exe?.name, startIn, SessionPrefs.addedGameLaunch(context, folder),
mapOf(AddedGameArt.Slot.COVER to game.art, AddedGameArt.Slot.BACKGROUND to game.hero, AddedGameArt.Slot.ICON to game.icon),
)
}
/** From a summary row's game and its cover. */
fun of(game: AddedGames.Game, cover: File?) = EditPreview(
game.name, game.exe.name, game.guestDir.substringAfterLast('/'), game.launchOptions, mapOf(AddedGameArt.Slot.COVER to cover),
)
}
}
/** A small spinner where a value is still being read. */
@Composable
private fun Loading() {
androidx.compose.material3.CircularProgressIndicator(Modifier.size(14.dp), strokeWidth = 2.dp)
}
/**
* An added game's editor, Steam's non-Steam Properties in the app: Name, Target (the ranked exes,
* "?" where nothing clearly won, Other exe…), Start in, Launch options, the four pieces of art, and
* Remove (two presses; the files stay). Every change goes through the game's own Steam shortcut.
*/
@Composable
internal fun AddedGameEditor(
request: EditRequest, onBack: () -> Unit, onClose: () -> Unit, onChanged: () -> Unit,
/** Remove pressed twice: the game's folder, its shortcut appid when known, its name. */
onRemove: (folder: String, appId: Long?, name: String) -> Unit,
) {
val ctx = LocalContext.current
val app = ctx.applicationContext
val colors = MaterialTheme.colorScheme
val scope = rememberCoroutineScope()
val shown = rememberShown(onClose)
val close = { shown.targetState = false }
val folder = request.folder
var version by remember { mutableIntStateOf(0) }
var game by remember { mutableStateOf<AddedGames.Game?>(null) }
var arts by remember { mutableStateOf<List<AddedGameArt.SlotState>>(emptyList()) }
var ranked by remember { mutableStateOf<List<File>?>(null) }
var targetOpen by remember { mutableStateOf(request.openTarget) }
var armed by remember { mutableStateOf(false) }
var editing by remember { mutableStateOf<String?>(null) }
var otherExe by remember { mutableStateOf(false) }
var artSlot by remember { mutableStateOf<AddedGameArt.Slot?>(null) }
var unreachable by remember { mutableStateOf(false) }
LaunchedEffect(version) {
withContext(Dispatchers.IO) {
val g = AddedGameEdits.game(app, folder)
game = g
if (g != null) {
ranked = g.candidates.let { list -> if (list.any { it.path == g.exe.path }) list else listOf(g.exe) + list }
arts = AddedGameArt.describe(app, g)
}
}
}
LaunchedEffect(armed) { if (armed) { kotlinx.coroutines.delay(4_000); armed = false } }
val change: (() -> Unit) -> Unit = { work ->
scope.launch {
withContext(Dispatchers.IO) { work() }
version++
onChanged()
}
}
val first = remember { FocusRequester() }
LaunchedEffect(Unit) { focusWithinFrames({ false }) { first } }
val preview = request.preview
AppDialog(shown, close, "gameEditor", wide = false, maxWidth = 460.dp) {
val g = game
val name = g?.name ?: preview.name
DialogTitleRow(
name, onClose = close,
leading = if (request.fromSummary) ({ SmallIconButton(Icons.AutoMirrored.Filled.ArrowBack, stringResource(R.string.common_back), colors.onBackground) { onBack(); close() } }) else null,
)
val maxHeight = (LocalConfiguration.current.screenHeightDp * 0.72f).dp
Column(
verticalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier.fillMaxWidth().heightIn(max = maxHeight).verticalScroll(rememberScrollState()),
) {
FieldRow(stringResource(R.string.edit_name), focus = first, onClick = { editing = "name" }) { ValueText(name) }
FieldRow(stringResource(R.string.edit_target), onClick = { targetOpen = !targetOpen }) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
val exeName = g?.exe?.name ?: preview.exeName
Box(Modifier.weight(1f)) { if (exeName != null) ValueText(exeName) else Loading() }
if (g == null && exeName != null) Loading()
if (g?.exeUncertain == true) UncertainMark(stringResource(R.string.mode_added_exe_check))
}
}
if (targetOpen) {
Column(verticalArrangement = Arrangement.spacedBy(4.dp), modifier = Modifier.padding(start = 16.dp)) {
val list = ranked
if (g == null || list == null) Box(Modifier.padding(8.dp)) { Loading() }
else for (exe in list) key(exe.path) {
val rel = exe.relativeToOrSelf(g.folder).invariantSeparatorsPath
PickerRow(null, exe.name, rel.substringBeforeLast('/', "").ifEmpty { null }, accent = exe.path == g.exe.path) {
targetOpen = false
change { AddedGameEdits.setExe(app, folder, exe) }
}
}
PickerRow(null, stringResource(R.string.edit_other_exe), null, enabled = g != null) { otherExe = true }
}
}
FieldRow(stringResource(R.string.edit_start_in), onClick = { if (g != null) editing = "start" }) {
val startIn = g?.guestDir?.substringAfterLast('/') ?: preview.startIn
if (startIn != null) ValueText(startIn) else Loading()
}
val launch = g?.launchOptions ?: preview.launchOptions
FieldRow(stringResource(R.string.edit_launch_options), onClick = { editing = "launch" }) { ValueText(launch.ifEmpty { "—" }, muted = launch.isEmpty()) }
Text(stringResource(R.string.edit_artwork), fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(start = 4.dp, top = 8.dp))
for (slot in AddedGameArt.Slot.values()) key(slot) {
val state = arts.firstOrNull { it.slot == slot }
FieldRow(slot.label(), onClick = { if (g != null) artSlot = slot }) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
SlotThumb(slot, if (state != null) state.file else preview.art[slot])
if (state != null) ValueText(artSourceLabel(state.source), muted = true) else Loading()
}
}
}
RemoveRow(armed) {
if (!armed) armed = true else {
armed = false
// At once: the page drops the game and the rest runs off this dialog's life.
onRemove(folder, game?.appId, game?.name ?: preview.name)
if (request.fromSummary) onBack()
close()
}
}
}
if (unreachable) Text(stringResource(R.string.games_add_unreachable), fontSize = 12.sp, color = colors.error)
}
val shownName = game?.name ?: preview.name
when (editing) {
"name" -> TextEntryDialog(stringResource(R.string.edit_name), SessionPrefs.addedGameName(ctx, folder).ifEmpty { shownName }, onDismiss = { editing = null }) { value ->
change { AddedGameEdits.setName(app, folder, if (value == shownName && SessionPrefs.addedGameName(app, folder).isEmpty()) "" else value) }
}
"launch" -> TextEntryDialog(stringResource(R.string.edit_launch_options), game?.launchOptions ?: preview.launchOptions, onDismiss = { editing = null }) { value ->
change { AddedGameEdits.setLaunchOptions(app, folder, value) }
}
}
val g = game ?: return
when (editing) {
"start" -> TextEntryDialog(stringResource(R.string.edit_start_in), hostPath(ctx, g), onDismiss = { editing = null }) { value ->
scope.launch {
val ok = withContext(Dispatchers.IO) { AddedGameEdits.setStartIn(app, folder, if (value == g.exe.parentFile?.path) "" else value) }
unreachable = !ok
version++
onChanged()
}
}
}
if (otherExe) ExePickerDialog(stringResource(R.string.games_pick_exe_title), start = g.folder, onDismiss = { otherExe = false }, onPick = { exe ->
targetOpen = false
scope.launch {
val ok = withContext(Dispatchers.IO) { AddedGameEdits.setExe(app, folder, exe) }
unreachable = !ok
version++
onChanged()
}
})
artSlot?.let { slot ->
val current = arts.firstOrNull { it.slot == slot }
ArtChooserDialog(g, slot, current, onBack = { artSlot = null }, onCloseAll = { artSlot = null; close() }) { version++; onChanged() }
}
}
/** Start in as a path on the device: the override mapped back under the game's folder, else the exe's folder. */
private fun hostPath(context: android.content.Context, game: AddedGames.Game): String {
val folderGuest = AddedGames.guestPath(context, game.folder) ?: return game.exe.parentFile?.path.orEmpty()
return when {
game.guestDir == folderGuest -> game.folder.path
game.guestDir.startsWith("$folderGuest/") -> game.folder.path + game.guestDir.removePrefix(folderGuest)
else -> game.exe.parentFile?.path.orEmpty()
}
}
@Composable
private fun ValueText(text: String, muted: Boolean = false) {
Text(
text, fontSize = 14.sp, color = if (muted) MaterialTheme.colorScheme.onSurfaceVariant else MaterialTheme.colorScheme.onBackground,
maxLines = 1, overflow = TextOverflow.Ellipsis,
)
}
/** "Remove" in red; pressed once it asks, a second press within four seconds removes. */
@Composable
private fun RemoveRow(armed: Boolean, onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val src = remember { androidx.compose.foundation.interaction.MutableInteractionSource() }
val hot = rememberHot(src)
Box(
Modifier.fillMaxWidth().padding(top = 8.dp).clip(Shape12)
.background(if (armed) colors.error.copy(alpha = 0.18f) else if (hot) colors.error.copy(alpha = 0.10f) else androidx.compose.ui.graphics.Color.Transparent)
.glideBorder(hot, Shape12, colors.error, colors.error.copy(alpha = 0.4f))
.hoverable(src)
.clickable(interactionSource = src, indication = androidx.compose.foundation.LocalIndication.current, role = Role.Button, onClick = onClick)
.controllerConfirm(onClick = onClick)
.padding(horizontal = 12.dp, vertical = 10.dp),
) {
Text(
stringResource(if (armed) R.string.mode_added_remove_confirm else R.string.edit_remove),
fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = colors.error,
)
}
}
/** One line of text in a compact dialog: [title] and a red X, the field, OK. */
@Composable
internal fun TextEntryDialog(title: String, initial: String, onDismiss: () -> Unit, onSave: (String) -> Unit) {
val shown = rememberShown(onDismiss)
val close = { shown.targetState = false }
var value by remember { mutableStateOf(initial) }
val focus = remember { FocusRequester() }
LaunchedEffect(Unit) { focusWithinFrames({ false }) { focus } }
AppDialog(shown, close, "textEntry", wide = false, maxWidth = 460.dp) {
DialogTitleRow(title, onClose = close)
androidx.compose.material3.OutlinedTextField(
value, { value = it }, singleLine = true, modifier = Modifier.fillMaxWidth().focusRequester(focus),
keyboardActions = androidx.compose.foundation.text.KeyboardActions(onDone = { onSave(value.trim()); close() }),
keyboardOptions = androidx.compose.foundation.text.KeyboardOptions(imeAction = androidx.compose.ui.text.input.ImeAction.Done),
)
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
SecondaryButton(stringResource(R.string.common_ok), compact = true) { onSave(value.trim()); close() }
}
}
}
/**
* The art chooser for one [slot]: back, the slot's name and a red X; the images grouped by where
* they come from (the game's folder, Steam, SteamGridDB, fetched as it opens), the current one
* outlined, a tap applies it; "Pick image…" and "Reset to automatic".
*/
@OptIn(ExperimentalLayoutApi::class)
@Composable
private fun ArtChooserDialog(
game: AddedGames.Game, slot: AddedGameArt.Slot, current: AddedGameArt.SlotState?,
onBack: () -> Unit, onCloseAll: () -> Unit, onChanged: () -> Unit,
) {
val ctx = LocalContext.current
val app = ctx.applicationContext
val colors = MaterialTheme.colorScheme
val scope = rememberCoroutineScope()
val shown = rememberShown(onBack)
val back = { shown.targetState = false }
var options by remember { mutableStateOf<List<AddedGameArt.Option>?>(null) }
var picking by remember { mutableStateOf(false) }
val chosenRef = remember(current) { AddedGameArt.chosenSource(app, game, slot).second }
LaunchedEffect(slot) { options = withContext(Dispatchers.IO) { runCatching { AddedGameArt.options(app, game, slot) }.getOrDefault(emptyList()) } }
val first = remember { FocusRequester() }
LaunchedEffect(Unit) { focusWithinFrames({ false }) { first } }
val apply: (AddedGameArt.Option) -> Unit = { option ->
scope.launch {
withContext(Dispatchers.IO) { AddedGameEdits.setArt(app, game.folder.path, slot, option) }
onChanged()
back()
}
}
val slotName = slot.label()
AppDialog(shown, back, "artChooser", wide = false, maxWidth = 460.dp) {
DialogTitleRow(slotName, onClose = { onCloseAll() }, leading = {
SmallIconButton(Icons.AutoMirrored.Filled.ArrowBack, stringResource(R.string.common_back), colors.onBackground, onClick = back)
})
val maxHeight = (LocalConfiguration.current.screenHeightDp * 0.72f).dp
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.fillMaxWidth().heightIn(max = maxHeight).verticalScroll(rememberScrollState()),
) {
val opts = options
if (opts == null) {
androidx.compose.material3.LinearProgressIndicator(Modifier.fillMaxWidth().padding(vertical = 8.dp))
} else {
var firstGiven = false
for (group in listOf(AddedGameArt.FOLDER, AddedGameArt.STEAM, AddedGameArt.SGDB)) {
val inGroup = opts.filter { it.group == group }
if (inGroup.isEmpty()) continue
Text(artSourceLabel(group), fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(start = 2.dp, top = 4.dp))
FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
for (option in inGroup) key(option.full) {
val focus = if (!firstGiven) first.also { firstGiven = true } else null
ArtOption(slot, option, selected = current?.chosen == true && option.full == chosenRef, focus = focus, description = "${artSourceLabel(group)} $slotName") { apply(option) }
}
}
}
}
PickerRow(Icons.Outlined.Image, stringResource(R.string.art_pick_image), null, focus = if (opts?.isEmpty() != false) first else null) { picking = true }
PickerRow(null, stringResource(R.string.art_reset), null) {
scope.launch {
withContext(Dispatchers.IO) { AddedGameEdits.resetArt(app, game.folder.path, slot) }
onChanged()
back()
}
}
}
}
if (picking) ExePickerDialog(stringResource(R.string.art_pick_title, slotName), kind = PickKind.IMAGE, onDismiss = { picking = false }, onPick = { file ->
apply(AddedGameArt.Option(AddedGameArt.FILE, file.path, file.path))
})
}
@Composable
private fun ArtOption(slot: AddedGameArt.Slot, option: AddedGameArt.Option, selected: Boolean, focus: FocusRequester?, description: String, onClick: () -> Unit) {
val pal = LocalPalette.current
val src = remember { androidx.compose.foundation.interaction.MutableInteractionSource() }
val hot = rememberHot(src)
val scale = when (slot) { AddedGameArt.Slot.COVER -> 1.9f; AddedGameArt.Slot.ICON -> 1.6f; else -> 1.5f }
Box(
Modifier.then(if (focus != null) Modifier.focusRequester(focus) else Modifier).clip(RoundedCornerShape(8.dp))
.glideBorder(hot, RoundedCornerShape(8.dp), pal.signal)
.hoverable(src)
.clickable(interactionSource = src, indication = androidx.compose.foundation.LocalIndication.current, role = Role.Button, onClick = onClick)
.controllerConfirm(onClick = onClick)
.semantics { contentDescription = description }
.padding(2.dp),
) {
SlotThumb(slot, if (option.thumb.startsWith("https://")) option.thumb else File(option.thumb), scale, selected)
}
}
/**
* After "Add all games in this folder": how many were added and how many were there already, then
* one row per added game (cover, name, exe, "?" where unsure); a row opens that game's editor.
* [games] are the added games as the add left them, shown at once; the rows then follow edits and
* removals, and the covers arrive.
*/
@Composable
internal fun AddedGamesSummaryDialog(
games: List<AddedGames.Game>, already: Int, checking: String? = null,
onOpen: (folder: String, uncertain: Boolean, preview: EditPreview) -> Unit,
onRemove: (folder: String, appId: Long?, name: String) -> Unit,
onDismiss: () -> Unit,
) {
val ctx = LocalContext.current
val app = ctx.applicationContext
val colors = MaterialTheme.colorScheme
val shown = rememberShown(onDismiss)
val close = { shown.targetState = false }
var rows by remember { mutableStateOf(games.map { it to (null as File?) }) }
var gone by remember { mutableStateOf(emptySet<String>()) }
var armed by remember { mutableStateOf<String?>(null) }
LaunchedEffect(armed) { if (armed != null) { kotlinx.coroutines.delay(4_000); armed = null } }
// Rows show as the games arrive; each is refreshed once (current name and exe, a removed one
// dropped) and gets its cover, without redoing the ones already done when more arrive.
var resolved by remember { mutableStateOf(emptyMap<String, Pair<AddedGames.Game, File?>?>()) }
LaunchedEffect(games) {
for (old in games) {
val path = old.folder.path
if (path in resolved) continue
val fresh = withContext(Dispatchers.IO) { AddedGames.single(app, path)?.let { g -> g to AddedGameArt.resolve(app, g).portrait } }
resolved = resolved + (path to fresh)
}
}
LaunchedEffect(games, resolved) {
rows = games.mapNotNull { g -> if (g.folder.path in resolved) resolved[g.folder.path] else g to null }
}
val first = remember { FocusRequester() }
val list = rows.filter { it.first.folder.path !in gone }
LaunchedEffect(list.isNotEmpty()) { if (list.isNotEmpty()) focusWithinFrames({ false }) { first } }
AppDialog(shown, close, "addedSummary", wide = false, maxWidth = 440.dp) {
DialogTitleRow(
if (list.isEmpty() && checking == null) stringResource(R.string.games_added_none) else pluralStringResource(R.plurals.games_added_n, list.size, list.size),
onClose = close,
)
if (already > 0) Text(pluralStringResource(R.plurals.games_already_n, already, already), fontSize = 12.sp, color = colors.onSurfaceVariant)
if (checking != null) Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
androidx.compose.material3.CircularProgressIndicator(Modifier.size(14.dp), strokeWidth = 2.dp, color = colors.primary)
Text(checking, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
val maxHeight = (LocalConfiguration.current.screenHeightDp * 0.7f).dp
Column(
verticalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier.fillMaxWidth().heightIn(max = maxHeight).verticalScroll(rememberScrollState()),
) {
list.forEachIndexed { i, (g, cover) ->
key(g.folder.path) {
ListRow(focus = if (i == 0) first else null, onClick = { onOpen(g.folder.path, g.exeUncertain, EditPreview.of(g, cover)); close() }) {
SlotThumb(AddedGameArt.Slot.COVER, cover, 0.9f)
Column(Modifier.weight(1f)) {
Text(g.name, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
Text(g.exe.name, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
if (g.exeUncertain) UncertainMark(stringResource(R.string.mode_added_exe_check))
val path = g.folder.path
RemoveX(armed == path, stringResource(R.string.summary_remove_game, g.name)) {
if (armed != path) armed = path else {
armed = null
gone = gone + path
onRemove(path, g.appId, g.name)
}
}
}
}
}
}
}
}
/** A summary row's red X: the first press arms it (filled), a second within 4 s removes the game. */
@Composable
private fun RemoveX(armed: Boolean, description: String, onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val src = remember { androidx.compose.foundation.interaction.MutableInteractionSource() }
val hot = rememberHot(src)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.size(32.dp).clip(Shape12)
.background(if (armed) colors.error else if (hot) colors.error.copy(alpha = 0.15f) else androidx.compose.ui.graphics.Color.Transparent)
.glideBorder(hot, Shape12, colors.error)
.hoverable(src)
.clickable(interactionSource = src, indication = androidx.compose.foundation.LocalIndication.current, role = Role.Button, onClick = onClick)
.controllerConfirm(onClick = onClick)
.semantics { contentDescription = description },
) {
androidx.compose.material3.Icon(Icons.Filled.Close, null, tint = if (armed) colors.onError else colors.error, modifier = Modifier.size(18.dp))
}
}
@@ -0,0 +1,234 @@
package com.droiddeck.launcher.ui
import android.content.Context
import android.os.Environment
import android.os.StatFs
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
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.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.ArrowBack
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.outlined.Folder
import androidx.compose.material.icons.outlined.Image
import androidx.compose.material.icons.outlined.InsertDriveFile
import androidx.compose.material.icons.outlined.SdCard
import androidx.compose.material.icons.outlined.Smartphone
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
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.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.droiddeck.launcher.R
import com.droiddeck.launcher.session.GameStorage
import com.droiddeck.launcher.stores.formatBytes
import java.io.File
/** What a picker lists besides folders. */
internal enum class PickKind(val extensions: Set<String>) {
EXE(setOf("exe")),
IMAGE(setOf("png", "jpg", "jpeg", "webp", "ico")),
}
/** A place a file can be picked from: internal storage or a card, at its root. */
internal class PickVolume(val root: File, val label: String, val removable: Boolean) {
val free: Long get() = runCatching { StatFs(root.path).availableBytes }.getOrDefault(0L)
}
internal fun pickVolumes(context: Context): List<PickVolume> =
listOf(PickVolume(Environment.getExternalStorageDirectory(), context.getString(R.string.games_internal), removable = false)) +
GameStorage.options(context).mapNotNull { o ->
File(o.path.substringBefore("/Android/")).takeIf { it.isDirectory }?.let { PickVolume(it, o.name, removable = true) }
}.distinctBy { it.root.absolutePath }
/** A folder in a listing; [readable] false = shown greyed, not opened. */
internal class PickFolder(val dir: File, val readable: Boolean)
internal class PickListing(val folders: List<PickFolder>, val files: List<File>)
/**
* Every folder of [dir] (dot-folders left out, the unreadable ones marked), then the files [kind]
* takes; each A-Z.
*/
internal fun pickListing(dir: File, kind: PickKind): PickListing {
val all = dir.listFiles()?.filter { !it.name.startsWith(".") }.orEmpty().sortedBy { it.name.lowercase() }
return PickListing(
all.filter { it.isDirectory }.map { PickFolder(it, it.canRead() && it.list() != null) },
all.filter { it.isFile && it.extension.lowercase() in kind.extensions },
)
}
/**
* The compact in-app file picker: [title] and a red X on one line; the storage rows (internal
* storage, each card, free space); inside one, its root first, a breadcrumb, "..", every folder
* and the [kind] files, scrolling in the dialog. Its width is what the first step needed and stays;
* long names are cut short. B / Back goes up a folder, and closes from the storage rows. [start]
* opens in a folder. [onAddAll] adds a row on top of a folder with subfolders.
*/
@Composable
internal fun ExePickerDialog(
title: String, kind: PickKind = PickKind.EXE, start: File? = null,
onAddAll: ((File) -> Unit)? = null, onPick: (File) -> Unit, onDismiss: () -> Unit,
) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
val density = LocalDensity.current
val shown = rememberShown(onDismiss)
val close = { shown.targetState = false }
val volumes = remember { pickVolumes(ctx) }
fun volumeOf(d: File) = volumes.filter { d.path == it.root.path || d.path.startsWith(it.root.path + "/") }.maxByOrNull { it.root.path.length }
var dir by remember { mutableStateOf(start?.takeIf { it.isDirectory && volumeOf(it) != null }) }
val volume = dir?.let { volumeOf(it) }
val up = { dir = dir?.let { d -> if (volume == null || d.path == volume.root.path) null else d.parentFile } }
val back = { if (dir == null) close() else up() }
val first = remember(dir) { FocusRequester() }
LaunchedEffect(dir) { focusWithinFrames({ false }) { first } }
val listing = remember(dir) { dir?.let { pickListing(it, kind) } }
var locked by remember { mutableStateOf<Dp?>(null) }
AppDialog(
shown, close, "filePicker", wide = false, maxWidth = 520.dp, width = locked, fitContent = locked == null, back = back,
modifier = Modifier.onSizeChanged { if (locked == null && it.width > 0) locked = with(density) { it.width.toDp() } },
) {
Column(verticalArrangement = Arrangement.spacedBy(6.dp), modifier = Modifier.fillMaxWidth()) {
DialogTitleRow(title, onClose = close)
if (dir != null && volume != null) {
val crumbs = listOf(volume.label) + dir!!.path.removePrefix(volume.root.path).split('/').filter { it.isNotEmpty() }
Text(crumbs.joinToString(" › "), fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
val maxHeight = (LocalConfiguration.current.screenHeightDp * 0.7f).dp
Column(
verticalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier.fillMaxWidth().heightIn(max = maxHeight).verticalScroll(rememberScrollState()).padding(top = 4.dp),
) {
if (dir == null) {
volumes.forEachIndexed { i, v ->
key(v.root.path) {
PickerRow(if (v.removable) Icons.Outlined.SdCard else Icons.Outlined.Smartphone, v.label,
stringResource(R.string.stores_target_free, formatBytes(v.free)), tall = true, focus = if (i == 0) first else null) { dir = v.root }
}
}
} else {
val shownListing = listing ?: PickListing(emptyList(), emptyList())
PickerRow(Icons.AutoMirrored.Outlined.ArrowBack, "..", null, focus = first, onClick = up)
if (onAddAll != null && shownListing.folders.any { it.readable }) {
PickerRow(Icons.Filled.Add, stringResource(R.string.games_add_all), null, accent = true) { onAddAll(dir!!); close() }
}
for (f in shownListing.folders) key(f.dir.path) {
PickerRow(Icons.Outlined.Folder, f.dir.name, null, enabled = f.readable) { dir = f.dir }
}
for (f in shownListing.files) key(f.path) {
PickerRow(if (kind == PickKind.IMAGE) Icons.Outlined.Image else Icons.Outlined.InsertDriveFile, f.name, formatBytes(f.length()), file = true) {
onPick(f); close()
}
}
}
}
}
}
}
/** A compact dialog's title line: [leading] (a back arrow), the title, a small red X. */
@Composable
internal fun DialogTitleRow(title: String, onClose: () -> Unit, leading: (@Composable () -> Unit)? = null) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp), modifier = Modifier.fillMaxWidth()) {
leading?.invoke()
Text(title, fontSize = 15.sp, color = MaterialTheme.colorScheme.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
SmallIconButton(Icons.Filled.Close, stringResource(R.string.common_close), tint = MaterialTheme.colorScheme.error, onClick = onClose)
}
}
/** A 32 dp icon button for a dialog's title line. */
@Composable
internal fun SmallIconButton(icon: ImageVector, description: String, tint: androidx.compose.ui.graphics.Color, onClick: () -> Unit) {
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.size(32.dp).clip(Shape12)
.background(if (hot) tint.copy(alpha = 0.15f) else androidx.compose.ui.graphics.Color.Transparent)
.glideBorder(hot, Shape12, tint)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = onClick)
.controllerConfirm(onClick = onClick)
.semantics { contentDescription = description },
) {
Icon(icon, null, tint = tint, modifier = Modifier.size(18.dp))
}
}
/** One row of a compact dialog's list, the Install dialog's style: [content] laid out in a row. */
@Composable
internal fun ListRow(
enabled: Boolean = true, accent: Boolean = false, tall: Boolean = false, focus: FocusRequester? = null,
onClick: () -> Unit, content: @Composable androidx.compose.foundation.layout.RowScope.(hot: Boolean) -> Unit,
) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src) && enabled
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp),
modifier = Modifier.fillMaxWidth().then(if (focus != null) Modifier.focusRequester(focus) else Modifier).clip(Shape12)
.alpha(if (enabled) 1f else 0.4f)
.background(if (hot) pal.signal.copy(alpha = 0.14f) else colors.surface.copy(alpha = 0.6f))
.glideBorder(hot, Shape12, pal.signal, if (accent) pal.signal else pal.line)
.then(
if (enabled) Modifier.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = onClick)
.controllerConfirm(onClick = onClick) else Modifier,
)
.padding(horizontal = 12.dp, vertical = if (tall) 11.dp else 9.dp),
) { content(hot) }
}
/** A list row with an icon, a name (cut short when long) and a detail on the right. */
@Composable
internal fun PickerRow(
icon: ImageVector?, name: String, detail: String?, tall: Boolean = false, file: Boolean = false, accent: Boolean = false,
enabled: Boolean = true, focus: FocusRequester? = null, onClick: () -> Unit,
) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
ListRow(enabled, accent, tall, focus, onClick) { hot ->
if (icon != null) Icon(icon, null, tint = if (hot || file || accent) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(20.dp))
Text(name, fontSize = 14.sp, fontWeight = if (tall) FontWeight.SemiBold else FontWeight.Normal, color = colors.onBackground,
maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
if (detail != null) Text(detail, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, modifier = Modifier.padding(start = 8.dp))
}
}
@@ -30,6 +30,10 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Edit
import androidx.compose.ui.semantics.semantics
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@@ -55,6 +59,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.droiddeck.launcher.frontend.Library
import kotlinx.coroutines.launch
// The Games page: the list, the hero for the selected game and its labels.
@@ -67,9 +72,15 @@ internal fun GamesPage(s: FrontEndState, a: FrontEndActions, selected: String, o
val games = remember(s.steamGames) { s.steamGames.sortedByDescending { it.lastPlayed } }
val narrow = LocalNarrowPane.current
val current = games.firstOrNull { "app:${it.appId}" == selected } ?: games.firstOrNull()
GamesDialogs(a)
val onAdd: (() -> Unit)? = if (s.shortcutPicker) null else ({ GamesDialogState.adding = true })
val pageContext = androidx.compose.ui.platform.LocalContext.current
val onEdit: (Library.SteamGame) -> Unit = { g ->
g.gameFiles?.let { GamesDialogState.editing = EditRequest(it.path, openTarget = false, fromSummary = false, preview = EditPreview.of(pageContext, g, it.path)) }
}
if (current == null) {
Column(modifier = modifier.padding(horizontal = if (narrow) 16.dp else 22.dp, vertical = if (narrow) 12.dp else 18.dp)) {
Rise(0) { PageHeader(stringResource(R.string.content_games)) }
Rise(0) { PageHeader(stringResource(R.string.content_games)) { onAdd?.let { AddGameButton(it) } } }
Rise(1) { Note(stringResource(if (s.shortcutPicker && s.shortcutLibraryScanning) R.string.game_shortcut_scanning else R.string.games_empty)) }
if (!s.shortcutPicker) Rise(2) {
Actions { PrimaryButton(stringResource(R.string.games_play_steam), enabled = !s.busy, main = true, icon = Icons.Filled.PlayArrow, modifier = Modifier.padding(top = 12.dp).testTag("play-steam"), onClick = a.onPlay) }
@@ -81,11 +92,12 @@ internal fun GamesPage(s: FrontEndState, a: FrontEndActions, selected: String, o
val host = rememberMenuHost()
if (games.size == 1) {
Column(modifier = modifier.verticalScroll(rememberScrollState()).padding(horizontal = if (narrow) 16.dp else 22.dp, vertical = if (narrow) 12.dp else 18.dp)) {
if (onAdd != null) Rise(0) { GamesHeader(1, onAdd, Modifier.padding(bottom = 10.dp)) }
Rise(0) {
Row(verticalAlignment = Alignment.Bottom) {
GameHero(current, Modifier.weight(1f).heightIn(min = if (narrow) 190.dp else 250.dp)) {
GameHeroCopy(current, if (narrow) 28.sp else 38.sp)
GameActions(current, s, a)
GameActions(current, s, a, onEdit)
}
if (!narrow) Poster(current.art, current.name, Modifier.width(168.dp))
}
@@ -98,7 +110,7 @@ internal fun GamesPage(s: FrontEndState, a: FrontEndActions, selected: String, o
}
val pal = LocalPalette.current
Row(modifier = modifier) {
GameList(games, current, onSelect = { onSelect("app:${it.appId}") }, onLaunch = { a.onSteamGame(it) },
GameList(games, current, onSelect = { onSelect("app:${it.appId}") }, onLaunch = { a.onSteamGame(it) }, onAdd = onAdd,
modifier = Modifier.width(if (narrow) 168.dp else 250.dp).fillMaxHeight())
Box(Modifier.width(1.dp).fillMaxHeight().background(pal.line))
Column(
@@ -107,7 +119,7 @@ internal fun GamesPage(s: FrontEndState, a: FrontEndActions, selected: String, o
) {
GameHero(current, Modifier.fillMaxWidth().heightIn(min = if (narrow) 170.dp else 200.dp)) {
GameHeroCopy(current, if (narrow) 24.sp else 32.sp)
GameActions(current, s, a)
GameActions(current, s, a, onEdit)
}
SectionTitle(stringResource(R.string.games_launch_settings), null)
LaunchSettings(s, a, host, current)
@@ -135,7 +147,7 @@ private fun GameFileFolderActions(s: FrontEndState, a: FrontEndActions) {
@Composable
private fun GameActions(g: Library.SteamGame, s: FrontEndState, a: FrontEndActions) {
private fun GameActions(g: Library.SteamGame, s: FrontEndState, a: FrontEndActions, onEdit: (Library.SteamGame) -> Unit) {
Actions {
PrimaryButton(stringResource(if (s.shortcutPicker) R.string.game_shortcut_choose else R.string.games_launch), enabled = !s.busy, main = true, icon = Icons.Filled.PlayArrow) { a.onSteamGame(g) }
g.gameFiles?.takeIf { it.isDirectory }?.let { dir ->
@@ -147,6 +159,8 @@ private fun GameActions(g: Library.SteamGame, s: FrontEndState, a: FrontEndActio
if (g.library == Library.ADDED) ManageSaves(g, dir, a)
}
if (!s.shortcutPicker) GameShortcutMenu(g, a)
// A game added in DroidDeck (Custom): its editor, Steam's Properties for a non-Steam game.
if (!s.shortcutPicker && g.library == Library.ADDED && g.source == Library.ADDED && g.gameFiles != null) EditGameButton { onEdit(g) }
BusyChip(s)
}
}
@@ -299,7 +313,7 @@ private fun ColumnScope.GameHeroCopy(g: Library.SteamGame, titleSize: androidx.c
@Composable
private fun GameList(
games: List<Library.SteamGame>, current: Library.SteamGame,
onSelect: (Library.SteamGame) -> Unit, onLaunch: (Library.SteamGame) -> Unit, modifier: Modifier,
onSelect: (Library.SteamGame) -> Unit, onLaunch: (Library.SteamGame) -> Unit, onAdd: (() -> Unit)?, modifier: Modifier,
) {
val colors = MaterialTheme.colorScheme
// Laid out whole, as the art grid is: the pad's focus search only finds rows that exist.
@@ -307,16 +321,127 @@ private fun GameList(
verticalArrangement = Arrangement.spacedBy(2.dp),
modifier = modifier.verticalScroll(rememberScrollState()).padding(start = 12.dp, end = 10.dp, top = 16.dp, bottom = 16.dp),
) {
Row(verticalAlignment = Alignment.Bottom, horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(start = 6.dp, bottom = 10.dp)) {
Text(stringResource(R.string.content_games), fontSize = 22.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1)
Text(games.size.toString(), fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(bottom = 3.dp))
}
GamesHeader(games.size, onAdd, Modifier.padding(start = 6.dp, bottom = 10.dp))
for (g in games) key(g.appId) {
GameRow(g, g.appId == current.appId, onSelect = { onSelect(g) }, onLaunch = { onLaunch(g) })
}
}
}
/** "Games N", and the + that adds a game from its .exe beside it ([onAdd] null: no +). */
@Composable
private fun GamesHeader(count: Int, onAdd: (() -> Unit)?, modifier: Modifier) {
val colors = MaterialTheme.colorScheme
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier) {
Text(stringResource(R.string.content_games), fontSize = 22.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1)
Text(count.toString(), fontSize = 13.sp, color = colors.onSurfaceVariant)
if (onAdd != null) AddGameButton(onAdd)
}
}
/**
* The Games tab's dialogs, one at a time: the + picker, the summary after "Add all games in this
* folder", and a game's editor (from the page's ✎ or a summary row, with back to the summary).
*/
internal object GamesDialogState {
var adding by androidx.compose.runtime.mutableStateOf(false)
var summary by androidx.compose.runtime.mutableStateOf<Pair<List<com.droiddeck.launcher.frontend.AddedGames.Game>, Int>?>(null)
var editing by androidx.compose.runtime.mutableStateOf<EditRequest?>(null)
/** The subfolder "Add all games in this folder" is looking at; null when it is done. */
var checking by androidx.compose.runtime.mutableStateOf<String?>(null)
/** The summary an editor opened from it goes back to. */
var behindEditor: Pair<List<com.droiddeck.launcher.frontend.AddedGames.Game>, Int>? = null
}
@Composable
private fun GamesDialogs(a: FrontEndActions) {
val ctx = androidx.compose.ui.platform.LocalContext.current
val scope = androidx.compose.runtime.rememberCoroutineScope()
val st = GamesDialogState
if (st.adding) ExePickerDialog(
stringResource(R.string.games_add_title),
onAddAll = { dir ->
st.summary = emptyList<com.droiddeck.launcher.frontend.AddedGames.Game>() to 0
st.checking = dir.name
scope.launch {
val result = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {
com.droiddeck.launcher.frontend.AddedGames.addFolder(
ctx.applicationContext, dir,
onGame = { g -> scope.launch { st.summary?.let { (list, n) -> st.summary = (list + g) to n } } },
onChecking = { name -> scope.launch { st.checking = name } },
)
}
st.checking = null
a.onAddedGamesChanged(result.added.map { it.folder.path })
st.summary?.let { (list, _) -> st.summary = list to result.already }
}
},
onPick = { a.onAddGameExe(it.path) },
onDismiss = { st.adding = false },
)
st.summary?.let { (added, already) ->
AddedGamesSummaryDialog(added, already, checking = st.checking, onOpen = { folder, uncertain, preview ->
st.behindEditor = added to already
st.editing = EditRequest(folder, openTarget = uncertain, fromSummary = true, preview = preview)
}, onRemove = { folder, appId, name ->
st.summary = st.summary?.let { (list, n) -> list.filterNot { it.folder.path == folder } to n }
a.onAddedGameRemoved(folder, appId, name)
}, onDismiss = { st.summary = null; st.checking = null })
}
st.editing?.let { request ->
AddedGameEditor(
request,
onBack = { st.behindEditor?.let { st.summary = it }; st.behindEditor = null },
onClose = { st.editing = null },
onChanged = { a.onAddedGamesChanged(listOf(request.folder)) },
onRemove = { folder, appId, name -> a.onAddedGameRemoved(folder, appId, name) },
)
}
}
/** The ✎ on a Custom game's page: icon only. */
@Composable
private fun EditGameButton(onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src)
val label = stringResource(R.string.common_edit)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.paneItem("game:edit").size(40.dp).clip(Shape12)
.background(if (hot) pal.signal.copy(alpha = 0.18f) else colors.surface.copy(alpha = 0.55f))
.glideBorder(hot, Shape12, pal.signal, pal.line2)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = androidx.compose.ui.semantics.Role.Button, onClick = onClick)
.controllerConfirm(onClick = onClick)
.semantics { contentDescription = label },
) {
androidx.compose.material3.Icon(Icons.Outlined.Edit, contentDescription = null, tint = colors.onBackground, modifier = Modifier.size(18.dp))
}
}
/** A round + that opens the .exe picker. */
@Composable
private fun AddGameButton(onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val src = remember { MutableInteractionSource() }
val focused by src.collectIsFocusedAsState()
val hovered by src.collectIsHoveredAsState()
val label = stringResource(R.string.games_add)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.paneItem("games:add").size(32.dp).clip(CircleShape)
.background(if (focused || hovered) pal.signal.copy(alpha = 0.18f) else colors.surfaceVariant)
.glideBorder(focused, CircleShape, pal.signal)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = androidx.compose.ui.semantics.Role.Button, onClick = onClick)
.controllerConfirm(onClick = onClick)
.semantics { contentDescription = label },
) {
androidx.compose.material3.Icon(Icons.Filled.Add, contentDescription = null, tint = colors.onBackground, modifier = Modifier.size(20.dp))
}
}
/** One game in the list. Moving onto it with the pad shows it; A launches it, a tap only shows it. */
@Composable
private fun GameRow(g: Library.SteamGame, selected: Boolean, onSelect: () -> Unit, onLaunch: () -> Unit) {
@@ -137,6 +137,9 @@ class FrontEndState(
val storesOpenTab: String = SessionPrefs.STORES_OPEN_LIBRARY,
/** A page to open once: "stores:downloads", or a selection such as "app:<id>" (a notification's tap). */
val navigate: String? = null,
/** Setup: art for added games is fetched; the user has a SteamGridDB key of their own. */
val addedGamesArt: Boolean = true,
val sgdbUserKey: Boolean = false,
val storesShowMature: Boolean = false,
/** Downloads queued, running or paused across the three stores; the rail item's badge. */
val storeDownloadsActive: Int = 0,
@@ -151,6 +154,15 @@ class FrontEndActions(
val onGameShortcut: (Library.SteamGame) -> Unit = {},
val onExportGameFile: (Library.SteamGame) -> Unit = {},
val onSyncGameFiles: () -> Unit = {},
/** The Games tab's +: the .exe picked in its dialog, to add as a game. */
val onAddGameExe: (path: String) -> Unit = {},
/** These added games (by folder) were added or edited: the Games tab updates just them. */
val onAddedGamesChanged: (folders: List<String>) -> Unit = {},
/** An added game removed in its editor: off the Games tab at once, out of Steam after. */
val onAddedGameRemoved: (folder: String, appId: Long?, name: String) -> Unit = { _, _, _ -> },
/** Setup's Artwork switch and the user's SteamGridDB API key ("" removes it). */
val onAddedGamesArt: (Boolean) -> Unit = {},
val onSgdbKey: (String) -> Unit = {},
val onStopGameFileSync: () -> Unit = {},
val onCopyGameLink: (Library.SteamGame) -> Unit = {},
val onDesktop: () -> Unit,
@@ -164,6 +164,8 @@ internal fun SetupPanel(
val limitBlocks = PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)
val signedIn = s.offlineAccount != null
var showLimitDetails by rememberSaveable { mutableStateOf(false) }
var editSgdbKey by remember { mutableStateOf(false) }
if (editSgdbKey) SgdbKeyDialog(s.sgdbUserKey, onSave = { a.onSgdbKey(it); editSgdbKey = false }, onDismiss = { editSgdbKey = false })
// Four tabs instead of one long scroll; LB and RB turn them from anywhere on the page. Build
// and credits are on the Updates page.
val tabs = listOf(stringResource(R.string.setup_tab_overview), stringResource(R.string.setup_tab_controller), stringResource(R.string.setup_tab_session), stringResource(R.string.setup_tab_launcher))
@@ -368,6 +370,13 @@ internal fun SetupPanel(
s.storeEnabled,
) { a.onStoreEnabled(it) }
}
SettingsGroup(stringResource(R.string.content_games)) {
ToggleRow(host, "added-art", stringResource(R.string.mode_added_art), stringResource(R.string.mode_added_art_hint), s.addedGamesArt) { a.onAddedGamesArt(it) }
ActionRow(
stringResource(R.string.mode_sgdb_key), if (s.sgdbUserKey) stringResource(R.string.mode_sgdb_key_yours) else null,
stringResource(R.string.mode_sgdb_edit), onClick = { editSgdbKey = true },
)
}
SettingsGroup(stringResource(R.string.setup_stores)) {
ToggleRow(
host, "stores-enabled", stringResource(R.string.setup_stores_show),
@@ -103,10 +103,6 @@ class ModeSettings(
val wifiDiscoveryLocation: Boolean = false,
val wifiDiscoveryAsked: Boolean = false,
val wifiDiscoveryBlocked: Boolean = false,
/** Steam only: the user's chosen Games folders; null outside Steam. */
val addedGamesDirs: List<String>? = null,
val addedGames: List<AddedGameRow> = emptyList(),
val addedGamesArt: Boolean = true,
/** Latest Banners-Turnip release: what each driver menu offers to download, and the refresh line. */
/** Steam only: Decky Loader is managed from the Steam session settings. */
val deckyInstalled: String? = null,
@@ -120,9 +116,6 @@ class ModeSettings(
val deckySessionRunning: Boolean = false,
)
/** One added game as the settings page shows it: its folder, the chosen .exe, the other .exe files it could be. */
class AddedGameRow(val folderPath: String, val folderName: String, val exePath: String, val exeName: String, val candidates: List<Pair<String, String>>)
class ModeSettingsActions(
val onResolution: (String) -> Unit,
val onHdr: (Boolean) -> Unit,
@@ -154,11 +147,6 @@ class ModeSettingsActions(
val onRunSteamAtStartup: (Boolean) -> Unit = {},
val onWifiDiscovery: (Boolean) -> Unit = {},
val onWifiDiscoverySettings: () -> Unit = {},
val onPickAddedGamesDir: () -> Unit = {},
val onForgetAddedGamesDir: (path: String) -> Unit = {},
val onAddedGamesArt: (Boolean) -> Unit = {},
val onAddedGameExe: (folderPath: String, path: String) -> Unit = { _, _ -> },
val onPickAddedGameExe: (folderPath: String) -> Unit = {},
val onDeckyInstall: (DeckyManager.Release) -> Unit = {},
val onDeckyCheck: () -> Unit = {},
val onDeckyEnabled: (Boolean) -> Unit = {},
@@ -429,33 +417,6 @@ fun ModeSettingsPage(s: ModeSettings, a: ModeSettingsActions) {
}
}
}
if (steam && tab == ModeSettingsTab.GAMES && s.addedGamesDirs != null) SettingsGroup(stringResource(R.string.mode_added_games)) {
for (dir in s.addedGamesDirs) {
val n = s.addedGames.count { it.folderPath.startsWith("$dir/") }
ActionRow(
dir.substringAfterLast('/').ifEmpty { dir }, dir + " · " + (if (n == 0) stringResource(R.string.mode_added_none) else pluralStringResource(R.plurals.mode_added_count, n, n)) + ". " + stringResource(R.string.added_games_forget_hint),
stringResource(R.string.common_forget), onClick = { a.onForgetAddedGamesDir(dir) },
)
}
ActionRow(
if (s.addedGamesDirs.isEmpty()) stringResource(R.string.mode_games_folder) else stringResource(R.string.mode_games_folder_another),
stringResource(R.string.added_games_import_hint),
stringResource(R.string.common_add_ellipsis), onClick = a.onPickAddedGamesDir,
)
ToggleRow(
host, "addedArt", stringResource(R.string.mode_added_art),
stringResource(R.string.mode_added_art_hint),
s.addedGamesArt, onChange = a.onAddedGamesArt,
)
for (g in s.addedGames) {
ChoiceRow(
host, "added:" + g.folderPath, g.folderName, if (s.addedGamesDirs.size > 1) stringResource(R.string.mode_added_launches_in, g.exeName, g.folderPath.substringBeforeLast('/').substringAfterLast('/')) else stringResource(R.string.mode_added_launches, g.exeName),
g.candidates + ("__pick__" to stringResource(R.string.mode_added_choose)), g.exePath,
note = stringResource(R.string.mode_added_exe_note),
onPick = { path -> if (path == "__pick__") a.onPickAddedGameExe(g.folderPath) else a.onAddedGameExe(g.folderPath, path) },
)
}
}
if (steam && tab == ModeSettingsTab.GAMES && s.fexPreset != null) SettingsGroup(stringResource(R.string.game_settings_title)) {
if (s.syncBackend != null) SettingsRow(
stringResource(R.string.sync_backend_title),
@@ -552,6 +513,31 @@ fun ModeSettingsPage(s: ModeSettings, a: ModeSettingsActions) {
}
/** Width × height for the session, with the common handheld shapes one tap away. */
/** Entry for the user's SteamGridDB API key; the saved key is never shown back. */
@Composable
internal fun SgdbKeyDialog(hasKey: Boolean, onSave: (String) -> Unit, onDismiss: () -> Unit) {
var key by remember { mutableStateOf("") }
androidx.compose.material3.AlertDialog(
onDismissRequest = onDismiss,
title = { Text(stringResource(R.string.mode_sgdb_key)) },
text = {
androidx.compose.material3.OutlinedTextField(
key, { v -> key = v.trim() }, label = { Text(stringResource(R.string.mode_sgdb_key)) },
singleLine = true, visualTransformation = androidx.compose.ui.text.input.PasswordVisualTransformation(),
keyboardOptions = androidx.compose.foundation.text.KeyboardOptions(keyboardType = androidx.compose.ui.text.input.KeyboardType.Password),
modifier = Modifier.fillMaxWidth(),
)
},
confirmButton = { androidx.compose.material3.TextButton(onClick = { onSave(key) }, enabled = key.isNotEmpty()) { Text(stringResource(R.string.common_ok)) } },
dismissButton = {
androidx.compose.foundation.layout.Row {
if (hasKey) androidx.compose.material3.TextButton(onClick = { onSave("") }) { Text(stringResource(R.string.common_delete)) }
androidx.compose.material3.TextButton(onClick = onDismiss) { Text(stringResource(R.string.common_cancel)) }
}
},
)
}
@OptIn(androidx.compose.foundation.layout.ExperimentalLayoutApi::class)
@Composable
internal fun CustomResolutionDialog(initial: Pair<Int, Int>?, onSave: (Pair<Int, Int>) -> Unit, onDismiss: () -> Unit) {
@@ -494,6 +494,19 @@ fun <T> ChoiceRow(
}
}
/** A small "?" beside a value the app guessed and is not sure of; [description] says what to check. */
@Composable
fun UncertainMark(description: String) {
val colors = MaterialTheme.colorScheme
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.size(22.dp).clip(CircleShape).background(colors.surfaceVariant)
.semantics { contentDescription = description },
) {
Text("?", fontSize = 13.sp, fontWeight = FontWeight.Bold, color = colors.onSurfaceVariant)
}
}
@Composable
fun ToggleRow(host: MenuHost, key: String, label: String, hint: String?, checked: Boolean, enabled: Boolean = true, chipModifier: Modifier = Modifier, onChange: (Boolean) -> Unit) =
SettingsRow(label, hint) {