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.

Home's front door: what each tool found the last time it looked

Țugui Dragoșc3ae02a407f9
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index ad1e479b..23ef9ce2 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -159,7 +159,7 @@ prints goes through `Output`, in plain ASCII, so scripts can read it.
| `~/Library/Application Support/Peel/digests.bin` | What Duplicates already read, so an unchanged file isn't read again. |
| `~/Library/Application Support/Peel/apps.json`, `teams.json` | What Peel remembers about apps and their signing teams between launches. |
| `/private/var/db/com.tuguidragos.Peel.Helper/` | The helper's ledger of what it moved. |
-| Peel's preferences | Settings, the totals Home shows, and the last answer of each update check. |
+| Peel's preferences | Settings, the totals Home shows, what each tool found the last time it looked, and the last answer of each update check. |
Remove Peel, in Settings, takes all of it to the Trash except the helper's ledger, which only the helper could
move, and it unregisters the helper first. It is the only way Peel is removed: Peel's own page in Applications, and
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 05474698..14f7a9fc 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -30726,6 +30726,112 @@
"comment" : "Homebrew's own name for one of its two kinds of package, in the plural. It heads a section of the Homebrew page and labels a count there. Homebrew prints it in English whatever language the Mac uses, so it stays in English.",
"shouldTranslate" : false
},
+ "Found" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nalezené"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Gefunden"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Encontrados"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Trouvé"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Trovati"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "検出結果"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "찾은 항목"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Gevonden"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Znalezione"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Encontrado"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Găsite"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Найденное"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Hittat"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bulunanlar"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Знайдене"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "已找到"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "已找到"
+ }
+ }
+ }
+ },
"Free up space from inside the provider’s app" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Home/FoundLastTime.swift b/Packages/PeelCore/Sources/PeelCore/Home/FoundLastTime.swift
new file mode 100644
index 00000000..b72dec74
--- /dev/null
+++ b/Packages/PeelCore/Sources/PeelCore/Home/FoundLastTime.swift
@@ -0,0 +1,61 @@
+public import Foundation
+
+/// What each tool found the last time it looked, kept so Home can say it after Peel is opened again.
+///
+/// A tool is named by the app. A finding is how many things the tool found, their size when the tool measures
+/// them, and when it looked. A tool that finds nothing leaves the list.
+public struct FoundLastTime: Sendable, Equatable {
+ public struct Finding: Sendable, Equatable {
+ public let count: Int
+ /// Nil for what has no size, such as updates.
+ public let size: SizeTotal?
+ public let date: Date
+
+ public init(count: Int, size: SizeTotal?, date: Date) {
+ self.count = count
+ self.size = size
+ self.date = date
+ }
+ }
+
+ public private(set) var findings: [String: Finding] = [:]
+
+ public init() {}
+
+ /// Reads what `data` holds. Any process can write an app's preferences, so an entry that makes no sense
+ /// is left out, and the others are kept.
+ public init(data: Data?) {
+ guard let data, let entries = try? JSONDecoder().decode([String: Entry].self, from: data) else { return }
+ for (tool, entry) in entries {
+ guard let stored = entry.stored, stored.count > 0, (stored.bytes ?? 0) >= 0 else { continue }
+ let size = stored.bytes.map { SizeTotal(known: $0, isComplete: stored.complete ?? true) }
+ findings[tool] = Finding(count: stored.count, size: size, date: stored.date)
+ }
+ }
+
+ public var data: Data {
+ let entries = findings.mapValues { Stored(count: $0.count, bytes: $0.size?.known, complete: $0.size?.isComplete, date: $0.date) }
+ return (try? JSONEncoder().encode(entries)) ?? Data()
+ }
+
+ /// Records what `tool` found when it looked at `date`. Nothing found takes the tool off the list.
+ public mutating func record(count: Int, size: SizeTotal?, for tool: String, at date: Date = .now) {
+ findings[tool] = count > 0 ? Finding(count: count, size: size, date: date) : nil
+ }
+
+ private struct Stored: Codable {
+ let count: Int
+ let bytes: Int64?
+ let complete: Bool?
+ let date: Date
+ }
+
+ /// One entry, read on its own, so one that cannot be read costs that entry only.
+ private struct Entry: Decodable {
+ let stored: Stored?
+
+ init(from decoder: any Decoder) throws {
+ stored = try? Stored(from: decoder)
+ }
+ }
+}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FoundLastTimeTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FoundLastTimeTests.swift
new file mode 100644
index 00000000..377e1b9a
--- /dev/null
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FoundLastTimeTests.swift
@@ -0,0 +1,54 @@
+import Foundation
+@testable import PeelCore
+import Testing
+
+/// Home lists what each tool found the last time it looked, from what Peel kept in its preferences.
+struct FoundLastTimeTests {
+ private let monday = Date(timeIntervalSinceReferenceDate: 800_000_000)
+ private let tuesday = Date(timeIntervalSinceReferenceDate: 800_086_400)
+
+ @Test func keepsWhatEachToolFoundAcrossLaunches() {
+ var found = FoundLastTime()
+ found.record(count: 7, size: SizeTotal(known: 1_200_000, isComplete: true), for: "orphans", at: monday)
+ found.record(count: 3, size: nil, for: "applications", at: tuesday)
+
+ let read = FoundLastTime(data: found.data)
+
+ #expect(read == found)
+ #expect(read.findings["orphans"] == FoundLastTime.Finding(count: 7, size: SizeTotal(known: 1_200_000, isComplete: true), date: monday))
+ #expect(read.findings["applications"] == FoundLastTime.Finding(count: 3, size: nil, date: tuesday))
+ }
+
+ /// A total that left something unmeasured out is only the least it can be, and stays so.
+ @Test func aSizeNotAllMeasuredStaysALowerBound() {
+ var found = FoundLastTime()
+ found.record(count: 2, size: SizeTotal(known: 500, isComplete: false), for: "developer", at: monday)
+
+ #expect(FoundLastTime(data: found.data).findings["developer"]?.size == SizeTotal(known: 500, isComplete: false))
+ }
+
+ /// Looking again replaces what was found before, and finding nothing takes the tool off the list.
+ @Test func aToolThatFindsNothingLeavesTheList() {
+ var found = FoundLastTime()
+ found.record(count: 7, size: nil, for: "orphans", at: monday)
+ found.record(count: 4, size: nil, for: "orphans", at: tuesday)
+ #expect(found.findings["orphans"] == FoundLastTime.Finding(count: 4, size: nil, date: tuesday))
+
+ found.record(count: 0, size: SizeTotal(known: 0, isComplete: true), for: "orphans", at: tuesday)
+ #expect(found.findings.isEmpty)
+ }
+
+ /// Any process can write an app's preferences, so an entry that makes no sense is left out, and the rest stay.
+ @Test func readsNothingThatMakesNoSense() {
+ let json = #"""
+ {"orphans": {"count": -2, "date": 0}, "developer": {"count": 3, "bytes": -5, "date": 0},
+ "cloud": "a word", "space": {"count": 2, "bytes": 10, "date": 0}}
+ """#
+
+ let read = FoundLastTime(data: Data(json.utf8))
+
+ #expect(read.findings == ["space": FoundLastTime.Finding(count: 2, size: SizeTotal(known: 10, isComplete: true), date: Date(timeIntervalSinceReferenceDate: 0))])
+ #expect(FoundLastTime(data: Data("not a list".utf8)).findings.isEmpty)
+ #expect(FoundLastTime(data: nil).findings.isEmpty)
+ }
+}
diff --git a/Peel/HomeSnapshot.swift b/Peel/HomeSnapshot.swift
index 4954ac07..49333eea 100644
--- a/Peel/HomeSnapshot.swift
+++ b/Peel/HomeSnapshot.swift
@@ -12,6 +12,7 @@ enum HomeSnapshot {
let home = HomeModel()
let helper = HelperModel()
let stats = LifetimeStats()
+ let found = FoundLastTimeStore()
await home.refresh(helper: helper)
await ExclusionsStore.shared.load()
let window = Color(nsColor: .windowBackgroundColor)
@@ -24,8 +25,8 @@ enum HomeSnapshot {
render(HomeContent().environment(home).environment(helper).environment(stats).environment(\._accessibilityShowButtonShapes, true), width: 360, height: 760, on: window, scheme: scheme, to: "\(directory)/home-content-borders-\(name).png")
}
// The permissions at their widest, and at their narrowest, where Home puts its two halves side by side.
- render(HomePermissionsContent().environment(home).environment(helper).environment(ExclusionsStore.shared), width: 720, height: 680, on: window, scheme: scheme, contrast: contrast, to: "\(directory)/home-detail-\(name).png")
- render(HomePermissionsContent().environment(home).environment(helper).environment(ExclusionsStore.shared), width: 480, height: 700, on: window, scheme: scheme, contrast: contrast, to: "\(directory)/detail-narrow-\(name).png")
+ render(HomePermissionsContent().environment(home).environment(helper).environment(ExclusionsStore.shared).environment(found), width: 720, on: window, scheme: scheme, contrast: contrast, to: "\(directory)/home-detail-\(name).png")
+ render(HomePermissionsContent().environment(home).environment(helper).environment(ExclusionsStore.shared).environment(found), width: 480, on: window, scheme: scheme, contrast: contrast, to: "\(directory)/detail-narrow-\(name).png")
render(AboutContent().fixedSize(horizontal: false, vertical: true), width: AboutContent.width, on: Album.sheet, scheme: scheme, contrast: contrast, to: "\(directory)/about-\(name).png")
render(MenuBarPanel().environment(AppLibrary()).environment(stats), width: 320, scheme: scheme, contrast: contrast, to: "\(directory)/menu-bar-\(name).png")
}
diff --git a/Peel/Model/FoundLastTimeStore.swift b/Peel/Model/FoundLastTimeStore.swift
new file mode 100644
index 00000000..5783c358
--- /dev/null
+++ b/Peel/Model/FoundLastTimeStore.swift
@@ -0,0 +1,102 @@
+import Foundation
+import Observation
+import PeelCore
+
+/// What each tool found the last time it looked, as Home lists it. It is kept in the app's user defaults, beside
+/// `LifetimeStats`, so Home can say it again after Peel is opened.
+@Observable
+final class FoundLastTimeStore {
+ private static let key = "home.foundLastTime"
+ private let defaults: UserDefaults
+ private(set) var found: FoundLastTime
+
+ init(defaults: UserDefaults = .standard) {
+ self.defaults = defaults
+ found = FoundLastTime(data: defaults.data(forKey: Self.key))
+ }
+
+ /// The tools that found something, in the sidebar's order.
+ var findings: [(tool: Tool, finding: FoundLastTime.Finding)] {
+ Tool.allCases.compactMap { tool in found.findings[tool.rawValue].map { (tool, $0) } }
+ }
+
+ func record(_ looked: Looked, for tool: Tool) {
+ found.record(count: looked.count, size: looked.size, for: tool.rawValue)
+ defaults.set(found.data, forKey: Self.key)
+ }
+}
+
+/// How many things a tool found when it last looked, and their size when the tool measures what it finds.
+struct Looked: Equatable {
+ let count: Int
+ let size: SizeTotal?
+}
+
+// What counts as found for each tool Home lists. Each is nil until the tool has looked since Peel opened, so
+// what an earlier look found stays until the tool looks again.
+
+extension AppLibrary {
+ /// The apps with an update waiting, as the menu bar counts them, once a round of checks is over.
+ var looked: Looked? {
+ hasLoaded && appsCheckingForUpdates.isEmpty ? Looked(count: menuBarUpdateCount, size: nil) : nil
+ }
+}
+
+extension OrphanLibrary {
+ var looked: Looked? {
+ scan.map { Looked(count: $0.groups.count, size: SizeTotal(combining: $0.groups.map(\.total))) }
+ }
+}
+
+extension IntelLibrary {
+ var looked: Looked? {
+ scan.map { Looked(count: $0.findings.count, size: nil) }
+ }
+}
+
+extension HomebrewLibrary {
+ /// The packages with a newer version waiting.
+ var looked: Looked? {
+ packages.map { Looked(count: $0.count(where: \.isOutdated), size: nil) }
+ }
+}
+
+extension SpaceLibrary {
+ var looked: Looked? {
+ report.map { Looked(count: $0.items.count, size: SizeTotal($0.items.map(\.size))) }
+ }
+}
+
+extension DeveloperLibrary {
+ var looked: Looked? {
+ environments.map { Looked(count: $0.count, size: SizeTotal(combining: $0.map(\.total))) }
+ }
+}
+
+extension ProjectLibrary {
+ var looked: Looked? {
+ groups.map { Looked(count: $0.count, size: SizeTotal(combining: $0.map(\.total))) }
+ }
+}
+
+extension InstallerLibrary {
+ var looked: Looked? {
+ scan.map { Looked(count: $0.items.count, size: SizeTotal($0.items.map(\.size))) }
+ }
+}
+
+extension DuplicateLibrary {
+ /// The groups of copies, and what moving every copy but one of each would free.
+ var looked: Looked? {
+ scan.map { scan in
+ let reclaimable = scan.groups.reduce(0) { $0 + $1.reclaimableSize } + scan.folderGroups.reduce(0) { $0 + $1.reclaimableSize }
+ return Looked(count: scan.groups.count + scan.folderGroups.count, size: SizeTotal(known: reclaimable, isComplete: true))
+ }
+ }
+}
+
+extension CloudLibrary {
+ var looked: Looked? {
+ files.map { Looked(count: $0.count, size: SizeTotal(known: totalSize, isComplete: true)) }
+ }
+}
diff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swift
index 5818413b..3678548a 100644
--- a/Peel/PeelApp.swift
+++ b/Peel/PeelApp.swift
@@ -25,6 +25,7 @@ struct PeelApp: App {
@State private var trashMonitor = TrashMonitor()
@State private var notifications: PeelNotifications
@State private var stats = LifetimeStats()
+ @State private var found = FoundLastTimeStore()
@State private var library = AppLibrary()
@State private var orphans = OrphanLibrary()
@State private var projects = ProjectLibrary()
@@ -88,6 +89,36 @@ struct PeelApp: App {
}
}
+ /// Records what each tool finds whenever it finds it, with its page open or not, so Home can list it. Each tool
+ /// is followed on its own, so one that looks again leaves the others' dates as they were.
+ private func followFindings() async {
+ let tools: [(Tool, @MainActor @Sendable () -> Looked?)] = [
+ (.applications, { [library] in library.looked }),
+ (.orphans, { [orphans] in orphans.looked }),
+ (.intel, { [intel] in intel.looked }),
+ (.homebrew, { [homebrew] in homebrew.looked }),
+ (.space, { [space] in space.looked }),
+ (.developer, { [developer] in developer.looked }),
+ (.projects, { [projects] in projects.looked }),
+ (.installers, { [installers] in installers.looked }),
+ (.duplicates, { [duplicates] in duplicates.looked }),
+ (.cloud, { [cloud] in cloud.looked }),
+ ]
+ await withDiscardingTaskGroup { group in
+ for (tool, looked) in tools {
+ group.addTask { await follow(tool, looked) }
+ }
+ }
+ }
+
+ private func follow(_ tool: Tool, _ looked: @escaping @MainActor @Sendable () -> Looked?) async {
+ for await value in Observations(looked) {
+ if let value {
+ found.record(value, for: tool)
+ }
+ }
+ }
+
/// Runs the update round every hour while update checks are on. Each app's schedule decides whether the round
/// checks it.
private func askWhenDue() async {
@@ -116,6 +147,7 @@ struct PeelApp: App {
.buttonBorderShape(.capsule)
.environment(outcome)
.environment(stats)
+ .environment(found)
.environment(library)
.environment(orphans)
.environment(projects)
@@ -178,7 +210,7 @@ struct PeelApp: App {
.task {
// Started once, and not as a child of this view's task, so the work goes on in the menu bar
// after the window closes.
- background.start([followFolders, askWhenDue])
+ background.start([followFolders, askWhenDue, followFindings])
}
}
.defaultSize(width: 1120, height: 764)
diff --git a/Peel/Views/Home/HomeFoundCard.swift b/Peel/Views/Home/HomeFoundCard.swift
new file mode 100644
index 00000000..2bb1ad4a
--- /dev/null
+++ b/Peel/Views/Home/HomeFoundCard.swift
@@ -0,0 +1,85 @@
+import PeelCore
+import SwiftUI
+
+/// Home's front door: a line for each tool that found something the last time it looked, leading to that tool.
+/// It says what each one found and when, and never adds the tools together or selects anything.
+struct HomeFoundCard: View {
+ @Environment(FoundLastTimeStore.self) private var store
+ @AppStorage(SettingsKey.hiddenTools) private var hiddenTools = ""
+ @State private var pointingAt: Tool?
+
+ var body: some View {
+ let lines = lines
+ if !lines.isEmpty {
+ VStack(alignment: .leading, spacing: 0) {
+ ForEach(Array(lines.enumerated()), id: \.element.tool) { index, line in
+ if index > 0 {
+ Perforation().padding(.leading, HomePermissionsContent.markSize + 12)
+ }
+ row(line.tool, sentence: line.sentence, date: line.date, tilt: index.isMultiple(of: 2) ? -3 : 3)
+ }
+ }
+ .padding(.horizontal, 14)
+ .padding(.top, 16)
+ .padding(.bottom, 8)
+ .sticker(radius: 14)
+ .overlay(alignment: .topLeading) {
+ TapeHeader(title: Text("Found"), fill: Album.charcoal, ink: .white, angle: -HomePermissionsContent.tapeAngle)
+ .alignmentGuide(.top) { $0[.top] + $0.height / 2 }
+ .alignmentGuide(.leading) { $0[.leading] + $0.width / 4 }
+ }
+ // The tape is rotated, so it reaches above the card. The gap leaves room for it under the banner.
+ .padding(.top, 42)
+ }
+ }
+
+ /// A tool turned off in Settings is left out, as it is from the sidebar.
+ private var lines: [(tool: Tool, sentence: AttributedString, date: Date)] {
+ let hidden = Tool.hidden(in: hiddenTools)
+ return store.findings.compactMap { tool, finding in
+ guard !hidden.contains(tool), let sentence = tool.sentence(for: Looked(count: finding.count, size: finding.size)) else {
+ return nil
+ }
+ return (tool, sentence, finding.date)
+ }
+ }
+
+ private func row(_ tool: Tool, sentence: AttributedString, date: Date, tilt: Double) -> some View {
+ let isPointedAt = pointingAt == tool
+ let markBody = HomePermissionsContent.markBody
+ return Button { Navigator.shared.requestedTool = tool } label: {
+ HStack(spacing: 12) {
+ Image(systemName: tool.systemImage)
+ .font(.system(size: 15, weight: .semibold))
+ .foregroundStyle(Album.charcoal)
+ .frame(width: markBody, height: markBody)
+ .sticker(radius: markBody / 2, fill: Album.cream, edge: HomePermissionsContent.markEdge)
+ .rotationEffect(.degrees(tilt))
+ .frame(width: HomePermissionsContent.markSize, height: HomePermissionsContent.markSize)
+ .accessibilityHidden(true)
+ VStack(alignment: .leading, spacing: 1) {
+ Text(tool.title)
+ .font(.system(.body, design: .rounded, weight: .bold))
+ .foregroundStyle(isPointedAt ? Album.orangeInk : Album.ink)
+ .underline(isPointedAt, pattern: .solid)
+ .fixedSize(horizontal: false, vertical: true)
+ Text(sentence)
+ .font(.system(size: 11.5, weight: .medium))
+ .foregroundStyle(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ Text(date, format: .relative(presentation: .named))
+ .font(.system(size: 11.5, weight: .medium))
+ .foregroundStyle(.secondary)
+ }
+ .padding(.vertical, 6)
+ .contentShape(.rect)
+ }
+ .buttonStyle(.plain)
+ .pointerStyle(.link)
+ .motion(.touch, value: isPointedAt)
+ .onHover { pointingAt = $0 ? tool : nil }
+ .help(Text("Open \(String(localized: tool.title))"))
+ }
+}
diff --git a/Peel/Views/Home/HomePermissionsView.swift b/Peel/Views/Home/HomePermissionsView.swift
index fcd1baca..082fee1d 100644
--- a/Peel/Views/Home/HomePermissionsView.swift
+++ b/Peel/Views/Home/HomePermissionsView.swift
@@ -8,16 +8,17 @@ struct HomePermissionsContent: View {
@Environment(ExclusionsStore.self) private var exclusions
@State private var pointingAt: HomeModel.Permission?
- private static let markSize: CGFloat = 36
+ static let markSize: CGFloat = 36
/// A whole number of points, so the mark's body (30) and edge (3 on each side) fall on whole pixels at
/// any scale. With a half-point edge, one side of the circle looks thicker on a screen that is not Retina.
- private static let markEdge: CGFloat = 3
- private static let markBody: CGFloat = markSize - markEdge * 2
- private static let tapeAngle: Double = 28
+ static let markEdge: CGFloat = 3
+ static let markBody: CGFloat = markSize - markEdge * 2
+ static let tapeAngle: Double = 28
var body: some View {
VStack(alignment: .leading, spacing: 0) {
banner
+ HomeFoundCard()
// The tape is rotated, so it reaches above the card it sits on. The gap leaves room for it under
// the banner, so the tape and the banner don't look stuck together.
card(HomeModel.Permission.allCases.filter(\.isRequired), named: "Required", tapedAt: .topTrailing)
diff --git a/Peel/Views/ToolSummaries.swift b/Peel/Views/ToolSummaries.swift
index 9af84563..7c4ca5d8 100644
--- a/Peel/Views/ToolSummaries.swift
+++ b/Peel/Views/ToolSummaries.swift
@@ -16,6 +16,43 @@ extension SizeTotal {
}
}
+extension Tool {
+ /// What the tool found, as its pane and Home both say it, or nil for a tool Home doesn't list.
+ func sentence(for looked: Looked) -> AttributedString? {
+ let count = looked.count
+ let total = looked.size.flatMap { $0.known > 0 ? $0.text : nil }
+ switch self {
+ case .applications, .homebrew:
+ return AttributedString(localized: "^[\(count) update](inflect: true) waiting.")
+ case .orphans, .duplicates:
+ return total.map { AttributedString(localized: "\($0) in ^[\(count) group](inflect: true).") }
+ ?? AttributedString(localized: "^[\(count) group](inflect: true).")
+ case .developer:
+ return total.map { AttributedString(localized: "\($0) in ^[\(count) tool](inflect: true).") }
+ ?? AttributedString(localized: "^[\(count) tool](inflect: true).")
+ case .projects:
+ return total.map { AttributedString(localized: "\($0) in ^[\(count) project](inflect: true).") }
+ ?? AttributedString(localized: "^[\(count) project](inflect: true).")
+ case .space:
+ return total.map { AttributedString(localized: "\($0) in ^[\(count) area](inflect: true).") }
+ ?? AttributedString(localized: "^[\(count) area](inflect: true).")
+ case .installers, .cloud:
+ return total.map { AttributedString(localized: "\($0) in ^[\(count) item](inflect: true).") }
+ ?? AttributedString(localized: "^[\(count) item](inflect: true).")
+ case .intel:
+ return AttributedString(localized: "^[\(count) item](inflect: true) built for Intel.")
+ case .home, .packages, .fileSearch, .backgroundItems, .extensions, .plugins, .tweaks, .history:
+ return nil
+ }
+ }
+
+ /// The sentence for what `looked` holds, or nil while the tool hasn't looked or found nothing.
+ func summary(of looked: Looked?) -> AttributedString? {
+ guard let looked, looked.count > 0 else { return nil }
+ return sentence(for: looked)
+ }
+}
+
extension AppLibrary {
var summary: AttributedString? {
guard hasLoaded else { return nil }
@@ -23,69 +60,37 @@ extension AppLibrary {
let known = sizes.values.reduce(0, +)
let total = SizeTotal(known: known, isComplete: sizes.count >= count)
let size = known > 0 ? AttributedString(localized: "\(total.text) in ^[\(count) app](inflect: true).") : AttributedString(localized: "^[\(count) app](inflect: true).")
- let waiting = appsWithUpdates.count
- guard waiting > 0 else { return size }
- return size + AttributedString("\n") + AttributedString(localized: "^[\(waiting) update](inflect: true) waiting.")
+ guard let updates = Tool.applications.summary(of: Looked(count: appsWithUpdates.count, size: nil)) else { return size }
+ return size + AttributedString("\n") + updates
}
}
extension OrphanLibrary {
- var summary: AttributedString? {
- guard let groups = scan?.groups, !groups.isEmpty else { return nil }
- let total = SizeTotal(combining: groups.map(\.total))
- return total.known > 0
- ? AttributedString(localized: "\(total.text) in ^[\(groups.count) group](inflect: true).")
- : AttributedString(localized: "^[\(groups.count) group](inflect: true).")
- }
+ var summary: AttributedString? { Tool.orphans.summary(of: looked) }
}
extension DeveloperLibrary {
- var summary: AttributedString? {
- guard let environments, !environments.isEmpty else { return nil }
- let total = SizeTotal(combining: environments.map(\.total))
- return total.known > 0
- ? AttributedString(localized: "\(total.text) in ^[\(environments.count) tool](inflect: true).")
- : AttributedString(localized: "^[\(environments.count) tool](inflect: true).")
- }
+ var summary: AttributedString? { Tool.developer.summary(of: looked) }
}
extension ProjectLibrary {
- var summary: AttributedString? {
- guard let groups, !groups.isEmpty else { return nil }
- let total = SizeTotal(combining: groups.map(\.total))
- return total.known > 0
- ? AttributedString(localized: "\(total.text) in ^[\(groups.count) project](inflect: true).")
- : AttributedString(localized: "^[\(groups.count) project](inflect: true).")
- }
+ var summary: AttributedString? { Tool.projects.summary(of: looked) }
}
extension SpaceLibrary {
- var summary: AttributedString? {
- guard let items = report?.items, !items.isEmpty else { return nil }
- let total = SizeTotal(items.map(\.size))
- return total.known > 0
- ? AttributedString(localized: "\(total.text) in ^[\(items.count) area](inflect: true).")
- : AttributedString(localized: "^[\(items.count) area](inflect: true).")
- }
+ var summary: AttributedString? { Tool.space.summary(of: looked) }
}
extension InstallerLibrary {
- var summary: AttributedString? {
- guard let items = scan?.items, !items.isEmpty else { return nil }
- let total = SizeTotal(items.map(\.size))
- return total.known > 0
- ? AttributedString(localized: "\(total.text) in ^[\(items.count) item](inflect: true).")
- : AttributedString(localized: "^[\(items.count) item](inflect: true).")
- }
+ var summary: AttributedString? { Tool.installers.summary(of: looked) }
}
extension HomebrewLibrary {
var summary: AttributedString? {
guard let packages, !packages.isEmpty else { return nil }
let count = AttributedString(localized: "^[\(packages.count) package](inflect: true).")
- let outdated = packages.count(where: \.isOutdated)
- guard outdated > 0 else { return count }
- return count + AttributedString("\n") + AttributedString(localized: "^[\(outdated) update](inflect: true) waiting.")
+ guard let updates = Tool.homebrew.summary(of: looked) else { return count }
+ return count + AttributedString("\n") + updates
}
}
@@ -118,10 +123,7 @@ extension BackgroundItemLibrary {
}
extension IntelLibrary {
- var summary: AttributedString? {
- guard let findings = scan?.findings, !findings.isEmpty else { return nil }
- return AttributedString(localized: "^[\(findings.count) item](inflect: true) built for Intel.")
- }
+ var summary: AttributedString? { Tool.intel.summary(of: looked) }
}
extension RemovalHistoryStore {
diff --git a/README.md b/README.md
index 47172488..7e158d95 100644
--- a/README.md
+++ b/README.md
@@ -49,6 +49,9 @@ files scattered across your Library, sometimes gigabytes of them. Peel finds wha
file belongs to it and how sure it is, and moves what you choose to the Trash. Nothing is deleted, and History can
put all of it back.
+When you open it, Home lists what each tool found the last time it looked, a line per tool that takes you there. It
+never adds them up into one figure and never selects anything for you.
+
Peel is free and open source, and it speaks English and 17 other languages.
## What Peel does