mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
fix: confirm before bulk-removing unused components in Storage (#1140)
This commit is contained in:
1 parent
a42ad82bcb
commit
48daa064c9
2 files changed
+111
-2
No files matched your search
@@ -781,17 +781,18 @@ private fun GameDataView(report: StorageReport, sessionRunning: Boolean, onBack:
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ComponentsView(report: StorageReport, sessionRunning: Boolean, onBack: () -> Unit) {
|
||||
internal fun ComponentsView(report: StorageReport, sessionRunning: Boolean, onBack: () -> Unit) {
|
||||
val ctx = LocalContext.current
|
||||
val pal = LocalPalette.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val busy = sessionRunning || StorageState.cleaning
|
||||
var confirm by remember { mutableStateOf<ComponentUsage?>(null) }
|
||||
var confirmAll by remember { mutableStateOf(false) }
|
||||
val unused = report.unusedComponents
|
||||
SubHeader(stringResource(R.string.storage_components),
|
||||
stringResource(R.string.storage_tools_detail, gb(report.components.sumOf { it.bytes }), gb(unused.sumOf { it.bytes })), onBack) {
|
||||
if (unused.isNotEmpty()) PrimaryButton(stringResource(R.string.storage_remove_unused, gb(unused.sumOf { it.bytes })), compact = true, enabled = !busy) {
|
||||
StorageState.clean(ctx, setOf(CleanItem.UNUSED_COMPONENTS)) { }
|
||||
confirmAll = true
|
||||
}
|
||||
}
|
||||
ActionStatus()
|
||||
@@ -824,6 +825,19 @@ private fun ComponentsView(report: StorageReport, sessionRunning: Boolean, onBac
|
||||
stringResource(if (c.packageFile != null) R.string.storage_component_confirm else R.string.storage_original_confirm, gb(c.bytes)),
|
||||
stringResource(R.string.storage_remove), onConfirm = { StorageState.removeComponent(ctx, c) }, onDismiss = { confirm = null })
|
||||
}
|
||||
if (confirmAll) {
|
||||
val total = gb(unused.sumOf { it.bytes })
|
||||
val lines = unused.map { "• " + componentLabel(it) + " " + gb(it.bytes) }.joinToString("\n")
|
||||
val warning = stringResource(
|
||||
if (unused.any { it.packageFile != null }) R.string.storage_component_confirm else R.string.storage_original_confirm, total)
|
||||
ConfirmDialog(
|
||||
stringResource(R.string.storage_remove_unused, total),
|
||||
lines + "\n\n" + warning,
|
||||
stringResource(R.string.storage_remove),
|
||||
onConfirm = { StorageState.clean(ctx, setOf(CleanItem.UNUSED_COMPONENTS)) { } },
|
||||
onDismiss = { confirmAll = false },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.storage.ComponentUsage
|
||||
import com.droiddeck.launcher.storage.StorageReport
|
||||
import com.droiddeck.launcher.storage.StorageState
|
||||
import org.junit.Assert.assertFalse
|
||||
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 StorageComponentsBulkConfirmTest {
|
||||
@get:Rule val compose = createRobolectricComposeRule()
|
||||
|
||||
private fun reportWith(components: List<ComponentUsage>) = StorageReport(
|
||||
at = 1L,
|
||||
total = 64L * 1024 * 1024 * 1024,
|
||||
free = 32L * 1024 * 1024 * 1024,
|
||||
buckets = emptyMap(),
|
||||
prefixes = 0L,
|
||||
shaders = 0L,
|
||||
workshop = 0L,
|
||||
flatpak = 0L,
|
||||
games = emptyList(),
|
||||
tools = emptyList(),
|
||||
leftovers = emptyList(),
|
||||
logs = emptyList(),
|
||||
logBytes = 0L,
|
||||
components = components,
|
||||
flatpakApps = emptyList(),
|
||||
flatpakRuntimes = 0L,
|
||||
otherPrefixes = 0L,
|
||||
leftoversChecked = true,
|
||||
)
|
||||
|
||||
@Test fun bulkRemoveWithUnusedPackageShowsImportedWarningAndCancelKeepsIdle() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val mb10 = 10L * 1024 * 1024
|
||||
val report = reportWith(
|
||||
listOf(
|
||||
ComponentUsage(comp = "dxvk", version = "2.4.1", bytes = mb10, inUse = false, packageFile = "dxvk-2.4.1.wcp"),
|
||||
ComponentUsage(comp = "vkd3d-proton", version = "2.13", bytes = mb10, inUse = false, protonId = "proton-9", protonName = "Proton 9"),
|
||||
),
|
||||
)
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
Column {
|
||||
ComponentsView(report = report, sessionRunning = false, onBack = {})
|
||||
}
|
||||
}
|
||||
}
|
||||
val removeUnusedBtn = context.getString(R.string.storage_remove_unused, "20 MB")
|
||||
compose.onNodeWithText(removeUnusedBtn).performClick()
|
||||
assertFalse(StorageState.cleaning)
|
||||
|
||||
val expectedWarning = context.getString(R.string.storage_component_confirm, "20 MB")
|
||||
compose.onNodeWithText(expectedWarning, substring = true).assertExists()
|
||||
compose.onNodeWithText("• DXVK 2.4.1 10 MB", substring = true).assertExists()
|
||||
|
||||
compose.onNodeWithText(context.getString(R.string.common_cancel)).performClick()
|
||||
compose.onNodeWithText(expectedWarning, substring = true).assertDoesNotExist()
|
||||
assertFalse(StorageState.cleaning)
|
||||
}
|
||||
|
||||
@Test fun bulkRemoveWithOnlyUnusedOriginalsShowsOriginalConfirmText() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val mb10 = 10L * 1024 * 1024
|
||||
val report = reportWith(
|
||||
listOf(
|
||||
ComponentUsage(comp = "dxvk", version = "2.4", bytes = mb10, inUse = false, protonId = "proton-9", protonName = "Proton 9"),
|
||||
),
|
||||
)
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
Column {
|
||||
ComponentsView(report = report, sessionRunning = false, onBack = {})
|
||||
}
|
||||
}
|
||||
}
|
||||
val removeUnusedBtn = context.getString(R.string.storage_remove_unused, "10 MB")
|
||||
compose.onNodeWithText(removeUnusedBtn).performClick()
|
||||
assertFalse(StorageState.cleaning)
|
||||
|
||||
val expectedWarning = context.getString(R.string.storage_original_confirm, "10 MB")
|
||||
compose.onNodeWithText(expectedWarning, substring = true).assertExists()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user