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
Say how a plug-in's move went before reading the list again
Țugui Dragoș58b7fed7c300
diff --git a/Peel/Model/PluginLibrary.swift b/Peel/Model/PluginLibrary.swiftindex 2d019703..b4f97eec 100644--- a/Peel/Model/PluginLibrary.swift+++ b/Peel/Model/PluginLibrary.swift@@ -13,14 +13,24 @@ final class PluginLibrary {var isScanning: Bool { scanRun.isRunning }private(set) var isRemoving = falsevar selection: Plugin.ID?+ private let scan: @MainActor (Exclusions) async -> PluginScan+ private let trashService: @MainActor (Exclusions) -> TrashService++ init(+ scan: @escaping @MainActor (Exclusions) async -> PluginScan = { await Plugins.scan(exclusions: $0) },+ trashService: @escaping @MainActor (Exclusions) -> TrashService = { TrashService(exclusions: $0) }+ ) {+ self.scan = scan+ self.trashService = trashService+ }var selectedPlugin: Plugin? {plugins?.first { $0.id == selection }}func refresh() async {- guard let result = await scanRun.run({ await Plugins.scan(exclusions: ExclusionsStore.shared.exclusions) })- else { return }+ let scan = scan+ guard let result = await scanRun.run({ await scan(ExclusionsStore.shared.exclusions) }) else { return }plugins = result.pluginsunreadable = result.unreadableneedsFullDiskAccess = result.needsFullDiskAccess@@ -33,16 +43,19 @@ final class PluginLibrary {isRemoving = truedefer { isRemoving = false }let privileged: Set<URL> = plugin.requiresPrivileges ? [plugin.url] : []+ let service = trashService(ExclusionsStore.shared.exclusions)let result = await QuitGuard.shared.run {- let result = await TrashService(exclusions: ExclusionsStore.shared.exclusions).trash(- [plugin.url],- usingHelperFor: privileged- )- // Written down before the rescan, which can take a while: History is the way back for what just moved.+ let result = await service.trash([plugin.url], usingHelperFor: privileged)await record(result)return result}- await refresh()+ // What moved leaves the list at once, so the page can say how the move went before the list, which can take+ // a while, is read again.+ let moved = Set(result.trashed.map(\.originalURL))+ plugins?.removeAll { moved.contains($0.url) }+ if let selection, moved.contains(selection) {+ self.selection = nil+ }return result}}diff --git a/Peel/Views/Plugins/PluginDetailView.swift b/Peel/Views/Plugins/PluginDetailView.swiftindex 7c145f3c..200a2fe0 100644--- a/Peel/Views/Plugins/PluginDetailView.swift+++ b/Peel/Views/Plugins/PluginDetailView.swift@@ -116,6 +116,9 @@ struct PluginDetailView: View {)}outcome.report(result)+ if !result.trashed.isEmpty {+ await plugins.refresh()+ }}}Button("Cancel", role: .cancel) {}diff --git a/PeelTests/PluginLibraryTests.swift b/PeelTests/PluginLibraryTests.swiftnew file mode 100644index 00000000..b1af451c--- /dev/null+++ b/PeelTests/PluginLibraryTests.swift@@ -0,0 +1,55 @@+import Foundation+@testable import Peel+@testable import PeelCore+import Testing++@MainActor+struct PluginLibraryTests {+ private final class Reads {+ var count = 0+ }++ @Test func takesAMovedPlugInOffTheListBeforeReadingItAgain() async throws {+ let root = FileManager.default.temporaryDirectory.appending(+ path: "PluginLibraryTests-\(UUID().uuidString)", directoryHint: .isDirectory+ )+ defer { try? FileManager.default.removeItem(at: root) }+ let home = root.appending(path: "home", directoryHint: .isDirectory)+ let trash = root.appending(path: "Trash", directoryHint: .isDirectory)+ let echo = home.appending(path: "Library/Audio/Plug-Ins/Components/Echo.component", directoryHint: .isDirectory)+ try FileManager.default.createDirectory(at: echo, withIntermediateDirectories: true)+ try FileManager.default.createDirectory(at: trash, withIntermediateDirectories: true)+ let plugin = Plugin(+ url: echo, name: "Echo", 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: [plugin])+ },+ trashService: { _ in+ TrashService(+ environment: SearchEnvironment(+ homeDirectory: home, rootDirectory: root.appending(path: "root", directoryHint: .isDirectory)+ ),+ moveToTrash: { url in+ let destination = trash.appending(path: UUID().uuidString)+ try FileManager.default.moveItem(at: url, to: destination)+ return destination+ }+ )+ }+ )+ await library.refresh()+ library.selection = plugin.id++ let result = await library.moveToTrash(plugin) { _ in }++ #expect(result.trashed.map(\.originalURL) == [echo])+ #expect(library.plugins?.isEmpty == true)+ #expect(library.selection == nil)+ #expect(reads.count == 1, "the list is read again only once the page has said how the move went")+ }+}