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
Look on disk only at the Dock tiles of the apps asked about
Țugui Dragoșc1c2c3cdb7ee
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex eea3e912..268a3de8 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -154,7 +154,9 @@ the Homebrew page's uninstall and cleanups are Homebrew's own.checks the move makes first (the guard, History, and the programs holding it) say it will go(`PrivacyReset`).6. **Finish.** Only for what really moved: the launch jobs whose files went are stopped, macOS is told to- forget the preference domains whose files went, and an uninstalled app's Dock icon comes out (`DockTiles`),+ forget the preference domains whose files went, and an uninstalled app's Dock icon comes out (`DockTiles`: the+ tile naming the app's place, or naming its identifier with a bookmark that finds the app where it went, so an app+ the person moved or had already put in the Trash loses its icon too),unless Also remove from the Dock was turned off, or `peel uninstall` was given `--keep-in-dock`. On macOS 27,an app's page and several apps' page also say when macOS still starts the app's login items at login, now fromthe Trash, until the Trash is emptied (`TrashResult.startsFromTheTrash`). Both pages, and `peel uninstall`, alsodiff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swiftindex fbeef166..87caf037 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift@@ -685,7 +685,7 @@ struct UninstallCommand: AsyncParsableCommand {}let privacy = reset.map { Self.privacyOutcome($0, app: target, after: result) }if isInTheDock, Self.takesOutDockIcon(of: target, after: result, keeping: keepInDock) {- _ = await DockTiles().takeOut([target.url])+ _ = await DockTiles().takeOut([target.url], foundAt: result.trashedAt)}let references = await ShellReferences.find(naming: result.trashed.map(\.originalURL))diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/DockTiles.swift b/Packages/PeelCore/Sources/PeelCore/Apps/DockTiles.swiftindex 75a53d05..1224536d 100644--- a/Packages/PeelCore/Sources/PeelCore/Apps/DockTiles.swift+++ b/Packages/PeelCore/Sources/PeelCore/Apps/DockTiles.swift@@ -112,29 +112,35 @@ public struct DockTiles: Sendable {/// Those of `apps` that have a tile in the Dock.@concurrentpublic func holding(_ apps: [URL]) async -> Set<URL> {- let lists = DockList.allCases.compactMap { store.tiles(in: $0) }.map(Places.init)- return Set(apps.filter { app in lists.contains { !$0.indices(of: key(app)).isEmpty } })+ let asked = apps.map { Asked(app: $0, now: $0) }+ let lists = DockList.allCases.compactMap { store.tiles(in: $0) }.map { Places($0, lookingFor: asked) }+ return Set(asked.filter { app in lists.contains { !$0.indices(of: app).isEmpty } }.map(\.app))}/// Takes the tiles of `apps` out of the Dock, remembering where each was, and restarts the Dock once. False- /// when none had a tile, or when that could not be remembered or written. Peel removing itself remembers nothing,- /// since its folder, where the memory is kept, has gone to the Trash, and the tile of an app in `forgotten` is not- /// remembered either: such an app was already in the Trash, so History, which puts a tile back, never moved it.- public func takeOut(_ apps: [URL], remembering: Bool = true, forgetting forgotten: Set<URL> = []) async -> Bool {+ /// when none had a tile, or when that could not be remembered or written. An app that has moved is looked for where+ /// it went (`moves`). Peel removing itself remembers nothing, since its folder, where the memory is kept, has gone+ /// to the Trash, and the tile of an app in `forgotten` is not remembered either: such an app was already in the+ /// Trash, so History, which puts a tile back, never moved it.+ @concurrent+ public func takeOut(+ _ apps: [URL], foundAt moves: [URL: URL] = [:], remembering: Bool = true, forgetting forgotten: Set<URL> = []+ ) async -> Bool {+ let asked = apps.map { Asked(app: $0, now: moves[$0] ?? $0) }let lists = Dictionary(uniqueKeysWithValues: DockList.allCases.compactMap { list instore.tiles(in: list).map { (list, $0) }})- let places = lists.mapValues(Places.init)+ let places = lists.mapValues { Places($0, lookingFor: asked) }var removed: [String: [Removed]] = [:]- for app in apps {+ for one in asked {let found = lists.flatMap { list, tiles in- (places[list]?.indices(of: key(app)) ?? []).map { (list, tiles[$0], $0) }+ (places[list]?.indices(of: one) ?? []).map { (list, tiles[$0], $0) }}let kept = found.compactMap { list, tile, index in(try? PropertyListSerialization.data(fromPropertyList: tile, format: .binary, options: 0)).map { Removed(list: list, index: index, tile: $0, around: places[list]?.paths ?? []) }}- if !found.isEmpty, kept.count == found.count { removed[key(app)] = kept }+ if !found.isEmpty, kept.count == found.count { removed[key(one.app)] = kept }}let forgottenKeys = Set(forgotten.map(key))let remembered = removed.filter { !forgottenKeys.contains($0.key) }@@ -223,20 +229,51 @@ public struct DockTiles: Sendable {return found.map(PathPattern.comparablePath)}- /// Where each tile of a list leads, worked out once for the list, since a bookmark is resolved on disk.+ private static func identifier(of tile: Any) -> String? {+ (((tile as? [String: Any])?["tile-data"] as? [String: Any])?["bundle-identifier"] as? String)?.lowercased()+ }++ /// An app asked about: the place its tile names, and where it is now, which its tile's bookmark finds.+ private struct Asked {+ let app: URL+ let place: String+ let now: String+ let identifier: String?++ init(app: URL, now: URL) {+ self.app = app+ place = PathPattern.comparablePath(of: app)+ self.now = PathPattern.comparablePath(of: now)+ let info = BoundedRead.propertyList(at: AppBundleLayout(of: now).infoFolder.appending(path: "Info.plist"))+ identifier = (info?["CFBundleIdentifier"] as? String)?.lowercased()+ }+ }++ /// Where each tile of a list leads, worked out once for the list. Only a tile naming an app asked about is looked+ /// for on disk, so another app's tile, on a disk that may not answer, is never waited on.private struct Places {let paths: [String?]+ let identifiers: [String?]let bookmarked: [String?]- init(_ tiles: [Any]) {- paths = tiles.map(DockTiles.path(of:))- bookmarked = zip(tiles, paths).map { tile, path in- path.flatMap { DockTiles.bookmarkedPath(of: tile, leadingNowhereFrom: $0) }+ init(_ tiles: [Any], lookingFor asked: [Asked]) {+ let wanted = Set(asked.compactMap(\.identifier))+ let paths = tiles.map(DockTiles.path(of:))+ let identifiers = tiles.map(DockTiles.identifier(of:))+ bookmarked = tiles.indices.map { index in+ guard let identifier = identifiers[index], wanted.contains(identifier), let path = paths[index]+ else { return nil }+ return DockTiles.bookmarkedPath(of: tiles[index], leadingNowhereFrom: path)}+ self.paths = paths+ self.identifiers = identifiers}- func indices(of key: String) -> [Int] {- paths.indices.filter { paths[$0] == key || bookmarked[$0] == key }+ func indices(of app: Asked) -> [Int] {+ paths.indices.filter { index in+ paths[index] == app.place+ || app.identifier != nil && identifiers[index] == app.identifier && bookmarked[index] == app.now+ }}}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swiftindex 958d8f54..0e611dfc 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift@@ -254,6 +254,11 @@ public struct TrashResult: Sendable {self.failures = failures}+ /// Where each item that moved is now, by the place it was moved from.+ public var trashedAt: [URL: URL] {+ Dictionary(trashed.map { ($0.originalURL, $0.trashedURL) }) { first, _ in first }+ }+/// Marks each item whose move stopped the job it declares.mutating func note(_ stopped: [LaunchdCleanup.Job]) {for job in stopped {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DockTilesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DockTilesTests.swiftindex 8f53631d..97804443 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/DockTilesTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/DockTilesTests.swift@@ -53,8 +53,19 @@ struct DockTilesTests {["tile-data": ["file-data": ["_CFURLString": url, "_CFURLStringType": type]], "tile-type": "file-tile"]}- private static func tile(_ url: String, book: Data) -> [String: Any] {- ["tile-data": ["file-data": ["_CFURLString": url, "_CFURLStringType": 15], "book": book], "tile-type": "file-tile"]+ private static func tile(_ url: String, book: Data, identifier: String) -> [String: Any] {+ let file: [String: Any] = ["_CFURLString": url, "_CFURLStringType": 15]+ return ["tile-data": ["file-data": file, "book": book, "bundle-identifier": identifier], "tile-type": "file-tile"]+ }++ private static func app(+ _ directory: borrowing TemporaryDirectory, _ path: String, identifier: String+ ) throws -> URL {+ let info = ["CFBundleIdentifier": identifier]+ try directory.file("\(path)/Contents/Info.plist", contents: PropertyListSerialization.data(+ fromPropertyList: info, format: .xml, options: 0+ ))+ return directory.url.appending(path: path, directoryHint: .isDirectory).resolvingSymlinksInPath()}private static func spacer() -> [String: Any] {@@ -97,8 +108,8 @@ struct DockTilesTests {@Test func takesOutTheTileOfAnAppAlreadyInTheTrashWithoutRememberingIt() async throws {let directory = try TemporaryDirectory()let root = directory.url.resolvingSymlinksInPath()- let kept = try directory.directory("Applications/org.example.Studio.app").resolvingSymlinksInPath()- let tile = try Self.tile(kept.absoluteString, book: kept.bookmarkData())+ let kept = try Self.app(directory, "Applications/org.example.Studio.app", identifier: "org.example.Studio")+ let tile = try Self.tile(kept.absoluteString, book: kept.bookmarkData(), identifier: "org.example.Studio")try directory.directory(".Trash")let trashed = root.appending(path: ".Trash/org.example.Studio.app", directoryHint: .isDirectory)try FileManager.default.moveItem(at: kept, to: trashed)@@ -116,16 +127,52 @@ struct DockTilesTests {@Test func aTileWhoseBookmarkFindsACopyElsewhereIsNotTheTrashedApps() async throws {let directory = try TemporaryDirectory()let root = directory.url.resolvingSymlinksInPath()- let kept = try directory.directory("Applications/org.example.Studio.app").resolvingSymlinksInPath()- let tile = try Self.tile(kept.absoluteString, book: kept.bookmarkData())+ let kept = try Self.app(directory, "Applications/org.example.Studio.app", identifier: "org.example.Studio")+ let tile = try Self.tile(kept.absoluteString, book: kept.bookmarkData(), identifier: "org.example.Studio")try directory.directory("Elsewhere")try FileManager.default.moveItem(at: kept, to: root.appending(path: "Elsewhere/org.example.Studio.app"))- let trashed = try directory.directory(".Trash/org.example.Studio.app").resolvingSymlinksInPath()+ let trashed = try Self.app(directory, ".Trash/org.example.Studio.app", identifier: "org.example.Studio")+ let tiles = DockTiles(store: Store([tile]), memory: directory.url.appending(path: "dock-tiles.json"))++ #expect(await tiles.holding([trashed]).isEmpty)+ }++ @Test func aStaleTileOfAnotherAppIsNeverTakenForThisOne() async throws {+ let directory = try TemporaryDirectory()+ let root = directory.url.resolvingSymlinksInPath()+ let kept = try Self.app(directory, "Applications/org.example.Studio.app", identifier: "org.example.Studio")+ let tile = try Self.tile(kept.absoluteString, book: kept.bookmarkData(), identifier: "org.example.Other")+ try directory.directory(".Trash")+ let trashed = root.appending(path: ".Trash/org.example.Studio.app", directoryHint: .isDirectory)+ try FileManager.default.moveItem(at: kept, to: trashed)let tiles = DockTiles(store: Store([tile]), memory: directory.url.appending(path: "dock-tiles.json"))#expect(await tiles.holding([trashed]).isEmpty)}+ @Test func takesOutTheTileOfAnAppThePersonMovedOnceItGoesToTheTrash() async throws {+ let directory = try TemporaryDirectory()+ let root = directory.url.resolvingSymlinksInPath()+ let first = try Self.app(directory, "Applications/org.example.Studio.app", identifier: "org.example.Studio")+ let tile = try Self.tile(first.absoluteString, book: first.bookmarkData(), identifier: "org.example.Studio")+ try directory.directory("Applications/Tools")+ let moved = root.appending(path: "Applications/Tools/org.example.Studio.app", directoryHint: .isDirectory)+ try FileManager.default.moveItem(at: first, to: moved)+ let store = Store([Self.tile("file:///System/Applications/Mail.app/"), tile])+ let tiles = DockTiles(store: store, memory: directory.url.appending(path: "dock-tiles.json"))+ #expect(await tiles.holding([moved]) == [moved])++ try directory.directory(".Trash")+ let trashed = root.appending(path: ".Trash/org.example.Studio.app", directoryHint: .isDirectory)+ try FileManager.default.moveItem(at: moved, to: trashed)+ #expect(await tiles.takeOut([moved], foundAt: [moved: trashed]))+ #expect(store.paths() == ["/System/Applications/Mail.app"])++ try FileManager.default.moveItem(at: trashed, to: moved)+ await tiles.putBack([moved])+ #expect(store.paths().count == 2, "History put the app back without its tile")+ }+@Test func takesOutATileWithoutRememberingItInAFolderThatIsGone() async throws {let directory = try TemporaryDirectory()let store = Store([Self.tile("file:///Applications/org.example.Studio.app/")])diff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swiftindex fc66bd66..202d076c 100644--- a/Peel/Views/AppDetailView.swift+++ b/Peel/Views/AppDetailView.swift@@ -516,7 +516,7 @@ struct AppDetailView: View {let movedTheApp = result.trashed.contains(where: { $0.originalURL == plan.app.url })if plan.removesDockTile, movedTheApp || plan.isAppInTheTrash && !result.trashed.isEmpty {let forgotten: Set<URL> = plan.isAppInTheTrash ? [plan.app.url] : []- _ = await DockTiles().takeOut([plan.app.url], forgetting: forgotten)+ _ = await DockTiles().takeOut([plan.app.url], foundAt: result.trashedAt, forgetting: forgotten)}if let state = AppManagement.state(after: result,diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swiftindex e1d99743..edad16c0 100644--- a/Peel/Views/MultipleAppsView.swift+++ b/Peel/Views/MultipleAppsView.swift@@ -405,7 +405,7 @@ struct MultipleAppsView: View {// app already in the Trash whose own files moved.let inTheTrash = plan.appsInTheTrash(withFilesAmong: moved).map(\.url)let apps = (plan.apps.map(\.url).filter(moved.contains) + inTheTrash).sorted { $0.path < $1.path }- _ = await DockTiles().takeOut(apps, forgetting: Set(inTheTrash))+ _ = await DockTiles().takeOut(apps, foundAt: result.trashedAt, forgetting: Set(inTheTrash))}if let state = AppManagement.state(after: result,