Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Show no "Zero kB" while only the helper could move a row's items

Țugui Dragoșf4188a08eb34
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift
index 1943afa0..7c0d8d25 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift
@@ -63,6 +63,12 @@ public struct OrphanGroup: Sendable, Hashable, Identifiable {
return SizeTotal(items.filter { selectable.contains($0.url) }.map(\.size))
}
+ /// The size a row of the list shows, as the page's total does: none while nothing could move now.
+ public func figure(canUseHelper: Bool) -> SizeTotal? {
+ let movable = movable(canUseHelper: canUseHelper)
+ return movable.isNothing ? nil : movable
+ }
+
public var lastModified: Date? {
items.compactMap(\.modificationDate).max()
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift
index a6f76f89..90170122 100644
--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift
@@ -80,6 +80,12 @@ public struct PackageReceipt: Sendable, Hashable, Identifiable {
)
}
+ /// The size a row of the list shows, as the page's total does: none while nothing could move now.
+ public func figure(canUseHelper: Bool) -> SizeTotal? {
+ let movable = movable(canUseHelper: canUseHelper)
+ return movable.isNothing ? nil : movable
+ }
+
/// How many items only the helper can move and a person could select once it can act.
public var itemsWaitingForTheHelper: Int { items.count { $0.requiresPrivileges && !$0.isLeftAlone } }
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/SizeTotal.swift b/Packages/PeelCore/Sources/PeelCore/Support/SizeTotal.swift
index 22169bee..b5d0efe6 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/SizeTotal.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/SizeTotal.swift
@@ -43,6 +43,9 @@ public struct SizeTotal: Sendable, Hashable, Comparable, Codable {
SizeTotal(known: known.addingCapped(other.known), isComplete: isComplete && other.isComplete)
}
+ /// True when the total is known to be nothing, which is no size to show.
+ public var isNothing: Bool { isComplete && known == 0 }
+
/// How the total reads: a size, the least it can be, or nothing known at all.
public enum Reading: Sendable, Hashable {
case exactly(Int64)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/MovableTotalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/MovableTotalTests.swift
index 4f7db489..826600b6 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/MovableTotalTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/MovableTotalTests.swift
@@ -4,6 +4,17 @@ import Testing
/// A list shows what a page would move, so a row and the page it opens never give two figures for one thing.
struct MovableTotalTests {
+ @Test func anOrphanRowShowsNoSizeWhileOnlyTheHelperCouldMoveAnything() {
+ let item = OrphanItem(
+ url: URL(filePath: "/Library/LaunchDaemons/org.example.gone.plist"), kind: .launchDaemons, size: 10,
+ modificationDate: nil, requiresPrivileges: true
+ )
+ let group = OrphanGroup(identifier: "org.example.gone", items: [item])
+
+ #expect(group.figure(canUseHelper: false) == nil)
+ #expect(group.figure(canUseHelper: true) == SizeTotal([10]))
+ }
+
@Test func anOrphanGroupCountsOnlyWhatCanMove() {
var library = OrphanItem(
url: URL(filePath: "/Users/x/Pictures/org.example.gone"), kind: .elsewhere, size: 1_000,
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
index d1369416..073c6f02 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
@@ -572,6 +572,18 @@ struct PackageReceiptsTests {
#expect(receipt.itemsWaitingForTheHelper == 1)
}
+ @Test func aRowShowsNoSizeWhileOnlyTheHelperCouldMoveAnything() {
+ let daemon = PackageReceipt.Item(
+ url: URL(filePath: "/Library/LaunchDaemons/org.example.helper.plist"), size: 10, requiresPrivileges: true
+ )
+ let receipt = PackageReceipt(
+ identifier: "org.example.pkg", version: nil, installDate: nil, volume: URL(filePath: "/"), items: [daemon]
+ )
+
+ #expect(receipt.figure(canUseHelper: false) == nil)
+ #expect(receipt.figure(canUseHelper: true) == SizeTotal([10]))
+ }
+
@Test func leavesTheRestOfAPackageToWhatRemovesItsApp() async throws {
let directory = try TemporaryDirectory()
let volume = PathPattern.canonical(directory.url)
diff --git a/Peel/Views/AppHeader.swift b/Peel/Views/AppHeader.swift
index 2e0c56fe..11eb9748 100644
--- a/Peel/Views/AppHeader.swift
+++ b/Peel/Views/AppHeader.swift
@@ -33,7 +33,7 @@ struct AppHeader<Actions: View>: View {
actions
}
Spacer(minLength: 12)
- if let total, total.known > 0 || !total.isComplete {
+ if let total, !total.isNothing {
TotalLabel(total: total, caption: Text("to remove"))
.accessibilityLabel(Text("\(total.text) can be moved to the Trash"))
}
diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swift
index 7b730525..d0b6e4f3 100644
--- a/Peel/Views/MultipleAppsView.swift
+++ b/Peel/Views/MultipleAppsView.swift
@@ -217,7 +217,7 @@ struct MultipleAppsView: View {
}
}
Spacer(minLength: 8)
- if plan.total.known > 0 || !plan.total.isComplete {
+ if !plan.total.isNothing {
TotalLabel(total: plan.total, caption: Text("to remove"))
.accessibilityLabel(Text("\(plan.total.text) can be moved to the Trash"))
}
diff --git a/Peel/Views/Orphans/OrphanList.swift b/Peel/Views/Orphans/OrphanList.swift
index 9ba3e951..de34b2af 100644
--- a/Peel/Views/Orphans/OrphanList.swift
+++ b/Peel/Views/Orphans/OrphanList.swift
@@ -255,8 +255,10 @@ private struct OrphanGroupRow: View {
.foregroundStyle(.secondary)
}
Spacer(minLength: 6)
- Text(group.movable(canUseHelper: canUseHelper).text)
- .rowFigure()
+ if let figure = group.figure(canUseHelper: canUseHelper) {
+ Text(figure.text)
+ .rowFigure()
+ }
}
.padding(.vertical, 2)
}
diff --git a/Peel/Views/Packages/PackageDetailView.swift b/Peel/Views/Packages/PackageDetailView.swift
index e6b18e58..02c2612b 100644
--- a/Peel/Views/Packages/PackageDetailView.swift
+++ b/Peel/Views/Packages/PackageDetailView.swift
@@ -204,7 +204,7 @@ struct PackageDetailView: View {
}
} trailing: {
let movable = receipt.movable(canUseHelper: helper.canAct)
- if movable.known > 0 || !movable.isComplete {
+ if !movable.isNothing {
TotalLabel(total: movable, caption: Text("to remove"))
.accessibilityLabel(Text("\(movable.text) can be moved to the Trash"))
}
diff --git a/Peel/Views/Packages/PackageList.swift b/Peel/Views/Packages/PackageList.swift
index a3a6dd9d..d8636c59 100644
--- a/Peel/Views/Packages/PackageList.swift
+++ b/Peel/Views/Packages/PackageList.swift
@@ -129,8 +129,9 @@ struct PackageList: View {
.foregroundStyle(.secondary)
}
Spacer(minLength: 6)
- if !receipt.nothingLeftOnDisk, !receipt.holdsNothingToRemove {
- Text(receipt.movable(canUseHelper: helper.canAct).text)
+ if !receipt.nothingLeftOnDisk, !receipt.holdsNothingToRemove,
+ let figure = receipt.figure(canUseHelper: helper.canAct) {
+ Text(figure.text)
.rowFigure()
}
}
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index 1bbee0fe..31ec4efb 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -580,7 +580,7 @@ extension SizeTotal {
/// What VoiceOver hears of a page's total once its scan ends, as the page's header says it, or nil when nothing
/// is to move.
var spoken: AttributedString? {
- known > 0 || !isComplete ? AttributedString(localized: "\(text) can be moved to the Trash") : nil
+ !isNothing ? AttributedString(localized: "\(text) can be moved to the Trash") : nil
}
var text: String {