Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Deselect a macOS installer once the helper can't move it

Țugui Dragoșdae61561eaad
diff --git a/Peel/Model/InstallerLibrary.swift b/Peel/Model/InstallerLibrary.swift
index 3b28f593..d75e8207 100644
--- a/Peel/Model/InstallerLibrary.swift
+++ b/Peel/Model/InstallerLibrary.swift
@@ -28,6 +28,15 @@ final class InstallerLibrary {
scan?.unreadableLocations ?? []
}
+ func follow(canUseHelper: Bool) {
+ let kept = Self.selection(selectedURLs, in: scan?.items ?? [], canUseHelper: canUseHelper)
+ if kept != selectedURLs { selectedURLs = kept }
+ }
+
+ static func selection(_ selected: Set<URL>, in items: [InstallerItem], canUseHelper: Bool) -> Set<URL> {
+ selected.subtracting(items.filter { $0.isLocked(canUseHelper: canUseHelper) }.map(\.url))
+ }
+
func refresh(installedApps: [InstalledApp]) async {
guard
let result = await scanRun.run({
diff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swift
index beac253f..28b072d8 100644
--- a/Peel/PeelApp.swift
+++ b/Peel/PeelApp.swift
@@ -129,6 +129,7 @@ struct PeelApp: App {
space.follow(canUseHelper: canAct)
orphans.follow(canUseHelper: canAct)
packages.follow(canUseHelper: canAct)
+ installers.follow(canUseHelper: canAct)
}
}
diff --git a/PeelTests/InstallerSelectionTests.swift b/PeelTests/InstallerSelectionTests.swift
new file mode 100644
index 00000000..6ac409b2
--- /dev/null
+++ b/PeelTests/InstallerSelectionTests.swift
@@ -0,0 +1,25 @@
+import Foundation
+@testable import Peel
+@testable import PeelCore
+import Testing
+
+@MainActor
+struct InstallerSelectionTests {
+ @Test func takesWhatWaitsForTheHelperOutOfTheSelection() {
+ let macOS = URL(filePath: "/Applications/Install macOS Tahoe.app", directoryHint: .isDirectory)
+ let image = URL(filePath: "/Users/me/Downloads/Tool.dmg")
+ var installer = InstallerItem(
+ url: macOS, kind: .macOSInstaller, name: "Install macOS Tahoe", size: 10, date: nil, installedApp: nil,
+ isReadOnly: false, notes: []
+ )
+ installer.requiresPrivileges = true
+ let download = InstallerItem(
+ url: image, kind: .appInstaller, name: "Tool.dmg", size: 10, date: nil, installedApp: nil,
+ isReadOnly: false, notes: []
+ )
+
+ let items = [installer, download]
+ #expect(InstallerLibrary.selection([macOS, image], in: items, canUseHelper: false) == [image])
+ #expect(InstallerLibrary.selection([macOS, image], in: items, canUseHelper: true) == [macOS, image])
+ }
+}