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
Take what left the disk off Plug-ins and Installers
Țugui Dragoș5a94bb8bc22b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1495d2ab..ccbbd5ed 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -632,6 +632,7 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.#### Installers and Backups+- What an uninstall moved, or Finder, leaves the page without a Rescan.- A downloaded update is no longer called installed, a `.part` another program writes is left unselected, and a diskimage that is open right now is never suggested or moved.- The figures count only what can move, device backups point to System Settings > General > Storage first, and a@@ -728,6 +729,7 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.#### Plug-ins+- A plug-in an uninstall moved, or Finder, leaves the list without a Rescan.- The page names the folders it couldn't read, follows a plug-in folder that is a link, and names a plug-in, and aQuick Action, as Finder and the Services menu do.- An input method in use gives the steps that free it, and a plug-in History can't put back says so before it moves.diff --git a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swiftindex ded8c248..f82bf72b 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift@@ -120,6 +120,11 @@ public struct InstallerScan: Sendable {public func items(in kind: InstallerItem.Kind) -> [InstallerItem] {items.filter { $0.kind == kind }}++ /// The scan without what is no longer on the disk.+ public var withoutWhatLeft: InstallerScan {+ InstallerScan(items: items.filter { !$0.url.isMissing }, unreadableLocations: unreadableLocations)+ }}public enum Installers {diff --git a/Peel/Model/InstallerLibrary.swift b/Peel/Model/InstallerLibrary.swiftindex a25561b8..c674a39f 100644--- a/Peel/Model/InstallerLibrary.swift+++ b/Peel/Model/InstallerLibrary.swift@@ -69,6 +69,17 @@ final class InstallerLibrary {await refresh(installedApps: installedApps)}+ /// Takes off the page what has left the disk since the scan, moved by another page's removal or in Finder.+ func leaveOutWhatLeft() {+ guard let scan, scan.items.contains(where: \.url.isMissing) else { return }+ let left = scan.withoutWhatLeft+ self.scan = left+ selectedURLs.formIntersection(left.items.map(\.url))+ if let selection, left.items(in: selection).isEmpty {+ self.selection = nil+ }+ }+func refresh(installedApps: [InstalledApp]) async {guardlet result = await scanRun.run({ [scanning] indiff --git a/Peel/Model/PluginLibrary.swift b/Peel/Model/PluginLibrary.swiftindex b4f97eec..35c87d5c 100644--- a/Peel/Model/PluginLibrary.swift+++ b/Peel/Model/PluginLibrary.swift@@ -39,6 +39,13 @@ final class PluginLibrary {}}+ /// Takes off the list what has left the disk since the scan, moved by another page's removal or in Finder.+ func leaveOutWhatLeft() {+ guard let plugins, plugins.contains(where: \.url.isMissing) else { return }+ self.plugins = plugins.filter { !$0.url.isMissing }+ if selectedPlugin == nil { selection = nil }+ }+func moveToTrash(_ plugin: Plugin, recording record: (TrashResult) async -> Void) async -> TrashResult {isRemoving = truedefer { isRemoving = false }diff --git a/Peel/Views/Installers/InstallerList.swift b/Peel/Views/Installers/InstallerList.swiftindex bde16e30..4c102c81 100644--- a/Peel/Views/Installers/InstallerList.swift+++ b/Peel/Views/Installers/InstallerList.swift@@ -5,6 +5,7 @@ import SwiftUIstruct InstallerList: View {@Environment(AppLibrary.self) private var library@Environment(InstallerLibrary.self) private var installers+ @Environment(RemovalHistoryStore.self) private var history@Environment(HelperModel.self) private var helper@State private var isRescanning = false@@ -90,6 +91,7 @@ struct InstallerList: View {guard library.hasLoaded else { return }await installers.refreshUnlessScanned(within: InstallerLibrary.scanAgainAfter, installedApps: library.apps)}+ .task(id: history.revision) { installers.leaveOutWhatLeft() }.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ inguard library.hasLoaded else { return }Task {diff --git a/Peel/Views/Plugins/PluginList.swift b/Peel/Views/Plugins/PluginList.swiftindex 8e1b9b51..8b5718f1 100644--- a/Peel/Views/Plugins/PluginList.swift+++ b/Peel/Views/Plugins/PluginList.swift@@ -3,6 +3,7 @@ import SwiftUIstruct PluginList: View {@Environment(PluginLibrary.self) private var plugins+ @Environment(RemovalHistoryStore.self) private var history@State private var searchText = ""@State private var isRescanning = false@@ -106,6 +107,7 @@ struct PluginList: View {guard plugins.plugins == nil, !plugins.scanRun.isWaitedFor, !plugins.scanRun.wasStopped else { return }await plugins.refresh()}+ .task(id: history.revision) { plugins.leaveOutWhatLeft() }.rescanOnExclusionChange("PluginList") { await plugins.refresh() }.rescanAfterPutBack(.plugins) { await plugins.refresh() }}diff --git a/PeelTests/InstallerSelectionTests.swift b/PeelTests/InstallerSelectionTests.swiftindex bf848342..a2e98b4b 100644--- a/PeelTests/InstallerSelectionTests.swift+++ b/PeelTests/InstallerSelectionTests.swift@@ -27,6 +27,44 @@ struct InstallerSelectionTests {#expect(scans.withLock { $0 } == 2)}+ @Test func leavesOutWhatHasLeftTheDiskWithoutScanningAgain() async throws {+ let directory = FileManager.default.temporaryDirectory.appending(+ path: "InstallerSelectionTests-\(UUID().uuidString)", directoryHint: .isDirectory+ )+ try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)+ defer { try? FileManager.default.removeItem(at: directory) }+ let items = try ["Kept.dmg", "Gone.dmg"].map { name in+ let url = directory.appending(path: name)+ try Data("x".utf8).write(to: url)+ return InstallerItem(+ url: url, kind: .appInstaller, name: name, size: 1, date: nil, installedApp: nil, isReadOnly: false,+ notes: []+ )+ }+ let scans = Mutex(0)+ let library = InstallerLibrary { _, _ in+ scans.withLock { $0 += 1 }+ return InstallerScan(items: items, unreadableLocations: [])+ }+ await library.refresh(installedApps: [])+ library.selection = .appInstaller+ library.selectedURLs = [items[0].url, items[1].url]+ try FileManager.default.removeItem(at: items[1].url)++ library.leaveOutWhatLeft()++ #expect(library.scan?.items.map(\.name) == ["Kept.dmg"])+ #expect(library.selectedURLs == [items[0].url])+ #expect(library.selection == .appInstaller)+ #expect(scans.withLock { $0 } == 1)++ try FileManager.default.removeItem(at: items[0].url)+ library.leaveOutWhatLeft()++ #expect(library.scan?.items.isEmpty == true)+ #expect(library.selection == nil)+ }+@Test func aSearchNarrowsThePageUnlessItNamesThePage() async {let items = [item("Firefox.dmg"), item("Chrome.dmg"), item("Install macOS", kind: .macOSInstaller)]let library = InstallerLibrary { _, _ in InstallerScan(items: items, unreadableLocations: []) }diff --git a/PeelTests/PluginLibraryTests.swift b/PeelTests/PluginLibraryTests.swiftindex b1af451c..e6ca6158 100644--- a/PeelTests/PluginLibraryTests.swift+++ b/PeelTests/PluginLibraryTests.swift@@ -52,4 +52,33 @@ struct PluginLibraryTests {#expect(library.selection == nil)#expect(reads.count == 1, "the list is read again only once the page has said how the move went")}++ @Test func leavesOutWhatHasLeftTheDiskWithoutReadingTheListAgain() async throws {+ let root = FileManager.default.temporaryDirectory.appending(+ path: "PluginLibraryTests-\(UUID().uuidString)", directoryHint: .isDirectory+ )+ defer { try? FileManager.default.removeItem(at: root) }+ let plugins = try ["Echo", "Delay"].map { name in+ let url = root.appending(path: "\(name).component", directoryHint: .isDirectory)+ try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)+ return Plugin(+ url: url, name: name, bundleIdentifier: nil, version: nil, category: .audioUnits,+ isInstalledForAllUsers: false, size: 1, requiresPrivileges: false, refusal: nil+ )+ }+ let reads = Reads()+ let library = PluginLibrary(scan: { _ in+ reads.count += 1+ return PluginScan(plugins: plugins)+ })+ await library.refresh()+ library.selection = plugins[0].id+ try FileManager.default.removeItem(at: plugins[0].url)++ library.leaveOutWhatLeft()++ #expect(library.plugins?.map(\.name) == ["Delay"])+ #expect(library.selection == nil)+ #expect(reads.count == 1)+ }}