Download components from the session drawer (#679)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-12 22:18:47 -04:00
1 parent 2503d69293
commit b74edb7e8d
14 files changed
+227 -22

No files matched your search

@@ -9,10 +9,10 @@ import com.droiddeck.launcher.session.ComponentsManager
import com.droiddeck.launcher.session.ProtonDefault
/**
* The Components page's state and work: the Protons and their DXVK/VKD3D sets, the Nightlies
* catalog, downloads and the swap/restore actions. The launcher screen keeps one and shows it.
* Component state and work for the launcher and session drawer: the Protons and their
* DXVK/VKD3D sets, the Nightlies catalog, downloads and the swap/restore actions.
*/
internal class ComponentsMenu(private val activity: android.app.Activity, private val ui: android.os.Handler) {
internal class ComponentsMenu(private val activity: android.app.Activity, private val ui: Handler) {
var compSnapshot by mutableStateOf<ComponentsManager.Snapshot?>(null)
var compCatalog by mutableStateOf<List<ComponentsManager.CatalogItem>>(emptyList())
var compCatalogAt by mutableStateOf(0L)
@@ -20,7 +20,10 @@ internal class ComponentsMenu(private val activity: android.app.Activity, privat
var compComp by mutableStateOf(com.droiddeck.launcher.ui.GPU_TAB)
var compChecking by mutableStateOf(false)
var compBusy by mutableStateOf<String?>(null)
var compDownloads by mutableStateOf<Map<String, Int>>(emptyMap())
var compDownloads: Map<String, Int>
get() = downloads
private set(value) { downloads = value }
val compDownloadRevision: Long get() = downloadRevision
private var shownDefault: String? = null
/** Reads the Protons (and on first open saves their originals) off the UI thread; the Nightlies list comes from its cache. */
@@ -72,15 +75,15 @@ internal class ComponentsMenu(private val activity: android.app.Activity, privat
}, "components-action").start()
}
fun refreshComponentCatalog() {
fun refreshComponentCatalog(force: Boolean = true) {
if (compChecking) return
compChecking = true
Thread({
val cat = runCatching { ComponentsManager.catalog(activity, true) }.getOrNull()
val cat = runCatching { ComponentsManager.catalog(activity, force) }.getOrNull()
ui.post {
compChecking = false
if (cat == null || cat.items.isEmpty()) android.widget.Toast.makeText(activity, activity.getString(R.string.comp_nightlies_unreachable), android.widget.Toast.LENGTH_LONG).show()
else { compCatalog = cat.items; compCatalogAt = cat.fetchedAt }
if (cat != null && cat.items.isNotEmpty()) { compCatalog = cat.items; compCatalogAt = cat.fetchedAt }
else if (force) android.widget.Toast.makeText(activity, activity.getString(R.string.comp_nightlies_unreachable), android.widget.Toast.LENGTH_LONG).show()
}
}, "components-catalog").start()
}
@@ -95,6 +98,7 @@ internal class ComponentsMenu(private val activity: android.app.Activity, privat
}.getOrElse { e -> activity.getString(R.string.comp_download_failed, e.message ?: e.javaClass.simpleName) }
ui.post {
compDownloads = compDownloads - item.file
downloadRevision++
android.widget.Toast.makeText(activity, message, android.widget.Toast.LENGTH_SHORT).show()
refreshComponents()
}
@@ -102,6 +106,10 @@ internal class ComponentsMenu(private val activity: android.app.Activity, privat
}
private companion object {
const val TAG = "MainActivity"
const val TAG = "ComponentsMenu"
// Both screens use the same package store and .part files. Keep the in-flight registry
// across menu/activity instances so a package cannot be downloaded twice at once.
var downloads by mutableStateOf<Map<String, Int>>(emptyMap())
var downloadRevision by mutableStateOf(0L)
}
}