Windows components: picked automatically by each game's source (#554)

Each game's Windows components now come from the list its own source
trusts, and the ones that list names turn on by themselves. The user's own
on/off switches always win; each automatic row says why it is on.

- Steam games: the Steamworks Shared redistributables Steam installs with
  the game (appmanifest SharedDepots, else the client's appinfo.vdf).
  Steam keeps its install scripts marked as already run.
- GOG: the build manifest's dependencies. Epic: the manifest's
  prerequisite (Unreal's maps to VC++ and DirectX). Amazon: fuel.json
  PostInstall. Older GOG/Epic installs get their list fetched once with the
  saved sign-in; game files are never downloaded again.
- Custom games (the + button, Add all, migrated folders): one shared Steam
  match per game, also used for artwork. An appid from the game's files
  turns components on; a name-only match stays Recommended; no match falls
  back to the folder scan.
- Steam app info for apps the client never saw comes from an anonymous
  Steam PICS lookup (CM websocket, anonymous logon, product info), cached
  per appid; the user's Steam sign-in is never used.
- Missing components download in the background on one low-priority
  worker that pauses during sessions and waits on battery saver, heat or a
  metered network unless the user asked. A game Steam installs during a
  session is readied right away so it can be played without ending the
  session; the launch waits up to 10 s only for a component still on its
  way.
- Page: "On for this game" with reasons, a quiet "Checking what this game
  needs..." only for games never worked out, rows that ease in, pieces that
  need a download greyed out while offline. The intro names no other app.
- The folder scan skips Unity's *_Data/Managed (Mono, not .NET Framework).
This commit is contained in:
The412Banner authored and GitHub committed 2026-10-10 21:15:56 -04:00
1 parent d45933e559
commit a2e596a200
35 files changed
+3810 -146

No files matched your search

@@ -322,8 +322,18 @@ private fun GameList(
modifier = modifier.verticalScroll(rememberScrollState()).padding(start = 12.dp, end = 10.dp, top = 16.dp, bottom = 16.dp),
) {
GamesHeader(games.size, onAdd, Modifier.padding(start = 6.dp, bottom = 10.dp))
// A game that arrives while the list is up (Steam installed it in the session that just
// ended, or it was added) eases in; the ones there when the page opened are simply there.
val seen = remember { HashSet<Int>() }
var settled by remember { androidx.compose.runtime.mutableStateOf(false) }
for (g in games) key(g.appId) {
GameRow(g, g.appId == current.appId, onSelect = { onSelect(g) }, onLaunch = { onLaunch(g) })
Box(Modifier.arriveIn(settled && g.appId !in seen)) {
GameRow(g, g.appId == current.appId, onSelect = { onSelect(g) }, onLaunch = { onLaunch(g) })
}
}
androidx.compose.runtime.SideEffect {
seen.addAll(games.map { it.appId })
if (games.isNotEmpty()) settled = true
}
}
}
@@ -442,6 +452,14 @@ private fun AddGameButton(onClick: () -> Unit) {
}
}
/** Fades and slides a row in once when [arriving]; nothing for one already there (or with animations off). */
@Composable
internal fun Modifier.arriveIn(arriving: Boolean): Modifier {
val t = remember { androidx.compose.animation.core.Animatable(if (arriving) 0f else 1f) }
LaunchedEffect(Unit) { if (t.value < 1f) t.animateTo(1f, Motion.tw(280)) }
return graphicsLayer { alpha = t.value; translationY = (1f - t.value) * 12.dp.toPx() }
}
/** 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) {
@@ -510,6 +510,7 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost
if (opened != null && wincompKey != null && game != null) WinComponentsDialog(
wincompKey, game.name, game.gameFiles, opened, compat = game.protonPrefix,
steamAppId = game.appId.takeIf { game.library != com.droiddeck.launcher.frontend.Library.ADDED },
game = game,
) { wincompOpen = null }
Column(verticalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().padding(bottom = 16.dp)) {
for (row in cards.chunked(columns)) {
@@ -15,6 +15,10 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.key
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -38,6 +42,7 @@ import com.droiddeck.launcher.R
import com.droiddeck.launcher.frontend.DependencyDetector
import com.droiddeck.launcher.frontend.PrefixInstalledDetector
import com.droiddeck.launcher.frontend.SteamRedists
import com.droiddeck.launcher.frontend.WinCompSources
import com.droiddeck.launcher.session.WinComponentNames
import com.droiddeck.launcher.session.WinComponents
import com.droiddeck.launcher.session.WinComponents.Support
@@ -53,13 +58,38 @@ import java.io.File
// picked ones into the game's prefix (droiddeck-wincomponents).
/** Bannerlator's detector names installers; here the DLL-copy twin is the one that installs. */
private fun installable(name: String, all: Map<String, WinComponents.Component>): String {
val dll = when (name) {
"oalinst" -> "oalinst_dll"
else -> "${name}_dll"
}
val twin = all[dll]
return if (twin != null && WinComponents.support(twin, all) == Support.READY) dll else name
private fun installable(name: String, all: Map<String, WinComponents.Component>): String = WinComponents.installable(name, all)
/** A store as a list's owner names it in a reason line. */
@Composable
private fun originName(origin: String): String = stringResource(
when (origin) {
WinCompSources.Origin.GOG.name -> R.string.wincomp_src_gog
WinCompSources.Origin.EPIC.name -> R.string.wincomp_src_epic
WinCompSources.Origin.AMAZON.name -> R.string.wincomp_src_amazon
else -> R.string.wincomp_src_steam
},
)
/** Why a component was turned on by itself, from [WinComponents.AutoReason] (args: what the list called it, then the origin's own). */
@Composable
private fun autoReason(r: WinComponents.AutoReason): String = when (r.kind) {
WinCompSources.Origin.STEAM.name -> stringResource(R.string.wincomp_auto_steam, r.args.getOrElse(1) { "" }, r.args.getOrElse(2) { "" }, r.args.getOrElse(3) { "" })
WinCompSources.Origin.GOG.name -> stringResource(R.string.wincomp_auto_gog)
WinCompSources.Origin.EPIC.name -> stringResource(R.string.wincomp_auto_epic)
WinCompSources.Origin.AMAZON.name -> stringResource(R.string.wincomp_auto_amazon)
else -> ""
}
/** The reason line of a finding that is only recommended. */
@Composable
private fun findingReason(f: WinCompSources.Finding): String = when (f.origin) {
WinCompSources.Origin.FOLDER -> stringResource(
if (f.args.getOrNull(1) == DependencyDetector.Kind.SHIPPED.name) R.string.wincomp_found_shipped else R.string.wincomp_found_bundled,
f.args.getOrElse(0) { f.original },
)
WinCompSources.Origin.STEAM_NAME -> stringResource(R.string.wincomp_steam_by_name, f.args.getOrElse(0) { f.original }, f.args.getOrElse(2) { "" })
else -> autoReason(WinComponents.AutoReason(f.origin.name, listOf(f.original) + f.args))
}
@OptIn(androidx.compose.ui.ExperimentalComposeUiApi::class)
@@ -68,6 +98,8 @@ internal fun WinComponentsDialog(
appKey: String, gameName: String, gameDir: File?, byPad: Boolean,
/** compatdata/<id>: what the prefix already has. [steamAppId]: a Steam title, whose appmanifest lists Steam's own redists. */
compat: File? = null, steamAppId: Int? = null,
/** The game as the Games tab has it: its source decides whose list is trusted ([WinCompSources]). */
game: com.droiddeck.launcher.frontend.Library.SteamGame? = null,
onClose: () -> Unit,
) {
val context = LocalContext.current
@@ -77,11 +109,17 @@ internal fun WinComponentsDialog(
// null while the catalog loads; empty when it could not be had.
var catalog by remember { mutableStateOf<Map<String, WinComponents.Component>?>(null) }
var offline by remember { mutableStateOf(false) }
var recommended by remember { mutableStateOf(emptyList<DependencyDetector.Recommendation>()) }
var findings by remember { mutableStateOf(emptyList<WinCompSources.Finding>()) }
// Whether the game's list has been worked out at least once (kept from an earlier time counts).
var findingsKnown by remember { mutableStateOf(game == null) }
// "Loading the components" only when the catalog takes a while.
var slowCatalog by remember { mutableStateOf(false) }
LaunchedEffect(Unit) { kotlinx.coroutines.delay(300); slowCatalog = true }
var installed by remember { mutableStateOf(emptySet<String>()) }
// Detector names (oalinst, physx...) already in the prefix from elsewhere.
var present by remember { mutableStateOf(emptySet<String>()) }
var picks by remember { mutableStateOf(WinComponents.picks(context, appKey)) }
var selection by remember { mutableStateOf(WinComponents.selection(context, appKey)) }
val picks = selection.effective
// The row being worked on: its id, the latest progress (a dependency's while that installs
// first), and whether it is turning off rather than on. The row greys out and shows the bar
// the moment the switch is pressed, and only that row; the rest of the page stays as it is.
@@ -96,6 +134,7 @@ internal fun WinComponentsDialog(
// pad, so the d-pad always has somewhere to start; LB and RB jump between the sections, since
// the full list runs past sixty switches.
val recFocus = remember { FocusRequester() }
val recFocusAfterAuto = remember { FocusRequester() }
val activeFocus = remember { FocusRequester() }
val allFocus = remember { FocusRequester() }
val waitFocus = remember { FocusRequester() }
@@ -105,20 +144,46 @@ internal fun WinComponentsDialog(
LaunchedEffect(Unit) {
val (entries, found) = withContext(Dispatchers.IO) {
// The folder's own installers first, then what Steam installs with the game.
val own = gameDir?.let { DependencyDetector.detect(it) } ?: emptyList()
val steam = steamAppId?.let { SteamRedists.detect(gameDir, it) } ?: emptyList()
WinComponents.fetch() to (own + steam)
val list = WinComponents.fetch(context)
// The source's list first (and what it turns on by itself, already installed), then the folder scan.
if (game != null) {
// The list kept from last time, at once; it is worked out again (and its components
// queued) on the background worker, which this page then follows.
com.droiddeck.launcher.frontend.AutoComponents.queueGame(context, game, asked = true)
val kept = com.droiddeck.launcher.frontend.AutoComponents.cachedFindings(context, appKey)
if (kept != null) findingsKnown = true
list to kept.orEmpty()
} else {
val own = gameDir?.let { DependencyDetector.detect(it) } ?: emptyList()
val steam = steamAppId?.let { SteamRedists.detect(gameDir, it) } ?: emptyList()
list to (own + steam).map { WinCompSources.Finding(it.componentName, it.reason, WinCompSources.Origin.FOLDER, false, listOf(it.reason, it.kind.name)) }
}
}
offline = entries == null
catalog = entries.orEmpty().associateBy { it.name }
recommended = found
findings = found
selection = withContext(Dispatchers.IO) { WinComponents.selection(context, appKey) }
present = withContext(Dispatchers.IO) { PrefixInstalledDetector.detect(compat) }
installed = withContext(Dispatchers.IO) { WinComponents.installedIds(context).toSet() }
}
fun setPicks(next: List<String>) {
picks = next
coroutine.launch(Dispatchers.IO) { WinComponents.setPicks(context, appKey, next) }
/** The user's own switch for [id]: kept apart from what was turned on by itself, and over it. */
// Automatic picks still downloading show on their rows; when one lands the page reads the picks again.
val autoDownloading by com.droiddeck.launcher.frontend.AutoComponents.downloading.collectAsState()
// Without a network a component not downloaded yet cannot be turned on; the rows say so and
// come back the moment the network does.
val online = rememberOnline()
val autoChanges by com.droiddeck.launcher.frontend.AutoComponents.changes.collectAsState()
val pendingGames by com.droiddeck.launcher.frontend.AutoComponents.pendingGames.collectAsState()
val pendingComponents by com.droiddeck.launcher.frontend.AutoComponents.pendingComponents.collectAsState()
LaunchedEffect(autoChanges) {
if (game != null) withContext(Dispatchers.IO) { com.droiddeck.launcher.frontend.AutoComponents.cachedFindings(context, appKey) }
?.let { findings = it; if (appKey !in pendingGames) findingsKnown = true }
selection = withContext(Dispatchers.IO) { WinComponents.selection(context, appKey) }
installed = withContext(Dispatchers.IO) { WinComponents.installedIds(context).toSet() }
}
fun setUser(id: String, on: Boolean) {
selection = WinComponents.Selection(selection.auto, selection.user + (id to on))
coroutine.launch(Dispatchers.IO) { WinComponents.setUser(context, appKey, id, on) }
}
fun toggle(id: String, on: Boolean) {
// Switches stay enabled during a download - a disabled one drops the pad's focus - so a press
@@ -130,17 +195,16 @@ internal fun WinComponentsDialog(
// Turning off is a saved pick, quick, but the row greys out until it is written so the
// press is seen to land; the files leave the prefix at the game's next launch.
busyId = id; reverting = true; progress = null
val next = picks - id
picks = next
selection = WinComponents.Selection(selection.auto, selection.user + (id to false))
coroutine.launch {
withContext(Dispatchers.IO) { WinComponents.setPicks(context, appKey, next) }
withContext(Dispatchers.IO) { WinComponents.setUser(context, appKey, id, false) }
busyId = null; reverting = false
}
return
}
val all = catalog.orEmpty()
val c = all[id]
if (id in installed || c == null) { setPicks(picks + id); return }
if (id in installed || c == null) { setUser(id, true); return }
busyId = id; reverting = false
progress = WinComponents.Progress(id, "", WinComponents.Phase.DOWNLOAD, -1)
coroutine.launch {
@@ -149,29 +213,48 @@ internal fun WinComponentsDialog(
}
progress = null
installed = withContext(Dispatchers.IO) { WinComponents.installedIds(context).toSet() }
if (problem != null) { error = problem; failed = id } else setPicks(picks + id)
if (problem != null) { error = problem; failed = id } else setUser(id, true)
busyId = null
}
}
val all = catalog
// The first data is in: rows that show up from now on ease in.
var arrived by remember { mutableStateOf(false) }
LaunchedEffect(all != null && findingsKnown) { if (all != null && findingsKnown) { withFrameNanos { }; arrived = true } }
val here = if (all == null) emptySet() else present.map { installable(it, all) }.toSet()
fun supportOf(id: String): Support =
all?.get(id)?.let { WinComponents.support(it, all) } ?: if (id in installed) Support.READY else Support.UNSUPPORTED
val recIds = if (all == null) emptyList() else recommended.distinctBy { installable(it.componentName, all) }
// Turned on by itself for this game, each with its reason; then what is only recommended (the
// folder scan, a name match, an auto pick that cannot install here); then what the lists name
// that is no component here, by its own name.
// Still being worked out on the background worker: the page says so instead of "nothing found".
// Only before the game's list has ever been worked out: a list kept from before shows at once and
// is checked again quietly, its changes easing in.
val checking = game != null && !findingsKnown
// Automatic picks on their way (queued or downloading) sit in their section already, with
// their progress, and settle there when they land.
val turningOn = if (all == null) emptyMap() else findings.filter { it.auto && it.component != null }
.associateBy { installable(it.component!!, all) }
.filterKeys { it !in selection.auto && selection.user[it] != false && (it in pendingComponents || it in autoDownloading) }
val autoIds = selection.auto.keys.toList() + turningOn.keys
val recIds = if (all == null) emptyList() else findings.filter { it.component != null }
.filter { installable(it.component!!, all).let { id -> id !in selection.auto && id !in turningOn } }
.distinctBy { installable(it.component!!, all) }
val suggestions = findings.filter { it.component == null }.distinctBy { it.origin to it.original }
val ready = all.orEmpty().values.filter { WinComponents.support(it, all.orEmpty()) == Support.READY }.map { it.name }
val extra = (installed + picks).filter { all?.containsKey(it) != true }
// What is turned on for this game gets its own section under the recommendations, which stay
// where they are; the rest of the list is everything else, so a component turned off goes back
// to its place in the alphabet. A component is listed once: the recommendations are left out
// of the full list too.
val recSet = recIds.map { installable(it.componentName, all.orEmpty()) }.toSet()
val recSet = recIds.map { installable(it.component!!, all.orEmpty()) }.toSet() + autoIds
val active = picks.filter { it !in recSet && (all?.containsKey(it) == true || it in installed) }.distinct()
.sortedBy { WinComponentNames.of(it).lowercase() }
val list = (ready + extra).distinct().filter { it !in active && it !in recSet }.sortedBy { WinComponentNames.of(it).lowercase() }
val waiting = all.orEmpty().values.filter { WinComponents.support(it, all.orEmpty()) == Support.NEEDS_INSTALLER }
.map { it.name }.sortedBy { WinComponentNames.of(it).lowercase() }
val hasRec = all != null && recIds.any { supportOf(installable(it.componentName, all)) == Support.READY }
val hasRec = all != null && (autoIds.isNotEmpty() || recIds.any { supportOf(installable(it.component!!, all)) == Support.READY })
val sections = listOfNotNull(recFocus.takeIf { hasRec }, activeFocus.takeIf { active.isNotEmpty() },
allFocus.takeIf { list.isNotEmpty() }, waitFocus.takeIf { waiting.isNotEmpty() }, doneFocus)
var section by remember { mutableStateOf(0) }
@@ -198,13 +281,14 @@ internal fun WinComponentsDialog(
DialogHeader(gameName, stringResource(R.string.wincomp_title))
Small(stringResource(R.string.wincomp_applies))
if (byPad) Small(stringResource(R.string.wincomp_pad_hint))
if (all == null) Small(stringResource(R.string.wincomp_loading))
if (all == null && slowCatalog) Small(stringResource(R.string.wincomp_loading))
if (offline) Small(stringResource(R.string.wincomp_offline), error = true)
@Composable
fun Item(id: String, reason: String?, focus: FocusRequester?) {
val c = all?.get(id)
val support = supportOf(id)
val status = when {
!online && id !in installed && support == Support.READY -> stringResource(R.string.wincomp_when_online)
id == failed && error != null -> stringResource(R.string.wincomp_failed, error.orEmpty())
id in here && id !in picks -> stringResource(R.string.wincomp_already_here)
id in installed -> stringResource(R.string.wincomp_downloaded)
@@ -214,12 +298,15 @@ internal fun WinComponentsDialog(
}
// The catalog key stays in the detail: it is what a log or a bug report names.
val detail = listOfNotNull(reason, c?.description?.takeIf { it.isNotEmpty() }, status, id).joinToString(" · ")
val usable = support == Support.READY
val busy = id == busyId
val offlineHere = !online && id !in installed
val usable = support == Support.READY && !offlineHere
val autoProgress = autoDownloading[id]?.takeIf { !offlineHere }
val busy = id == busyId || autoProgress != null
val shownProgress = if (id == busyId) progress else autoProgress
val caption = when {
!busy -> null
reverting -> stringResource(R.string.wincomp_reverting)
else -> progress?.let { p ->
id == busyId && reverting -> stringResource(R.string.wincomp_reverting)
else -> shownProgress?.let { p ->
val stage = if (p.component != id && p.stage.isNotEmpty()) "${WinComponentNames.of(p.component)}: ${p.stage}" else p.stage
val text = when (p.phase) {
WinComponents.Phase.DOWNLOAD -> stringResource(R.string.wincomp_downloading, stage)
@@ -229,9 +316,9 @@ internal fun WinComponentsDialog(
}
}
ComponentRow(
WinComponentNames.of(id), detail, checked = id in picks, enabled = usable || id in picks,
WinComponentNames.of(id), detail, checked = id in picks, enabled = usable || (id in picks && id in installed),
dim = !usable || busy, busy = busy, caption = caption,
percent = if (busy && !reverting) progress?.percent ?: -1 else -1,
percent = if (busy && !reverting) shownProgress?.percent ?: -1 else -1,
modifier = (if (usable && focus != null) Modifier.focusRequester(focus) else Modifier)
.onFocusChanged { if (it.isFocused) switchFocused = true },
) { on -> toggle(id, on) }
@@ -242,48 +329,97 @@ internal fun WinComponentsDialog(
return { id -> focus.takeIf { id == first } }
}
if (all != null && recIds.isNotEmpty()) {
Section(stringResource(R.string.wincomp_recommended))
val focusOf = firstUsable(recIds.map { installable(it.componentName, all) }, recFocus)
Panel {
recIds.forEachIndexed { i, rec ->
if (i > 0) Divider()
val reason = stringResource(
when (rec.kind) {
DependencyDetector.Kind.BUNDLED -> R.string.wincomp_found_bundled
DependencyDetector.Kind.SHIPPED -> R.string.wincomp_found_shipped
DependencyDetector.Kind.STEAM -> R.string.wincomp_found_steam
}, rec.reason,
)
val id = installable(rec.componentName, all)
Item(id, reason, focusOf(id))
// The lists only once the catalog is in, faded in once: no half list counted before it.
androidx.compose.animation.AnimatedVisibility(
visible = all != null,
enter = androidx.compose.animation.fadeIn(Motion.tw(220)),
exit = androidx.compose.animation.fadeOut(Motion.tw(0)),
label = "lists",
) {
Column(verticalArrangement = Arrangement.spacedBy(14.dp), modifier = Modifier.fillMaxWidth()) {
if (checking) Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
androidx.compose.material3.CircularProgressIndicator(Modifier.padding(start = 2.dp).size(12.dp), strokeWidth = 1.5.dp)
Small(stringResource(R.string.wincomp_checking))
}
androidx.compose.animation.AnimatedVisibility(
visible = all != null && autoIds.isNotEmpty(),
enter = androidx.compose.animation.fadeIn(Motion.tw(260)) + androidx.compose.animation.expandVertically(Motion.tw(260)),
exit = androidx.compose.animation.fadeOut(Motion.tw(180)) + androidx.compose.animation.shrinkVertically(Motion.tw(200)),
label = "autoSection",
) {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
Section(stringResource(R.string.wincomp_auto_section))
if (turningOn.isNotEmpty()) Small(pluralStringResource(R.plurals.wincomp_turning_on, turningOn.size, turningOn.size))
val focusOf = firstUsable(autoIds, recFocus)
Panel {
autoIds.forEachIndexed { i, id ->
key(id) {
Arrive(arrived) {
Column {
if (i > 0) Divider()
val reason = selection.auto[id] ?: turningOn[id]?.let { f -> WinComponents.AutoReason(f.origin.name, listOf(f.original) + f.args) }
Item(id, reason?.let { autoReason(it) }, focusOf(id))
}
}
}
}
}
}
}
if (all != null && recIds.isNotEmpty()) {
Section(stringResource(R.string.wincomp_recommended))
val focusOf = firstUsable(recIds.map { installable(it.component!!, all) }, if (autoIds.isEmpty()) recFocus else recFocusAfterAuto)
Panel {
recIds.forEachIndexed { i, rec ->
val id = installable(rec.component!!, all)
key(id) {
Arrive(arrived) {
Column {
if (i > 0) Divider()
Item(id, findingReason(rec), focusOf(id))
}
}
}
}
}
} else if (all != null && gameDir != null && autoIds.isEmpty() && !checking) Small(stringResource(R.string.wincomp_no_recommendation))
if (suggestions.isNotEmpty()) {
Section(stringResource(R.string.wincomp_suggestions))
Panel {
suggestions.forEachIndexed { i, f ->
if (i > 0) Divider()
Column(Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 10.dp)) {
Text(f.original, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground)
Text(stringResource(R.string.wincomp_suggestion_reason, originName(f.origin.name)), fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
}
}
}
if (active.isNotEmpty()) {
Section(stringResource(R.string.wincomp_active, active.size))
val focusOf = firstUsable(active, activeFocus)
Panel { active.forEachIndexed { i, id -> if (i > 0) Divider(); Item(id, null, focusOf(id)) } }
}
if (list.isNotEmpty()) {
Section(stringResource(R.string.wincomp_all, list.size))
val focusOf = firstUsable(list, allFocus)
Panel { list.forEachIndexed { i, id -> if (i > 0) Divider(); Item(id, null, focusOf(id)) } }
}
if (waiting.isNotEmpty()) {
Row(verticalAlignment = Alignment.CenterVertically) {
Section(stringResource(R.string.wincomp_installers, waiting.size))
Spacer(Modifier.weight(1f))
SecondaryButton(
stringResource(if (showWaiting) R.string.wincomp_hide else R.string.wincomp_show), compact = true,
modifier = Modifier.focusRequester(waitFocus),
) { showWaiting = !showWaiting }
}
Small(stringResource(R.string.wincomp_installers_note))
if (showWaiting) Panel { waiting.forEachIndexed { i, id -> if (i > 0) Divider(); Item(id, null, null) } }
}
}
} else if (all != null && gameDir != null) Small(stringResource(R.string.wincomp_no_recommendation))
if (active.isNotEmpty()) {
Section(stringResource(R.string.wincomp_active, active.size))
val focusOf = firstUsable(active, activeFocus)
Panel { active.forEachIndexed { i, id -> if (i > 0) Divider(); Item(id, null, focusOf(id)) } }
}
if (list.isNotEmpty()) {
Section(stringResource(R.string.wincomp_all, list.size))
val focusOf = firstUsable(list, allFocus)
Panel { list.forEachIndexed { i, id -> if (i > 0) Divider(); Item(id, null, focusOf(id)) } }
}
if (waiting.isNotEmpty()) {
Row(verticalAlignment = Alignment.CenterVertically) {
Section(stringResource(R.string.wincomp_installers, waiting.size))
Spacer(Modifier.weight(1f))
SecondaryButton(
stringResource(if (showWaiting) R.string.wincomp_hide else R.string.wincomp_show), compact = true,
modifier = Modifier.focusRequester(waitFocus),
) { showWaiting = !showWaiting }
}
Small(stringResource(R.string.wincomp_installers_note))
if (showWaiting) Panel { waiting.forEachIndexed { i, id -> if (i > 0) Divider(); Item(id, null, null) } }
}
error?.let { Small(it, error = true) }
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(top = 4.dp)) {
Small(stringResource(R.string.wincomp_next_launch))
@@ -293,6 +429,39 @@ internal fun WinComponentsDialog(
}
}
/** Once the page has its first data ([arrived]), a row that shows up eases in; the first ones are simply there. */
@Composable
private fun Arrive(arrived: Boolean, content: @Composable () -> Unit) {
val state = remember { androidx.compose.animation.core.MutableTransitionState(!arrived) }.apply { targetState = true }
androidx.compose.animation.AnimatedVisibility(
visibleState = state,
enter = androidx.compose.animation.fadeIn(Motion.tw(240)) + androidx.compose.animation.expandVertically(Motion.tw(240)) +
androidx.compose.animation.slideInVertically(Motion.tw(240)) { -it / 4 },
exit = androidx.compose.animation.fadeOut(Motion.tw(160)),
label = "arrive",
) { content() }
}
/** Whether the default network is there and validated, followed live. */
@Composable
private fun rememberOnline(): Boolean {
val context = LocalContext.current
var online by remember { mutableStateOf(com.droiddeck.launcher.frontend.AutoComponents.isOnline(context)) }
androidx.compose.runtime.DisposableEffect(Unit) {
val cm = context.getSystemService(android.net.ConnectivityManager::class.java)
val main = android.os.Handler(android.os.Looper.getMainLooper())
val callback = object : android.net.ConnectivityManager.NetworkCallback() {
private fun update() = main.post { online = com.droiddeck.launcher.frontend.AutoComponents.isOnline(context) }
override fun onAvailable(network: android.net.Network) { update() }
override fun onLost(network: android.net.Network) { update() }
override fun onCapabilitiesChanged(network: android.net.Network, caps: android.net.NetworkCapabilities) { update() }
}
runCatching { cm?.registerDefaultNetworkCallback(callback) }
onDispose { runCatching { cm?.unregisterNetworkCallback(callback) } }
}
return online
}
@Composable
private fun Section(title: String) =
Text(title.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)