Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Make peel updates answer as the app does and say what it couldn't read
Țugui Dragoșdece18a5fc0e
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swiftindex 2defea1a..08e1b6b6 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift@@ -722,8 +722,8 @@ struct UpdatesCommand: AsyncParsableCommand {abstract: "Check installed apps for updates.",discussion: """Peel reads the settings of the Peel app: which source it prefers, which apps it was told to leave alone, \- and which versions were skipped. Nothing is installed; apps with no feed are left out unless --all is \- given.+ which versions were skipped, and what its checks found before. Nothing is installed. Only apps with an \+ update or a check that failed are listed unless --all is given.""")@@ -803,7 +803,8 @@ struct UpdatesCommand: AsyncParsableCommand {}func run() async throws {- let apps = await AppCatalog.installedApps()+ let catalog = await AppCatalog.scan()+ let apps = catalog.apps// The Peel app's own update settings, so `peel` and the app agree on which updates are waiting.let preferences = UpdatePreferences.asTheAppSeesThem()let homebrew = await CaskLookup.installed()@@ -811,7 +812,8 @@ struct UpdatesCommand: AsyncParsableCommand {let checker = UpdateChecker()let statuses = await ProgressLine.reporting { show inawait Self.statuses(- for: toCheck, checker: checker, preference: preferences.source, casks: homebrew.casks+ for: toCheck, checker: checker, preference: preferences.source, casks: homebrew.casks,+ memory: UpdateMemories.asTheAppSeesThem().recalled(for: apps)) { answered inshow(Self.progress(checked: answered, of: toCheck.count))}@@ -833,6 +835,9 @@ struct UpdatesCommand: AsyncParsableCommand {if let note = homebrew.note {Output.note(note)}+ if let note = Output.unreadableNote(for: catalog) {+ Output.note(note)+ }let cannotTell = toCheck.filter { statuses[$0.id] == .unsupported }.compactMap { app inchecker.homebrewCannotTell(about: app, preference: preferences.source, casks: homebrew.casks)}@@ -893,25 +898,36 @@ struct UpdatesCommand: AsyncParsableCommand {}}- private static func statuses(+ static func statuses(for apps: [InstalledApp],checker: UpdateChecker,preference: UpdateSource,casks: [HomebrewPackage],+ memory: UpdateMemories,answered: (Int) -> Void) async -> [InstalledApp.ID: UpdateStatus] {- await withTaskGroup(of: (InstalledApp.ID, UpdateStatus).self) { group in+ // As the app does: what a check found before is its earlier answer, and an update its own source found is+ // kept through a check of that source that failed.+ let check = { @Sendable (app: InstalledApp) async -> (InstalledApp.ID, UpdateStatus) in+ let earlier = memory.entry(for: app)+ let answer = await checker.answer(+ for: app, preference: preference, casks: casks, earlier: earlier?.status,+ notListedBefore: earlier?.isNotListed == true+ )+ return (app.id, answer.following(earlier?.status))+ }+ return await withTaskGroup(of: (InstalledApp.ID, UpdateStatus).self) { group invar pending = apps.makeIterator()var statuses: [InstalledApp.ID: UpdateStatus] = [:]for _ in 0..<concurrentChecks {guard let app = pending.next() else { break }- group.addTask { (app.id, await checker.status(for: app, preference: preference, casks: casks)) }+ group.addTask { await check(app) }}while case let (id, status)? = await group.next() {statuses[id] = statusanswered(statuses.count)if let app = pending.next() {- group.addTask { (app.id, await checker.status(for: app, preference: preference, casks: casks)) }+ group.addTask { await check(app) }}}return statusesdiff --git a/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift b/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swiftindex 9020b94a..f1f78466 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/PeelCommand.swift@@ -6,7 +6,7 @@ public struct PeelCommand: AsyncParsableCommand {public static let configuration = CommandConfiguration(commandName: "peel",abstract: "Find what apps leave behind and move it to the Trash.",- discussion: "Peel only moves files to the Trash, so you can put them back. Items that need administrator access are left for the Peel app, which says how to remove in Finder those its helper may not move, and the tool refuses to run with sudo. History, the record of refusals, and the exclusions are in ~/Library/Application Support/Peel, shared with the Peel app, and in JSON a size Peel couldn't measure is null. The tool writes English whatever the Mac's language, since scripts read what it prints. Exit status: 0 when it did what was asked, 1 when something failed or stayed where it was, or History couldn't record what moved, 2 when you answered no, and 64 when the command or its options are wrong, or when Peel would have to ask and can't (add --yes).",+ discussion: "Peel only moves files to the Trash, so you can put them back. Items that need administrator access are left for the Peel app, which says how to remove in Finder those its helper may not move, and the tool refuses to run with sudo. History, the record of refusals, and the exclusions are in ~/Library/Application Support/Peel, shared with the Peel app, and in JSON a size Peel couldn't measure is null. The tool writes English whatever the Mac's language, since scripts read what it prints. Exit status: 0 when it did what was asked, 1 when something failed or stayed where it was (for `peel updates`, when no check got an answer), or History couldn't record what moved, 2 when you answered no, and 64 when the command or its options are wrong, or when Peel would have to ask and can't (add --yes).",version: Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "",subcommands: [AppsCommand.self,diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateMemory.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateMemory.swiftindex a21e767a..fa898b10 100644--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateMemory.swift+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateMemory.swift@@ -1,4 +1,5 @@public import Foundation+internal import PeelPrivileged/// What Peel knows about one app's updates, kept by bundle identifier so it survives the app being moved.///@@ -86,6 +87,16 @@ public struct UpdateMemories: Equatable, Sendable {entries.isEmpty}+ /// The key the Peel app keeps them under in its preferences, which `peel` reads too.+ public static let key = "updateMemory"++ /// What the Peel app remembers, read and never written, so `peel updates` keeps what the app keeps.+ public static func asTheAppSeesThem() -> UpdateMemories {+ let defaults = Bundle.main.bundleIdentifier == HelperIdentity.appIdentifier+ ? UserDefaults.standard : UserDefaults(suiteName: HelperIdentity.appIdentifier)+ return defaults?.data(forKey: key).flatMap(UpdateMemories.init(data:)) ?? UpdateMemories()+ }+/// The entry about the build `app` is at.public func entry(for app: InstalledApp) -> UpdateMemory? {app.bundleIdentifier.flatMap { entries[$0] }?.first { $0.describes(app) }diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swiftindex fd7043d4..0734dd64 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift@@ -1373,3 +1373,43 @@ struct CommandLineTests {#expect(source.components(separatedBy: "ExclusionStore().load()").count == 1)}}++/// Fails every request as a server that can't be reached does, and sends nothing anywhere.+private final class Unreachable: URLProtocol, @unchecked Sendable {+ override class func canInit(with request: URLRequest) -> Bool { true }+ override class func canonicalRequest(for request: URLRequest) -> URLRequest { request }+ override func stopLoading() {}++ override func startLoading() {+ client?.urlProtocol(self, didFailWithError: URLError(.cannotFindHost))+ }+}++struct UpdatesCommandTests {+ @Test func keepsAnUpdateThePeelAppFoundWhenItsCheckFails() async throws {+ let configuration = URLSessionConfiguration.ephemeral+ configuration.protocolClasses = [Unreachable.self]+ let checker = UpdateChecker(session: URLSession(configuration: configuration))+ let app = InstalledApp(+ url: URL(filePath: "/Applications/Fed.app"), bundleIdentifier: "org.example.fed", name: "Fed",+ version: "1.0", updateFeed: .sparkle(try #require(URL(string: "https://feed.example.com/appcast.xml")))+ )+ let found = UpdateStatus.updateAvailable(version: "2.0", source: .developer)+ var memory = UpdateMemories()+ memory.keep(+ UpdateMemory(status: found, schedule: .next(after: found, following: nil), checked: .now, describing: app),+ for: app+ )++ let statuses = await UpdatesCommand.statuses(+ for: [app], checker: checker, preference: .automatic, casks: [], memory: memory+ ) { _ in }++ #expect(statuses[app.id] == found, "peel said the check failed where the app shows the update it found")+ }++ @Test func saysWhatItLeavesOutWithoutAll() {+ let discussion = UpdatesCommand.configuration.discussion+ #expect(discussion.contains("Only apps with an update or a check that failed are listed unless --all is given."))+ }+}diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swiftindex d8d66f0d..0f9968a3 100644--- a/Peel/Views/Settings/SettingsView.swift+++ b/Peel/Views/Settings/SettingsView.swift@@ -140,11 +140,11 @@ enum SettingsKey {static let sidebarTools = "sidebar.tools"/// The tools left out before each tool had a default, carried into `sidebarTools` once.private static let hiddenToolsBefore = "sidebar.hiddenTools"- /// The `peel` tool reads these three keys too, so they are defined once, in PeelCore.+ /// The `peel` tool reads these four keys too, so they are defined once, in PeelCore.static let updateSource = UpdatePreferences.Key.sourcestatic let ignoredUpdateApps = UpdatePreferences.Key.ignoredAppsstatic let skippedUpdateVersions = UpdatePreferences.Key.skippedVersions- static let updateMemory = "updateMemory"+ static let updateMemory = UpdateMemories.keystatic let announcedUpdates = "updates.announced"/// Nil once the link leads to this copy's tool, and while something that may not be Peel's is where it goes.diff --git a/Support/peel.1 b/Support/peel.1index b28b9b7b..43361fe4 100644--- a/Support/peel.1+++ b/Support/peel.1@@ -11,7 +11,7 @@.Op Fl -version.Op Fl -help.Sh DESCRIPTION-Peel only moves files to the Trash, so you can put them back. Items that need administrator access are left for the Peel app, which says how to remove in Finder those its helper may not move, and the tool refuses to run with sudo. History, the record of refusals, and the exclusions are in ~/Library/Application Support/Peel, shared with the Peel app, and in JSON a size Peel couldn't measure is null. The tool writes English whatever the Mac's language, since scripts read what it prints. Exit status: 0 when it did what was asked, 1 when something failed or stayed where it was, or History couldn't record what moved, 2 when you answered no, and 64 when the command or its options are wrong, or when Peel would have to ask and can't (add --yes).+Peel only moves files to the Trash, so you can put them back. Items that need administrator access are left for the Peel app, which says how to remove in Finder those its helper may not move, and the tool refuses to run with sudo. History, the record of refusals, and the exclusions are in ~/Library/Application Support/Peel, shared with the Peel app, and in JSON a size Peel couldn't measure is null. The tool writes English whatever the Mac's language, since scripts read what it prints. Exit status: 0 when it did what was asked, 1 when something failed or stayed where it was (for `peel updates`, when no check got an answer), or History couldn't record what moved, 2 when you answered no, and 64 when the command or its options are wrong, or when Peel would have to ask and can't (add --yes)..Bl -tag -width 6n.It Fl -versionShow the version.@@ -311,7 +311,7 @@ Show help information..It Em updatesCheck installed apps for updates..Pp-Peel reads the settings of the Peel app: which source it prefers, which apps it was told to leave alone, and which versions were skipped. Nothing is installed; apps with no feed are left out unless --all is given.+Peel reads the settings of the Peel app: which source it prefers, which apps it was told to leave alone, which versions were skipped, and what its checks found before. Nothing is installed. Only apps with an update or a check that failed are listed unless --all is given..Bl -tag -width 6n.It Fl -allShow every app, not only those with an update.