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.

Count the services a framework carries as part of the app

Țugui Dragoș371ceeeca4f6
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
index 84ffa81b..f535b4dd 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
@@ -210,6 +210,13 @@ public enum AppInspector {
}
}
+ if !isWrapped {
+ for bundle in IntelInspector.frameworkProcesses(inside: contents.deletingLastPathComponent()) {
+ let info = infoDictionary(in: bundle.appending(path: "Contents", directoryHint: .isDirectory))
+ if let identifier = info?["CFBundleIdentifier"] as? String { identifiers.append(identifier) }
+ }
+ }
+
let launchServices = contents.appending(path: "Library/LaunchServices", directoryHint: .isDirectory)
if let helpers = try? fileManager.contentsOfDirectory(atPath: launchServices.path(percentEncoded: false)) {
identifiers += helpers.filter { $0.split(separator: ".").count >= 3 }
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
index cd85b147..f94fca12 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
@@ -118,6 +118,25 @@ struct AppInspectorTests {
#expect(!app.isSystemProtected)
}
+ @Test func aServiceAFrameworkCarriesIsTheAppsOnce() throws {
+ let directory = try TemporaryDirectory()
+ try plist(["CFBundleIdentifier": "org.example.carrier"], at: "Carrier.app/Contents/Info.plist", in: directory)
+ let framework = directory.url.appending(path: "Carrier.app/Contents/Frameworks/Updater.framework")
+ try plist(
+ ["CFBundleIdentifier": "org.example.updater.Downloader"],
+ at: "Carrier.app/Contents/Frameworks/Updater.framework/Versions/B/XPCServices/Downloader.xpc/Contents/Info.plist",
+ in: directory
+ )
+ try FileManager.default.createSymbolicLink(at: framework.appending(path: "Versions/Current"), withDestinationURL: URL(filePath: "B"))
+ try FileManager.default.createSymbolicLink(
+ at: framework.appending(path: "XPCServices"), withDestinationURL: URL(filePath: "Versions/Current/XPCServices")
+ )
+
+ let app = try #require(AppInspector.inspect(directory.url.appending(path: "Carrier.app")))
+
+ #expect(app.embeddedBundleIdentifiers == ["org.example.updater.Downloader"])
+ }
+
/// Spotlight does not index the temporary folder, and answers there with the bundle's modification date for when
/// it was last used.
@Test func anAppSpotlightDoesNotIndexHasNoRecordOfBeingOpened() throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift
index 8a31e5fd..019f27bb 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift
@@ -42,6 +42,29 @@ struct RunningCopiesTests {
]) == ["com.google.Chrome", "com.google.Chrome.helper", "com.google.Keystone.Agent", "com.google.Chrome.framework.AlertNotificationService"])
}
+ /// A component many apps carry, such as an updater's downloader, runs from inside each of them, and what runs
+ /// from inside another installed app is that app's.
+ @Test func aComponentRunningFromInsideAnotherInstalledAppIsThatApps() {
+ func app(_ name: String) -> InstalledApp {
+ InstalledApp(
+ url: URL(filePath: "/Applications/\(name).app", directoryHint: .isDirectory),
+ bundleIdentifier: "org.example.\(name.lowercased())", name: name,
+ embeddedBundleIdentifiers: ["org.example.updater.Downloader"]
+ )
+ }
+ let first = app("First"), second = app("Second")
+ let downloader = "Contents/Frameworks/Updater.framework/Versions/B/XPCServices/Downloader.xpc"
+ let running = [
+ process("org.example.updater.Downloader", at: "/Applications/Second.app/\(downloader)", pid: 2),
+ process("org.example.updater.Downloader", at: "/Applications/First.app/\(downloader)", pid: 3),
+ process("org.example.updater.Downloader", at: nil, pid: 4),
+ ]
+
+ let toQuit = RunningCopies.belonging(to: first, among: running, installedApps: [first, second])
+
+ #expect(toQuit.map(\.identifier) == [3, 4])
+ }
+
@MainActor @Test func leavesOutWhatThisAccountCannotQuit() {
let running = RunningCopies.current
let unquittable = running.filter { kill($0.identifier, 0) != 0 && errno == EPERM }