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.

Keep Intel Software current as plug-ins, jobs, and drivers change

Țugui Dragoș0e1a6c7e6271
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
index ed96dab1..4e6cff53 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
@@ -28,8 +28,8 @@ public struct IntelFinding: Sendable, Hashable, Identifiable {
public struct IntelScan: Sendable {
public let findings: [IntelFinding]
- /// What the scan couldn't read, each named once: folders it couldn't look into and programs it couldn't open, the
- /// plug-in scan's included. Something there may need Rosetta.
+ /// What the scan couldn't read, each named once: folders it couldn't look into and programs it couldn't open.
+ /// Something there may need Rosetta.
public var unreadable: [URL] = []
/// True when macOS's privacy protection kept Peel out of one of them, which Full Disk Access lifts.
public var needsFullDiskAccess = false
@@ -94,14 +94,12 @@ public enum IntelInspector {
@concurrent
public static func scan(
installedApps: [InstalledApp],
- plugins: PluginScan = PluginScan(),
backgroundItems: BackgroundItems.Scan = BackgroundItems.Scan(),
exclusions: Exclusions = .none,
environment: SearchEnvironment = .current
) async -> IntelScan {
await scan(
installedApps: installedApps,
- plugins: plugins,
backgroundItems: backgroundItems,
exclusions: exclusions,
environment: environment,
@@ -112,7 +110,6 @@ public enum IntelInspector {
@concurrent
static func scan(
installedApps: [InstalledApp],
- plugins: PluginScan = PluginScan(),
backgroundItems: BackgroundItems.Scan = BackgroundItems.Scan(),
exclusions: Exclusions,
environment: SearchEnvironment = .current,
@@ -154,15 +151,20 @@ public enum IntelInspector {
}
}
- unreadable += plugins.unreadable
- for plugin in plugins.plugins where !Task.isCancelled && !exclusions.excludes(plugin.url) {
- guard isIntelOnly(bundle: plugin.url, unreadable: &unreadable), isNew(plugin.url) else { continue }
+ // Read here rather than taken from the Plug-ins page, whose list is as old as its last scan. Apple's own are
+ // left out, as that page leaves them out.
+ for plugin in Plugins.installed(in: environment, unreadable: &unreadable)
+ where !Task.isCancelled && !exclusions.excludes(plugin.url) {
+ guard isIntelOnly(bundle: plugin.url, unreadable: &unreadable), !AppleCode.isApples(plugin.url),
+ isNew(plugin.url)
+ else { continue }
+ let info = AppInspector.infoDictionary(in: plugin.url.appending(path: "Contents", directoryHint: .isDirectory))
findings.append(IntelFinding(
url: plugin.url,
kind: .plugin,
- name: plugin.name,
+ name: Plugins.name(of: plugin.url, info: info),
owner: nil,
- size: plugin.size,
+ size: await measure(plugin.url),
pluginCategory: plugin.category,
))
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift b/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift
index 151fd39e..edbf2f08 100644
--- a/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Plugins/Plugins.swift
@@ -85,12 +85,6 @@ public struct PluginScan: Sendable {
public var unreadable: [URL] = []
/// True when macOS's privacy protection kept Peel out of one of them, which Full Disk Access lifts.
public var needsFullDiskAccess = false
-
- public init(plugins: [Plugin] = [], unreadable: [URL] = [], needsFullDiskAccess: Bool = false) {
- self.plugins = plugins
- self.unreadable = unreadable
- self.needsFullDiskAccess = needsFullDiskAccess
- }
}
/// Finds the plug-ins that apps have installed in the folders macOS loads plug-ins from. Apple's own
@@ -123,21 +117,9 @@ public enum Plugins {
exclusions: Exclusions,
measure: @escaping FileSize.Measure
) async -> PluginScan {
- let libraries = [
- (environment.homeDirectory.appending(path: "Library", directoryHint: .isDirectory), false),
- (environment.rootDirectory.appending(path: "Library", directoryHint: .isDirectory), true),
- ]
- var found: [(url: URL, category: Plugin.Category, isForAllUsers: Bool)] = []
var unreadable: [URL] = []
- for (library, isForAllUsers) in libraries {
- for (folder, category) in folders {
- let directory = library.appending(path: folder, directoryHint: .isDirectory)
- for url in bundles(in: directory, category: category, unreadable: &unreadable)
- where !Task.isCancelled && !exclusions.excludes(url) && !exclusions.holds(url) {
- found.append((url, category, isForAllUsers))
- }
- }
- }
+ let found = installed(in: environment, unreadable: &unreadable)
+ .filter { !exclusions.excludes($0.url) && !exclusions.holds($0.url) }
// A few at a time, as the other scans measure: the guard's answer and the size each take a while, and a Mac
// used for music can hold more than a thousand plug-ins.
let removalGuard = RemovalGuard(environment: environment, exclusions: exclusions)
@@ -149,7 +131,7 @@ public enum Plugins {
let requiresPrivileges = folder.requiresPrivileges(toRemove: item.url)
var plugin = Plugin(
url: item.url,
- name: (info?["CFBundleName"] as? String) ?? item.url.deletingPathExtension().lastPathComponent,
+ name: name(of: item.url, info: info),
bundleIdentifier: info?["CFBundleIdentifier"] as? String,
version: (info?["CFBundleShortVersionString"] ?? info?["CFBundleVersion"]) as? String,
category: item.category,
@@ -172,6 +154,32 @@ public enum Plugins {
)
}
+ /// The plug-ins in the user's Library and the Mac's, each with its kind and whether it is there for every account.
+ /// A folder that is there and can't be listed joins `unreadable`.
+ static func installed(
+ in environment: SearchEnvironment, unreadable: inout [URL]
+ ) -> [(url: URL, category: Plugin.Category, isForAllUsers: Bool)] {
+ let libraries = [
+ (environment.homeDirectory.appending(path: "Library", directoryHint: .isDirectory), false),
+ (environment.rootDirectory.appending(path: "Library", directoryHint: .isDirectory), true),
+ ]
+ var found: [(url: URL, category: Plugin.Category, isForAllUsers: Bool)] = []
+ for (library, isForAllUsers) in libraries {
+ for (folder, category) in folders {
+ let directory = library.appending(path: folder, directoryHint: .isDirectory)
+ for url in bundles(in: directory, category: category, unreadable: &unreadable) where !Task.isCancelled {
+ found.append((url, category, isForAllUsers))
+ }
+ }
+ }
+ return found
+ }
+
+ /// The name a plug-in shows: the one its bundle declares, or its file's without the extension that says its kind.
+ static func name(of url: URL, info: [String: Any]?) -> String {
+ (info?["CFBundleName"] as? String) ?? url.deletingPathExtension().lastPathComponent
+ }
+
/// The file extensions each kind of plug-in uses.
static let extensions: [Plugin.Category: Set<String>] = [
.audioUnits: ["component"],
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
index 374c853f..504491ce 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
@@ -231,8 +231,9 @@ struct IntelInspectorTests {
measure: { _ in 1 }
)
- #expect(Set(scan.findings.map(\.name)) == ["rastertovendor", "Port.driver", "Device.driver"])
- #expect(scan.findings.allSatisfy { $0.kind == .driver })
+ // A HAL driver sits in a folder of plug-ins too, and is listed as the Plug-ins page lists it.
+ let kinds = Dictionary(uniqueKeysWithValues: scan.findings.map { ($0.name, $0.kind) })
+ #expect(kinds == ["rastertovendor": .driver, "Port.driver": .driver, "Device": .plugin])
}
@Test func findsIntelHelpersInsideAUniversalApp() throws {
@@ -502,6 +503,20 @@ struct IntelInspectorTests {
#expect(!IntelInspector.embeddedDirectories.contains("Contents/Frameworks"))
}
+ @Test func readsThePlugInFoldersItself() async throws {
+ let directory = try TemporaryDirectory()
+ _ = try bundle(directory, "home/Library/Audio/Plug-Ins/VST3/Old.vst3", cpuTypes: [intel])
+ _ = try bundle(directory, "root/Library/Audio/Plug-Ins/Components/New.component", cpuTypes: [intel, appleSilicon])
+
+ let scan = await IntelInspector.scan(
+ installedApps: [], exclusions: .none, environment: environment(in: directory), measure: { _ in 1 }
+ )
+
+ #expect(scan.findings.map(\.name) == ["Old"])
+ #expect(scan.findings.map(\.kind) == [.plugin])
+ #expect(scan.findings.map(\.pluginCategory) == [.vst3])
+ }
+
@Test(.permissionsHold) func namesWhatItCouldNotRead() async throws {
let directory = try TemporaryDirectory()
let closedDrivers = try directory.directory("root/Library/Printers/Closed")
@@ -517,9 +532,11 @@ struct IntelInspectorTests {
let closedProgram = closedApp.appending(path: "Contents/MacOS/Closed")
try directory.setPermissions(0o010, of: groupsFilter)
for program in [tool, agent, closedProgram] { try directory.setPermissions(0o311, of: program) }
- for folder in [closedDrivers, closedLibrary] { try directory.setPermissions(0o000, of: folder) }
- defer { for folder in [closedDrivers, closedLibrary] { try? directory.setPermissions(0o755, of: folder) } }
- let plugInFolder = directory.url.appending(path: "home/Library/Audio/Plug-Ins/VST3/Vendor", directoryHint: .isDirectory)
+ let plugInFolder = try directory.directory("home/Library/Audio/Plug-Ins/VST3/Vendor")
+ _ = try bundle(directory, "home/Library/Audio/Plug-Ins/VST3/Vendor/Old.vst3", cpuTypes: [intel])
+ let closed = [closedDrivers, closedLibrary, plugInFolder]
+ for folder in closed { try directory.setPermissions(0o000, of: folder) }
+ defer { for folder in closed { try? directory.setPermissions(0o755, of: folder) } }
let job = BackgroundItem(
label: "org.example.agent", kind: .agent, source: .userLibrary, plistURL: nil,
program: agent.path(percentEncoded: false), runsAtLoad: false, keepsAlive: false,
@@ -532,7 +549,6 @@ struct IntelInspectorTests {
InstalledApp(url: universal, bundleIdentifier: "org.example.universal", name: "Universal", architectures: [.x86_64, .arm64]),
InstalledApp(url: closedApp, bundleIdentifier: "org.example.closed", name: "Closed", architectures: []),
],
- plugins: PluginScan(unreadable: [plugInFolder]),
backgroundItems: BackgroundItems.Scan(items: [job], unanswered: [.daemon]),
exclusions: .none,
environment: environment(in: directory),
diff --git a/Peel/Model/IntelLibrary.swift b/Peel/Model/IntelLibrary.swift
index ff72b65b..1bc697ce 100644
--- a/Peel/Model/IntelLibrary.swift
+++ b/Peel/Model/IntelLibrary.swift
@@ -8,9 +8,6 @@ final class IntelLibrary {
/// The scan this page runs, which a newer one or the Stop button ends.
let scanRun = ScanRun()
var isScanning: Bool { scanRun.isRunning }
- /// The revision of the apps list the scan was made from. The page scans again when the list changes, so an
- /// app removed since does not stay listed.
- private(set) var scannedRevision: Int?
var selection: IntelFinding.ID?
var selectedFinding: IntelFinding? {
@@ -20,22 +17,17 @@ final class IntelLibrary {
var findings: [IntelFinding] { scan?.findings ?? [] }
/// Scans everything the report covers, so it is complete even when the other pages were never opened.
- /// Plug-ins the Plug-ins page already found are reused, because that scan checks every plug-in's signature
- /// and a Mac used for music can hold hundreds of them.
- func refresh(installedApps: [InstalledApp], revision: Int, plugins known: PluginScan? = nil) async {
+ func refresh(installedApps: [InstalledApp]) async {
guard let result = await scanRun.run({
let exclusions = ExclusionsStore.shared.exclusions
async let backgroundItems = BackgroundItems.scan(exclusions: exclusions)
- let plugins = if let known { known } else { await Plugins.scan(exclusions: exclusions) }
return await IntelInspector.scan(
installedApps: installedApps,
- plugins: plugins,
backgroundItems: backgroundItems,
exclusions: exclusions
)
}) else { return }
scan = result
- scannedRevision = revision
if let selection, !result.findings.contains(where: { $0.id == selection }) {
self.selection = nil
}
diff --git a/Peel/Model/PluginLibrary.swift b/Peel/Model/PluginLibrary.swift
index 5eb2429f..2d019703 100644
--- a/Peel/Model/PluginLibrary.swift
+++ b/Peel/Model/PluginLibrary.swift
@@ -4,11 +4,10 @@ import PeelCore
@Observable
final class PluginLibrary {
- /// What the last scan found, and the folders it couldn't read, which may hold plug-ins it didn't list.
- private(set) var scan: PluginScan?
- var plugins: [Plugin]? { scan?.plugins }
- var unreadable: [URL] { scan?.unreadable ?? [] }
- var needsFullDiskAccess: Bool { scan?.needsFullDiskAccess ?? false }
+ private(set) var plugins: [Plugin]?
+ /// The folders the last scan couldn't read, which may hold plug-ins it didn't list.
+ private(set) var unreadable: [URL] = []
+ private(set) var needsFullDiskAccess = false
/// The scan this page runs, which a newer one or the Stop button ends.
let scanRun = ScanRun()
var isScanning: Bool { scanRun.isRunning }
@@ -22,7 +21,9 @@ final class PluginLibrary {
func refresh() async {
guard let result = await scanRun.run({ await Plugins.scan(exclusions: ExclusionsStore.shared.exclusions) })
else { return }
- scan = result
+ plugins = result.plugins
+ unreadable = result.unreadable
+ needsFullDiskAccess = result.needsFullDiskAccess
if let selection, !result.plugins.contains(where: { $0.id == selection }) {
self.selection = nil
}
diff --git a/Peel/Views/Intel/IntelList.swift b/Peel/Views/Intel/IntelList.swift
index 6109f8e4..8ea50e29 100644
--- a/Peel/Views/Intel/IntelList.swift
+++ b/Peel/Views/Intel/IntelList.swift
@@ -3,7 +3,6 @@ import SwiftUI
struct IntelList: View {
@Environment(IntelLibrary.self) private var intel
- @Environment(PluginLibrary.self) private var plugins
@Environment(AppLibrary.self) private var library
@Environment(HomeModel.self) private var home
@State private var isRescanning = false
@@ -83,12 +82,16 @@ struct IntelList: View {
}
}
}
+ // What the page lists can change from other pages and other apps, and a scan costs little, so it looks again
+ // each time it is shown and each time Peel comes forward.
.task(id: library.revision) {
- guard library.hasLoaded, intel.scannedRevision != library.revision,
- !(intel.scan == nil && intel.scanRun.wasStopped)
- else { return }
+ guard library.hasLoaded, !(intel.scan == nil && intel.scanRun.wasStopped) else { return }
await scan()
}
+ .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
+ guard library.hasLoaded, !(intel.scan == nil && intel.scanRun.wasStopped) else { return }
+ Task { await scan() }
+ }
.rescanOnExclusionChange("IntelList") { await scan() }
}
@@ -100,7 +103,7 @@ struct IntelList: View {
}
private func scan() async {
- await intel.refresh(installedApps: library.apps, revision: library.revision, plugins: plugins.scan)
+ await intel.refresh(installedApps: library.apps)
}
/// What Peel couldn't read for this page: the apps the Applications list couldn't, and what the scan couldn't.