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)
}
}
@@ -1230,6 +1230,8 @@ class MainActivity : ComponentActivity() {
)
},
)
// A download can finish in the session drawer while this page is visible.
androidx.compose.runtime.LaunchedEffect(components.compDownloadRevision) { components.refreshComponents() }
// A Proton installed or removed changes the stack's list of Protons.
androidx.compose.runtime.LaunchedEffect(protons.protonBusyId) { if (protons.protonBusyId == null) components.refreshComponents() }
}
@@ -263,6 +263,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private var closeAtOnce = false
/** The drawer's Components tab: the Protons as last read (ComponentsManager). */
private var drawerComponents by mutableStateOf<ComponentsManager.Snapshot?>(null)
private val drawerComponentMenu by lazy { ComponentsMenu(this, uiHandler) }
private var drawerGameProfileId by mutableStateOf<Long?>(null)
private val drawerGameInventory = GameProfileInventoryCache<Library.SteamGame>()
private var drawerGameInventoryRevision = 0L
@@ -735,7 +736,17 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
},
onClose = { drawerOpen = false },
components = drawerComponents,
onComponentsRefresh = { refreshDrawerComponents() },
onComponentsRefresh = {
refreshDrawerComponents()
drawerComponentMenu.refreshComponentCatalog(force = false)
},
componentCatalog = drawerComponentMenu.compCatalog,
componentCatalogAt = drawerComponentMenu.compCatalogAt,
componentCatalogChecking = drawerComponentMenu.compChecking,
componentDownloads = drawerComponentMenu.compDownloads,
componentDownloadRevision = drawerComponentMenu.compDownloadRevision,
onComponentCatalogRefresh = { drawerComponentMenu.refreshComponentCatalog() },
onComponentDownload = drawerComponentMenu::downloadComponent,
gameProfiles = drawerGameProfileRefresh.data?.profiles.orEmpty(),
selectedGameProfileId = drawerGameProfileId,
selectedGameProfile = drawerGameProfileRefresh.data
@@ -73,6 +73,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
@@ -265,6 +266,13 @@ class DrawerActions(
val components: ComponentsManager.Snapshot? = null,
/** Re-reads the Protons (and runs swaps that waited for a game to close). */
val onComponentsRefresh: () -> Unit = {},
val componentCatalog: List<ComponentsManager.CatalogItem> = emptyList(),
val componentCatalogAt: Long = 0,
val componentCatalogChecking: Boolean = false,
val componentDownloads: Map<String, Int> = emptyMap(),
val componentDownloadRevision: Long = 0,
val onComponentCatalogRefresh: () -> Unit = {},
val onComponentDownload: (ComponentsManager.CatalogItem) -> Unit = {},
/** Installed games available for profile inspection in the session drawer. */
val gameProfiles: List<Pair<Long, String>> = emptyList(),
/** The selected game profile, or null for the Default profile. */
@@ -314,7 +322,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
LaunchedEffect(a.selectedGameProfileId) {
if (host.open == "fex") host.open = null
}
LaunchedEffect(open, page) {
LaunchedEffect(open, page, a.componentDownloadRevision) {
if (open && page == SessionDrawerPage.GAMES) {
a.onGameProfilesPageOpened()
a.onComponentsRefresh()
@@ -535,6 +543,17 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
)
}
ComponentsDrawerPage(host, a) { key -> focus.track(page, key) }
ComponentDownloadsDrawerGroup(
host = host,
catalog = a.componentCatalog,
catalogAt = a.componentCatalogAt,
checking = a.componentCatalogChecking,
packages = a.components?.packages.orEmpty(),
downloads = a.componentDownloads,
onRefresh = a.onComponentCatalogRefresh,
onDownload = a.onComponentDownload,
track = { key -> focus.track(page, key) },
)
}
SessionDrawerPage.SESSION -> {
if (a.isHomeApp) SettingsGroup(stringResource(R.string.drawer_android_apps)) {
@@ -1117,8 +1136,8 @@ private fun ProfileSummaryRow(label: String, value: String) {
/**
* The Games tab's components: quick swaps between what is already installed, per Proton. A swap
* into the Proton a running game uses waits until that game closes; downloading, importing and
* deleting stay on the Components page in the app.
* into the Proton a running game uses waits until that game closes. Downloads below share the
* launcher's package store; importing and deleting stay on the Components page.
*/
@Composable
private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
@@ -1251,6 +1270,84 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin
)
}
/** Downloads only store packages; the profile/Proton choices above apply them separately. */
@Composable
internal fun ComponentDownloadsDrawerGroup(
host: MenuHost,
catalog: List<ComponentsManager.CatalogItem>,
catalogAt: Long,
checking: Boolean,
packages: List<ComponentsManager.Package>,
downloads: Map<String, Int>,
onRefresh: () -> Unit,
onDownload: (ComponentsManager.CatalogItem) -> Unit,
track: (String) -> Modifier = { Modifier },
) {
val colors = MaterialTheme.colorScheme
val installed = packages.map { it.file }.toSet()
SettingsGroup(stringResource(R.string.drawer_component_downloads)) {
Text(stringResource(R.string.drawer_component_downloads_hint), fontSize = 12.sp,
color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp))
SettingsRow(stringResource(R.string.comp_nightlies_checked,
if (catalogAt > 0) java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT)
.format(java.util.Date(catalogAt * 1000)) else stringResource(R.string.comp_never)), null, stacked = true) {
ValueChip(stringResource(if (checking) R.string.common_checking else R.string.stores_refresh),
false, enabled = !checking, modifier = track("cmp-download-refresh"), onClick = onRefresh)
}
for (comp in ComponentsManager.COMPONENTS) {
val key = "cmp-download-$comp"
val items = catalog.filter { it.comp == comp }
val open = host.open == key
Column(Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 10.dp)) {
Text(ComponentsManager.LABEL.getValue(comp), fontSize = 15.sp,
fontWeight = FontWeight.SemiBold, color = colors.onBackground)
Box(Modifier.fillMaxWidth().padding(top = 6.dp)) {
ValueChip(stringResource(R.string.drawer_component_choose_download), open,
enabled = items.isNotEmpty(), modifier = track(key).fillMaxWidth()) {
host.open = if (open) null else key
}
AnchoredMenu(open, onDismiss = { if (host.open == key) host.open = null },
title = ComponentsManager.LABEL.getValue(comp)) { firstItemFocus ->
val firstAvailable = items.firstOrNull { ComponentsManager.safeName(it.file) !in installed && it.file !in downloads }
items.forEach { item ->
val stored = ComponentsManager.safeName(item.file) in installed
val progress = downloads[item.file]
MenuItem(item.file.removeSuffix(".wcp"), checked = stored,
enabled = !stored && progress == null,
detail = when {
stored -> stringResource(R.string.wincomp_downloaded)
progress != null -> if (progress < 0) stringResource(R.string.wincomp_downloading, item.file.removeSuffix(".wcp")) else "$progress%"
else -> item.release + " · " + stringResource(R.string.common_size_mb, item.size / 1048576.0)
},
focusRequester = if (item == firstAvailable) firstItemFocus else null,
) {
onDownload(item)
host.open = null
}
}
}
}
}
}
if (catalog.isEmpty() && !checking) Text(
stringResource(if (catalogAt == 0L) R.string.comp_refresh_to_list else R.string.comp_nothing_new),
fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(14.dp),
)
for ((file, progress) in downloads) {
Column(Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 8.dp)) {
Text(stringResource(R.string.wincomp_downloading, file.removeSuffix(".wcp")),
fontSize = 12.sp, color = colors.onSurfaceVariant)
if (progress < 0) LinearProgressIndicator(modifier = Modifier.fillMaxWidth().padding(top = 4.dp))
else {
Text("$progress%", fontSize = 12.sp, color = colors.onSurfaceVariant)
LinearProgressIndicator(progress = { progress / 100f },
modifier = Modifier.fillMaxWidth().padding(top = 4.dp))
}
}
}
}
}
/**
* A choice for the drawer's narrow column: label, then the box across the full width, then the
* detail underneath - so a long Proton or package name never squeezes the text beside it.
+1 -1
View File
@@ -568,7 +568,7 @@
<string name="drawer_game_running">juego en ejecución</string>
<string name="drawer_reapplied">reaplicado al iniciar %1$s</string>
<string name="drawer_original">Original</string>
<string name="drawer_components_note">Descarga, importa y elimina en la página Componentes.</string>
<string name="drawer_components_note">Importa y elimina en la página Componentes.</string>
<string name="setup_check_done">Hecho</string>
<string name="setup_check_warn">Requiere atención</string>
<string name="setup_check_busy">Trabajando</string>
+1 -1
View File
@@ -451,7 +451,7 @@
<string name="drawer_game_running">Jeu en cours d\'exécution</string>
<string name="drawer_reapplied">Réappliqué au lancement de %1$s</string>
<string name="drawer_original">Original</string>
<string name="drawer_components_note">Veuillez télécharger, importer et supprimer depuis la page « Composants ».</string>
<string name="drawer_components_note">Importez et supprimez depuis la page « Composants ».</string>
<string name="setup_check_done">Terminé</string>
<string name="setup_check_warn">À traiter</string>
<string name="setup_check_busy">Traitement en cours</string>
+1 -1
View File
@@ -564,7 +564,7 @@
<string name="drawer_game_running">ゲーム実行中</string>
<string name="drawer_reapplied">%1$sの起動時に再適用しました</string>
<string name="drawer_original">元</string>
<string name="drawer_components_note">「コンポーネント」ページでダウンロード、インポート、削除してください。</string>
<string name="drawer_components_note">「コンポーネント」ページでインポート、削除してください。</string>
<string name="setup_check_done">完了</string>
<string name="setup_check_warn">要対応</string>
<string name="setup_check_busy">処理中</string>
+1 -1
View File
@@ -564,7 +564,7 @@
<string name="drawer_game_running">게임 실행 중</string>
<string name="drawer_reapplied">%1$s 시작 시 다시 적용됨</string>
<string name="drawer_original">원본</string>
<string name="drawer_components_note">\"구성 요소\" 페이지에서 다운로드, 가져오기 및 삭제하세요.</string>
<string name="drawer_components_note">구성 요소 페이지에서 가져오기 및 삭제하세요.</string>
<string name="setup_check_done">완료</string>
<string name="setup_check_warn">처리 필요</string>
<string name="setup_check_busy">처리 중</string>
+1 -1
View File
@@ -526,7 +526,7 @@
<string name="drawer_game_running">игра запущена</string>
<string name="drawer_reapplied">повторно применено при запуске %1$s</string>
<string name="drawer_original">Оригинал</string>
<string name="drawer_components_note">Скачивайте, импортируйте и удаляйте на странице «Компоненты».</string>
<string name="drawer_components_note">Импортируйте и удаляйте на странице «Компоненты».</string>
<string name="setup_check_done">Готово</string>
<string name="setup_check_warn">Требует внимания</string>
<string name="setup_check_busy">Обработка</string>
+1 -1
View File
@@ -564,7 +564,7 @@
<string name="drawer_game_running">游戏运行中</string>
<string name="drawer_reapplied">于启动 %1$s 时重新应用</string>
<string name="drawer_original">原件</string>
<string name="drawer_components_note">在“组件”页面下载、导入和删除。</string>
<string name="drawer_components_note">在“组件”页面导入和删除。</string>
<string name="setup_check_done">完成</string>
<string name="setup_check_warn">需要处理</string>
<string name="setup_check_busy">处理中</string>
+1 -1
View File
@@ -564,7 +564,7 @@
<string name="drawer_game_running">遊戲執行中</string>
<string name="drawer_reapplied">於 %1$s 啟動時重新套用</string>
<string name="drawer_original">原始</string>
<string name="drawer_components_note">請在「元件」頁面下載、匯入及刪除。</string>
<string name="drawer_components_note">請在「元件」頁面匯入及刪除。</string>
<string name="setup_check_done">完成</string>
<string name="setup_check_warn">需要處理</string>
<string name="setup_check_busy">處理中</string>
+1 -1
View File
@@ -564,7 +564,7 @@
<string name="drawer_game_running">遊戲執行中</string>
<string name="drawer_reapplied">已在啟動 %1$s 時重新套用</string>
<string name="drawer_original">原始</string>
<string name="drawer_components_note">請在「元件」頁面下載、匯入和刪除。</string>
<string name="drawer_components_note">請在「元件」頁面匯入和刪除。</string>
<string name="setup_check_done">完成</string>
<string name="setup_check_warn">需要處理</string>
<string name="setup_check_busy">處理中</string>
+4 -1
View File
@@ -631,7 +631,10 @@
<string name="drawer_game_running">game running</string>
<string name="drawer_reapplied">re-applied at launch %1$s</string>
<string name="drawer_original">Original</string>
<string name="drawer_components_note">Download, import and delete on the Components page.</string>
<string name="drawer_components_note">Import and delete on the Components page.</string>
<string name="drawer_component_downloads">Download components</string>
<string name="drawer_component_downloads_hint">Downloads are shared with the Components page. Choose a downloaded version above to use it on the next game launch.</string>
<string name="drawer_component_choose_download">Choose a version to download</string>
<string name="setup_check_done">Done</string>
<string name="setup_check_warn">Needs attention</string>
<string name="setup_check_busy">Working</string>
@@ -0,0 +1,84 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.droiddeck.launcher.R
import com.droiddeck.launcher.session.ComponentsManager
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28])
class ComponentDownloadsDrawerTest {
@get:Rule val compose = createRobolectricComposeRule()
private val dxvk = item("dxvk-2.4.1-linux.wcp", "dxvk")
private val stored = item("dxvk-2.3-linux.wcp", "dxvk")
private val inFlight = item("dxvk-2.7.1-linux.wcp", "dxvk")
private val fex = item("fex-2609-linux.wcp", "fex")
@Test fun choosingDxvkDownloadsTheCatalogItemAndPreventsStoredOrInFlightDownloads() {
val requested = mutableListOf<ComponentsManager.CatalogItem>()
show(downloads = mapOf(inFlight.file to 45), onDownload = requested::add)
compose.onNodeWithTag("cmp-download-dxvk").performClick()
compose.onNodeWithText(stored.file.removeSuffix(".wcp")).assertIsNotEnabled()
compose.onNodeWithText(inFlight.file.removeSuffix(".wcp")).assertIsNotEnabled()
compose.onNodeWithText(fex.file.removeSuffix(".wcp")).assertDoesNotExist()
compose.onNodeWithText(dxvk.file.removeSuffix(".wcp")).performClick()
assertEquals(listOf(dxvk), requested)
compose.onNodeWithText(dxvk.file.removeSuffix(".wcp")).assertDoesNotExist()
compose.onNodeWithText("45%").assertExists()
}
@Test fun emptyCatalogOffersRefreshAndDisablesVersionChoicesWhileChecking() {
var refreshes = 0
show(catalog = emptyList(), checking = false, onRefresh = { refreshes++ })
compose.onNodeWithTag("cmp-download-refresh").performClick()
assertEquals(1, refreshes)
compose.onNodeWithTag("cmp-download-dxvk").assertIsNotEnabled()
compose.onNodeWithText(RuntimeEnvironment.getApplication().getString(R.string.comp_refresh_to_list)).assertExists()
}
@Test fun catalogRefreshCannotBeStartedTwiceWhileChecking() {
show(checking = true)
compose.onNodeWithTag("cmp-download-refresh").assertIsNotEnabled()
}
private fun show(
catalog: List<ComponentsManager.CatalogItem> = listOf(dxvk, stored, inFlight, fex),
downloads: Map<String, Int> = emptyMap(),
checking: Boolean = false,
onRefresh: () -> Unit = {},
onDownload: (ComponentsManager.CatalogItem) -> Unit = {},
) {
compose.setContent {
DroidDeckTheme {
Column(Modifier.verticalScroll(rememberScrollState())) {
ComponentDownloadsDrawerGroup(
host = rememberMenuHost(), catalog = catalog, catalogAt = 0,
checking = checking,
packages = listOf(ComponentsManager.Package(stored.file, "dxvk", "2.3", "", 100)),
downloads = downloads, onRefresh = onRefresh, onDownload = onDownload,
track = { Modifier.testTag(it) },
)
}
}
}
}
private fun item(file: String, comp: String) = ComponentsManager.CatalogItem(
file, comp, "Nightlies", "https://github.com/example/$file", 100, "sha256:test",
)
}