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 an area's plan again once an app its note names quits
Țugui Dragoșe6e1f1810213
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swiftindex a3a8e389..89bf3bb8 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift@@ -274,10 +274,7 @@ public enum SpaceRemoval {var names: [String: String] = [:]for process in running {let bundle = process.bundleURL?.deletingPathExtension().lastPathComponent- // Folders on disk carry the bundle's file name. The user sees the app's name as Finder shows it.- guard let displayed = process.bundleURL.map(AppInspector.displayName) ?? process.bundleIdentifier else {- continue- }+ guard let displayed = name(of: process) else { continue }let spellings = [process.bundleIdentifier,process.bundleIdentifier?.split(separator: ".").last.map(String.init),@@ -291,6 +288,18 @@ public enum SpaceRemoval {return names}+ /// The name a plan gives an open app, the one the person knows: Finder's, else its identifier.+ static func name(of process: RunningCopies.Process) -> String? {+ process.bundleURL.map(AppInspector.displayName) ?? process.bundleIdentifier+ }++ /// Those of `apps`, named as a plan names them (`Plan.appsToQuit`), that `running` no longer holds.+ @concurrent+ public static func quit(of apps: [String], running: [RunningCopies.Process]) async -> [String] {+ let open = Set(running.compactMap(name(of:)))+ return apps.filter { !open.contains($0) }+ }+/// Squirrel's folder, named for the app's identifier, and electron-updater's, named in its `app-update.yml`.private static func updaterFolders(of process: RunningCopies.Process) -> [String] {let squirrel = process.bundleIdentifier.map { $0 + Squirrel.folderSuffix }diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swiftindex 404c8954..7b4f40d7 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift@@ -530,6 +530,14 @@ struct SpaceRemovalTests {#expect(plan.appsToQuit == ["Chat Example"])}+ @Test func knowsWhichOfTheAppsANoteNamesHaveQuit() async {+ let running = [RunningCopies.Process(identifier: 1, bundleIdentifier: "org.example.editor", bundleURL: nil)]++ let quit = await SpaceRemoval.quit(of: ["org.example.editor", "org.example.player"], running: running)++ #expect(quit == ["org.example.player"])+ }+@Test func anOpenAppAnswersToTheGroupsItsSignatureClaims() {let notes = RunningCopies.Process(identifier: 1, bundleIdentifier: "com.apple.Notes",diff --git a/Peel/Model/SpaceLibrary.swift b/Peel/Model/SpaceLibrary.swiftindex 2cd09c4b..ae5e688e 100644--- a/Peel/Model/SpaceLibrary.swift+++ b/Peel/Model/SpaceLibrary.swift@@ -23,6 +23,7 @@ final class SpaceLibrary: RowSelection {/// are none, and before the first measurement.private(set) var models: SizeTotal?@ObservationIgnored private var modelsMeasurement = 0+ @ObservationIgnored private var quitCheck: Task<Void, Never>?var selectedItem: SpaceItem? {report?.items.first { $0.id == selection }@@ -51,6 +52,17 @@ final class SpaceLibrary: RowSelection {await measureWhatIsLeftToDeveloper(in: item)}+ /// Makes the area's plan again once an app it leaves alone has quit, as its page asks the person to do.+ func followQuits(in item: SpaceItem) {+ guard let apps = plans[item.id]?.appsToQuit, !apps.isEmpty else { return }+ let running = RunningCopies.current+ quitCheck?.cancel()+ quitCheck = Task {+ guard await !SpaceRemoval.quit(of: apps, running: running).isEmpty, !Task.isCancelled else { return }+ await plan(item)+ }+ }+/// Measures the folders the area's plan leaves to Developer once its list is shown, since only the page's notice/// reads their sizes, and with them those it keeps in place, so the notice says what the area holds now. A plan/// made again meanwhile takes them only if it leaves the same folders.diff --git a/Peel/Views/Space/SpaceDetailView.swift b/Peel/Views/Space/SpaceDetailView.swiftindex 81258784..742d2135 100644--- a/Peel/Views/Space/SpaceDetailView.swift+++ b/Peel/Views/Space/SpaceDetailView.swift@@ -107,6 +107,11 @@ struct SpaceDetailView: View {guard !item.isReadOnly else { return }await space.plan(item)}+ // The note asks to quit an app to include its folders. The workspace reports every change to the apps that+ // run through key-value observing, while it posts no notice for a menu bar or background app.+ .onReceive(NSWorkspace.shared.publisher(for: \.runningApplications)) { _ in+ space.followQuits(in: item)+ }.fadesInColumn(whenRowsChange: rows).navigationTitle(Text(item.words.title)).toolbar(removing: .title)