feat(addons): open the addon browser on CurseForge and update every outdated addon at once (#3292)

* feat(addons): open the addon browser on CurseForge and update every outdated addon at once

* fix(addons): share one update per project, keep queued add-ons from being deleted, release progress on cancel

* fix(addons): keep update-all groups apart by source and release only the progress it still owns
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-26 17:33:21 -05:00
1 parent 1fe92c978a
commit f524ffc3d6
3 files changed
+68 -20

No files matched your search

@@ -273,7 +273,7 @@ internal fun AddonBrowserDialog(targets: List<WowAddons.Target>, initial: WowAdd
var text by remember { mutableStateOf("") }
var category by remember { mutableStateOf<WowAddonCatalog.Category?>(null) }
var sort by remember { mutableStateOf(WowAddonCatalog.Sort.POPULAR) }
var source by remember { mutableStateOf(AddonSource.WOWI) }
var source by remember(curseForge != null) { mutableStateOf(if (curseForge != null) AddonSource.CURSE else AddonSource.WOWI) }
val curse = if (source == AddonSource.CURSE && link != null) curseForge else null
LaunchedEffect(link) { link?.refresh() }
var notice by remember { mutableStateOf<Int?>(null) }
@@ -425,8 +425,8 @@ internal fun AddonBrowserDialog(targets: List<WowAddons.Target>, initial: WowAdd
}
val sourceChip: @Composable () -> Unit = {
if (curseForge != null) BrowseDropdown(sourceName) { first, done ->
MenuItem(stringResource(R.string.addons_source_wowi), source == AddonSource.WOWI, focusRequester = first) { source = AddonSource.WOWI; done() }
MenuItem(stringResource(R.string.addons_source_curse), source == AddonSource.CURSE) { source = AddonSource.CURSE; done() }
MenuItem(stringResource(R.string.addons_source_wowi), curse == null, focusRequester = first) { source = AddonSource.WOWI; done() }
MenuItem(stringResource(R.string.addons_source_curse), curse != null) { source = AddonSource.CURSE; done() }
}
}
val categoryChip: @Composable () -> Unit = {
@@ -56,6 +56,7 @@ import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
@@ -1069,8 +1070,36 @@ private fun AddonsTab(g: Library.SteamGame, targets: List<WowAddons.Target>, ses
runCatching { CurseForgeApp.byFolder(link.installed(context, target, scanKey)) }.getOrDefault(emptyMap())
}
}
val progress = remember(target.addOns) { mutableStateMapOf<String, Int>() }
val curseOf = { item: WowAddons.Installed -> link?.let { l -> managed[item.name.lowercase()]?.let { it to l } } }
val outdated = names.filter { item -> curseOf(item)?.first?.update ?: (updates[item.name] != null) }
val scope = rememberCoroutineScope()
if (targets.size > 1) SectionLabel(target.flavor)
MenuItem(stringResource(R.string.addons_download), checked = false) { browsing = target }
if (outdated.size > 1 && !SessionState.running) MenuItem(
stringResource(R.string.store_update_all, outdated.size), checked = false, enabled = progress.isEmpty(),
) {
val plan = outdated.groupBy { item -> curseOf(item)?.first?.id?.let { "curse:$it" } ?: "folder:${item.name}" }.values.map { group ->
Triple(group.map { it.name }, updates[group.first().name], curseOf(group.first()))
}
plan.forEach { (folders) -> folders.forEach { progress[it] = 0 } }
val owned = plan.flatMap { it.first }.toMutableSet()
scope.launch {
try {
plan.forEach { (folders, wowi, curse) ->
val name = folders.first()
val (message, ok) = updateAddon(context, name, wowi.takeIf { curse == null }, target, curse) { pct ->
scope.launch { folders.forEach { progress[it] = pct } }
}
folders.forEach { progress.remove(it) }
owned.removeAll(folders.toSet())
if (!ok && message != null) android.widget.Toast.makeText(context, message, android.widget.Toast.LENGTH_LONG).show()
}
} finally {
owned.forEach { progress.remove(it) }
}
}
}
MenuItem(
stringResource(R.string.games_import_addons), checked = false,
detail = pluralStringResource(R.plurals.games_addons_count, names.size, names.size),
@@ -1079,7 +1108,7 @@ private fun AddonsTab(g: Library.SteamGame, targets: List<WowAddons.Target>, ses
target.addOns.mkdirs()
a.onBrowseFiles(target.addOns)
}
names.forEach { item -> key(target.addOns, item.name) { AddonRow(item, updates[item.name], target, a, link?.let { l -> managed[item.name.lowercase()]?.let { it to l } }) } }
names.forEach { item -> key(target.addOns, item.name) { AddonRow(item, updates[item.name], target, a, progress, curseOf(item)) } }
}
}
}
@@ -1133,12 +1162,12 @@ private fun CurseForgeEntry(a: FrontEndActions) {
}
@Composable
internal fun AddonRow(item: WowAddons.Installed, wowiUpdate: WowAddonCatalog.Addon?, target: WowAddons.Target, a: FrontEndActions, curse: Pair<CurseForgeApp.Project, CurseLink>? = null) {
internal fun AddonRow(item: WowAddons.Installed, wowiUpdate: WowAddonCatalog.Addon?, target: WowAddons.Target, a: FrontEndActions, progresses: MutableMap<String, Int>, curse: Pair<CurseForgeApp.Project, CurseLink>? = null) {
val name = item.name
val update = wowiUpdate.takeIf { curse == null }
val outdated = update != null || curse?.first?.update == true
var asking by remember(target.addOns, name) { mutableStateOf(false) }
var progress by remember(target.addOns, name) { mutableStateOf<Int?>(null) }
val progress = progresses[name]
val context = LocalContext.current
val scope = rememberCoroutineScope()
val delete = stringResource(R.string.common_delete)
@@ -1153,31 +1182,39 @@ internal fun AddonRow(item: WowAddons.Installed, wowiUpdate: WowAddonCatalog.Add
)
}
if (outdated && !SessionState.running) IconAction(Icons.Outlined.Download, stringResource(R.string.common_update), "addon:update:${target.flavor}:$name", enabled = progress == null) {
progress = 0
progresses[name] = 0
scope.launch {
val message = withContext(Dispatchers.IO) {
if (curse != null) {
val (project, link) = curse
val done = runCatching { link.change(context, target) { CurseForgeApp.update(context, it.inspector, it.guid, project.id) } }.getOrDefault(false)
WowAddons.changed()
if (done) context.getString(R.string.user_apps_updated, name) else context.getString(R.string.stores_dl_failed_reason, name)
} else update?.let { installAddon(context, it, target) { pct -> scope.launch { progress = pct } }.first }
try {
val message = updateAddon(context, name, update, target, curse) { pct -> scope.launch { progresses[name] = pct } }.first
if (message != null) android.widget.Toast.makeText(context, message, android.widget.Toast.LENGTH_LONG).show()
} finally {
progresses.remove(name)
}
progress = null
if (message != null) android.widget.Toast.makeText(context, message, android.widget.Toast.LENGTH_LONG).show()
}
}
if (!SessionState.running) IconAction(Icons.Outlined.Delete, if (curse != null) stringResource(R.string.common_uninstall) else delete, "addon:delete:${target.flavor}:$name", danger = true) { asking = true }
if (!SessionState.running) IconAction(Icons.Outlined.Delete, if (curse != null) stringResource(R.string.common_uninstall) else delete, "addon:delete:${target.flavor}:$name", danger = true, enabled = progress == null) { asking = true }
}
if (asking) ConfirmDialog(
title = if (curse != null) stringResource(R.string.stores_uninstall_title, name) else stringResource(R.string.games_delete_addon_title, name),
text = stringResource(R.string.games_delete_addon_body),
confirm = if (curse != null) stringResource(R.string.common_uninstall) else delete,
onConfirm = { a.onAddonDelete(target, name) },
onConfirm = { asking = false; if (progresses[name] == null) a.onAddonDelete(target, name) },
onDismiss = { asking = false },
)
}
private suspend fun updateAddon(
context: android.content.Context, name: String, update: WowAddonCatalog.Addon?, target: WowAddons.Target,
curse: Pair<CurseForgeApp.Project, CurseLink>?, onProgress: (Int) -> Unit,
): Pair<String?, Boolean> = withContext(Dispatchers.IO) {
if (curse != null) {
val (project, link) = curse
val done = runCatching { link.change(context, target) { CurseForgeApp.update(context, it.inspector, it.guid, project.id) } }.getOrDefault(false)
WowAddons.changed()
(if (done) context.getString(R.string.user_apps_updated, name) else context.getString(R.string.stores_dl_failed_reason, name)) to done
} else update?.let { installAddon(context, it, target, onProgress).let { (message, version) -> message to (version != null) } } ?: (null to false)
}
@Composable
private fun CloudRows(g: Library.SteamGame, onSynced: () -> Unit = {}) {
val store = Store.byId(g.source)?.takeIf { it != Store.AMAZON } ?: return