Skip to content

Commit

Permalink
AppCleaner: Better feedback (progress display) during deletion
Browse files Browse the repository at this point in the history
See #1443
  • Loading branch information
d4rken committed Nov 12, 2024
1 parent 388fe9c commit 2a57ab7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ class AppCleaner @Inject constructor(
val filter = filters.singleOrNull { it.identifier == filterIdentifier }
?: throw IllegalStateException("Can't find filter for $filterIdentifier")

updateProgressSecondary(eu.darken.sdmse.common.R.string.general_progress_loading)

filter.withProgress(
client = this,
onUpdate = { old, new -> old?.copy(secondary = new?.secondary ?: CaString.EMPTY) },
onUpdate = { old, new -> old?.copy(secondary = new?.primary ?: CaString.EMPTY) },
onCompletion = { it }
) {
val result = process(targets, allMatches)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import eu.darken.sdmse.common.files.filterDistinctRoots
import eu.darken.sdmse.common.files.isAncestorOf
import eu.darken.sdmse.common.flow.throttleLatest
import eu.darken.sdmse.common.progress.Progress
import eu.darken.sdmse.common.progress.updateProgressSecondary
import eu.darken.sdmse.common.progress.increaseProgress
import eu.darken.sdmse.common.progress.updateProgressCount
import eu.darken.sdmse.common.progress.updateProgressPrimary
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow

Expand All @@ -35,22 +37,25 @@ abstract class BaseExpendablesFilter : ExpendablesFilter {
allMatches: Collection<ExpendablesFilter.Match>,
): ExpendablesFilter.ProcessResult {
log(TAG, INFO) { "deleteAll(...) Processing ${targets.size} out of ${allMatches.size} matches" }
updateProgressPrimary(eu.darken.sdmse.common.R.string.general_progress_preparing)
val successful = mutableSetOf<ExpendablesFilter.Match>()
val failed = mutableSetOf<Pair<ExpendablesFilter.Match, Exception>>()

val distinctRoots = targets.map { it.lookup }.filterDistinctRoots()

if (distinctRoots.size != targets.size) {
log(TAG, INFO) { "${targets.size} match objects but only ${distinctRoots.size} distinct roots" }
if (Bugs.isDebug) {
if (Bugs.isTrace) {
targets
.filter { !distinctRoots.contains(it.lookup) }
.forEachIndexed { index, item -> log(TAG, INFO) { "Non distinct root #$index: $item" } }
}
}

updateProgressCount(Progress.Count.Percent(distinctRoots.size))

distinctRoots.forEach { targetRoot ->
updateProgressSecondary(targetRoot.userReadablePath)
updateProgressPrimary(targetRoot.userReadablePath)
val main = targets.first { it.lookup == targetRoot }

val mainDeleted = try {
Expand All @@ -76,7 +81,7 @@ abstract class BaseExpendablesFilter : ExpendablesFilter {

// deleteAll(...) starts at leafs, children may have been deleted, even if the top-level dir wasn't
val affected = allMatches.filter { it != main && main.lookup.isAncestorOf(it.lookup) }
if (Bugs.isDebug) {
if (Bugs.isTrace) {
log(TAG) { "$main affects ${affected.size} other matches" }
affected.forEach { log(TAG, VERBOSE) { "Affected: $it" } }
}
Expand All @@ -96,6 +101,7 @@ abstract class BaseExpendablesFilter : ExpendablesFilter {
}
}
}
increaseProgress()
}

return ExpendablesFilter.ProcessResult(
Expand Down

0 comments on commit 2a57ab7

Please sign in to comment.