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.

Intel Software finds the app a bundle sits inside

Țugui Dragoș714cd24d16bf
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift
index 10fdd35f..4455c17d 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppCatalog.swift
@@ -1,4 +1,5 @@
public import Foundation
+internal import PeelPrivileged
import Synchronization
public enum AppCatalog {
@@ -28,6 +29,16 @@ public enum AppCatalog {
return apps.first { PathPattern.comparablePath(of: PathPattern.canonical($0.url)) == real }
}
+ /// The app `url` is, or the one it sits inside, such as the app that holds a plug-in. When apps sit inside
+ /// each other, the innermost one.
+ public static func app(holding url: URL, among apps: [InstalledApp]) -> InstalledApp? {
+ let path = PathPattern.comparablePath(of: url)
+ return apps
+ .map { (app: $0, path: PathPattern.comparablePath(of: $0.url)) }
+ .filter { PathComponents.isPath(path, atOrInside: $0.path) }
+ .max { $0.path.count < $1.path.count }?.app
+ }
+
@concurrent
public static func installedApps(in directories: [URL] = defaultDirectories) async -> [InstalledApp] {
let bundles = Set(directories.flatMap { appBundles(in: $0) })
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppCatalogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppCatalogTests.swift
new file mode 100644
index 00000000..84c1c246
--- /dev/null
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppCatalogTests.swift
@@ -0,0 +1,31 @@
+import Foundation
+@testable import PeelCore
+import Testing
+
+struct AppCatalogTests {
+ private func app(_ name: String) -> InstalledApp {
+ InstalledApp(url: URL(filePath: "/Applications/\(name).app", directoryHint: .isDirectory), bundleIdentifier: "org.example.\(name)", name: name)
+ }
+
+ /// A folder's URL ends in a slash, as the catalog reads it, and a plug-in inside the app still belongs to it.
+ @Test func findsTheAppABundleSitsInside() {
+ let apps = [app("Tunewell"), app("Tunewell Extras")]
+ let plugIn = URL(filePath: "/Applications/Tunewell.app/Contents/PlugIns/Bridge.bundle", directoryHint: .isDirectory)
+
+ #expect(AppCatalog.app(holding: plugIn, among: apps)?.name == "Tunewell")
+ #expect(AppCatalog.app(holding: apps[0].url, among: apps)?.name == "Tunewell")
+ #expect(AppCatalog.app(holding: URL(filePath: "/Applications/Tunewell Extras.app/Contents/Info.plist"), among: apps)?.name == "Tunewell Extras")
+ #expect(AppCatalog.app(holding: URL(filePath: "/Applications/Tunewell.application/x"), among: apps) == nil)
+ }
+
+ @Test func answersTheInnermostAppWhenAppsSitInsideEachOther() {
+ let helper = InstalledApp(
+ url: URL(filePath: "/Applications/Tunewell.app/Contents/Helpers/Agent.app", directoryHint: .isDirectory),
+ bundleIdentifier: "org.example.Tunewell.Agent", name: "Agent"
+ )
+ let apps = [app("Tunewell"), helper]
+
+ #expect(AppCatalog.app(holding: helper.url.appending(path: "Contents/MacOS/Agent"), among: apps)?.name == "Agent")
+ #expect(AppCatalog.app(holding: URL(filePath: "/Applications/Tunewell.app/Contents/MacOS/Tunewell"), among: apps)?.name == "Tunewell")
+ }
+}
diff --git a/Peel/Views/Intel/IntelDetailView.swift b/Peel/Views/Intel/IntelDetailView.swift
index 26d24d53..a4192846 100644
--- a/Peel/Views/Intel/IntelDetailView.swift
+++ b/Peel/Views/Intel/IntelDetailView.swift
@@ -7,7 +7,7 @@ struct IntelDetailView: View {
let finding: IntelFinding
private var app: InstalledApp? {
- library.apps.first { $0.url == finding.url || finding.url.path(percentEncoded: false).hasPrefix($0.url.path(percentEncoded: false) + "/") }
+ AppCatalog.app(holding: finding.url, among: library.apps)
}
var body: some View {