feat: store uninstall confirms in a step-out, shows progress, and lands on Install (#609)

feat: store uninstall confirms in a step-out, shows its progress in place, and the game reads Install the moment it is gone
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-12 11:03:03 +00:00
1 parent 486032f5db
commit aa901c3902
4 files changed
+78 -11

No files matched your search

@@ -1,5 +1,6 @@
package com.droiddeck.launcher.stores
import com.droiddeck.launcher.session.SessionPrefs
import android.content.Context
import android.util.Log
import com.droiddeck.launcher.frontend.AddedGames
@@ -76,14 +77,26 @@ object StoreInstalls {
/**
* Removes a store game: its folder with the sidecar, then the shortcut (the listing without
* it makes the writer drop the entry; the live client is asked too). Blocking.
* it makes the writer drop the entry; the live client is asked too). Blocking. [removed] runs
* once the files are gone, before the shortcut list is rebuilt (which reads every added game).
*/
fun uninstall(context: Context, game: InstalledStoreGame) {
fun uninstall(context: Context, game: InstalledStoreGame, progress: (Float) -> Unit = {}, removed: () -> Unit = {}) {
val app = context.applicationContext
val appId = AddedGames.scan(app).firstOrNull { it.folder.absolutePath == game.folder.absolutePath }?.appId
// The shortcut's id as stored for the folder: scanning every added game for it first held
// the bar at 0% for seconds before a file went.
val appId = SessionPrefs.addedGameStoredAppId(app, game.folder.path)
// File by file, deepest first, saying how far it has got: a big game takes a while to go.
val files = game.folder.walkBottomUp().toList()
val step = (files.size / 100).coerceAtLeast(1)
files.forEachIndexed { i, f ->
f.delete()
if (i % step == 0) progress((i + 1).toFloat() / files.size)
}
deleteTree(game.folder)
progress(1f)
// The scratch cache an install on a card may have left in the app's cache.
deleteTree(StoreInstallRoot.scratchDir(app, game.sidecar.store, game.sidecar.id))
removed()
register(app)
if (appId != null) SteamLiveShortcuts.remove(app, appId)
StoresState.logLine("uninstalled \"${game.sidecar.title}\"")
@@ -223,12 +223,26 @@ object StoresState {
backends[item.store]?.install(app, item, target) ?: logLine("${item.store.label}: this build cannot install yet")
}
/** Removes the game's folder and its shortcut, then [onDone] on the main thread. */
/** Games being removed, by key ("store:id"), and how far along (0..1): their page shows it. */
val uninstalling = mutableStateMapOf<String, Float>()
/**
* Removes the game's folder and its shortcut, then [onDone] on the main thread. The game reads
* as removed the moment it is gone (its page shows Install, its card its size), not once the
* whole library has been read again.
*/
fun uninstall(context: Context, game: InstalledStoreGame, onDone: () -> Unit = {}) {
val app = context.applicationContext
val key = "${game.sidecar.store.id}:${game.sidecar.id}"
uninstalling[key] = 0f
Thread({
runCatching { backends[game.sidecar.store]?.uninstall(app, game) }
StoreInstalls.uninstall(app, game)
StoreInstalls.uninstall(app, game, progress = { f -> main.post { if (key in uninstalling) uninstalling[key] = f } }, removed = {
main.post {
installed = installed.filterNot { it.folder.absolutePath == game.folder.absolutePath }
uninstalling.remove(key)
}
})
main.post(onDone)
}, "stores-uninstall").start()
}
@@ -1,5 +1,6 @@
package com.droiddeck.launcher.ui
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.layout.boundsInRoot
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.foundation.background
@@ -52,8 +53,6 @@ internal fun StoreGameDetail(store: Store, key: String, s: FrontEndState, a: Fro
val installed = StoresState.installedGame(store, id)
val download = StoresState.download("${store.id}:$id")?.takeIf { it.isActive }
// Removal asks twice: one stray press of A should not cost a download.
var confirmRemove by remember(key) { mutableStateOf(false) }
LaunchedEffect(confirmRemove) { if (confirmRemove) { kotlinx.coroutines.delay(4000); confirmRemove = false } }
val title = item?.title ?: installed?.sidecar?.title ?: id
Rise(0) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.padding(bottom = 12.dp)) {
@@ -91,10 +90,13 @@ internal fun StoreGameDetail(store: Store, key: String, s: FrontEndState, a: Fro
// Launching, the prefix and the files belong to the Games tab, where every
// installed game has them; here an install only says it is in Steam and
// offers the one thing Games does not: removing it.
// The row keeps its shape: the chip stays, and Uninstall becomes its own
// progress in place while the files go; then the page reads Install again.
ActionChip(stringResource(R.string.stores_in_steam), ok = true)
SecondaryButton(if (confirmRemove) stringResource(R.string.stores_uninstall_confirm) else stringResource(R.string.stores_uninstall), enabled = download == null) {
if (!confirmRemove) confirmRemove = true
else { confirmRemove = false; StoresState.uninstall(ctx, installed) { StoresState.refresh(ctx); a.onLibraryChanged() }; onBack() }
val gone = StoresState.uninstalling["${store.id}:$id"]
if (gone != null) SecondaryButton(stringResource(R.string.stores_uninstalling), enabled = false, progress = gone) {}
else UninstallButton(title, installed, enabled = download == null) {
StoresState.uninstall(ctx, installed) { StoresState.refresh(ctx); a.onLibraryChanged() }
}
}
download != null -> {
@@ -128,6 +130,40 @@ internal fun StoreGameDetail(store: Store, key: String, s: FrontEndState, a: Fro
}
}
/**
* Uninstall that asks the way Cancel does: a confirm steps out of it, naming the game and what
* goes (its size on disk), with Keep first so a stray A does nothing.
*/
@Composable
private fun UninstallButton(title: String, game: com.droiddeck.launcher.stores.InstalledStoreGame, enabled: Boolean, onUninstall: () -> Unit) {
val colors = MaterialTheme.colorScheme
val placed = remember { arrayOfNulls<androidx.compose.ui.layout.LayoutCoordinates>(1) }
val heading = stringResource(R.string.stores_uninstall_title, title)
val size = com.droiddeck.launcher.stores.StoreSizes.onDisk["${game.sidecar.store.id}:${game.sidecar.id}"]
val body = if (size != null && size > 0) stringResource(R.string.stores_uninstall_body_size, formatBytes(size)) else stringResource(R.string.stores_uninstall_body)
val keep = stringResource(R.string.stores_notification_keep)
val remove = stringResource(R.string.stores_uninstall)
Box(Modifier.onGloballyPositioned { placed[0] = it }) {
SecondaryButton(remove, enabled = enabled) {
val at = placed[0]?.takeIf { it.isAttached }?.boundsInRoot() ?: return@SecondaryButton
// It starts once the confirm has folded back into the button: started at once, the button
// turned into the progress under the fold and it drew back into a control that had gone.
var confirmed = false
StoresMotion.ask(StepAsk(anchor = at, side = StepSide.Right, accent = colors.error, items = 3, pillCorner = 12.dp, maxWidth = 340.dp,
onDismiss = { if (confirmed) onUninstall() }, handle = {
Text(remove, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.error, maxLines = 1)
}) {
StepTitle(heading)
Text(body, fontSize = 13.sp, lineHeight = 18.sp, color = colors.onSurfaceVariant, modifier = Modifier.stepItem(1).padding(start = 4.dp, bottom = 12.dp))
Row(horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End), modifier = Modifier.fillMaxWidth().stepItem(2)) {
StepChoice(keep, enabled = open, modifier = Modifier.focusRequester(first)) { StoresMotion.fold() }
StepChoice(remove, danger = true, enabled = open) { confirmed = true; StoresMotion.fold() }
}
})
}
}
}
/**
* Install (or Resume install) that says where it sits when pressed: where to install grows out of
* it, and the download it starts leaves it as a dot for the Downloads chip.