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
Background Items says when only a name ties a job to an app
Țugui Dragoșa46e73ff1a4f
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 79d9e58e..45c30d63 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -58692,6 +58692,112 @@}}},+ "Named like %@" : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Název připomíná aplikaci %@"+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Benannt wie %@"+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nombre parecido a %@"+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nom semblable à %@"+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nome simile a %@"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@に似た名前"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "‘%@’과(와) 비슷한 이름"+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Naam lijkt op %@"+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nazwą przypomina: %@"+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nome parecido com %@"+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nume asemănător cu %@"+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Имя похоже на «%@»"+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Namnet pekar på %@"+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ gibi adlandırılmış"+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Назва як у «%@»"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "名称类似%@"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "名稱類似「%@」"+ }+ }+ }+ },"Navigation" : {"localizations" : {"cs" : {@@ -72116,6 +72222,112 @@}}},+ "Only its name points to this app." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Na tuto aplikaci odkazuje jen název úlohy."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nur sein Name weist auf diese App hin."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Solo el nombre de la tarea apunta a esta app."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Seul son nom renvoie à cette app."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Solo il suo nome rimanda a questa app."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "名前だけがこのアプリを示しています。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "작업 이름만 이 앱을 가리킵니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Alleen de naam wijst op deze app."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Na tę aplikację wskazuje tylko jego nazwa."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Só o nome aponta para este app."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Doar numele său indică această aplicație."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "На это приложение указывает только его имя."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Bara namnet pekar på den här appen."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Yalnızca adı bu uygulamaya işaret ediyor."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "На цю програму вказує лише його назва."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "只有它的名称指向此App。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "只有名稱指向此App。"+ }+ }+ }+ },"Open %@" : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swiftindex fc19e001..db2bf8e4 100644--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItem.swift@@ -39,6 +39,8 @@ public struct BackgroundItem: Sendable, Hashable, Identifiable {public let isOrphan: Boolpublic let state: Statepublic let isDisabled: Bool+ /// False when only a name points to the owner (`BackgroundItemOwnership.Owner.isConfirmed`).+ public var isOwnerConfirmed = true/// Includes the file's path, because two files can declare one label (a per-user copy beside the/// system-wide one), and each file needs a row of its own.diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swiftindex 4205cf7f..4033a52a 100644--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift@@ -1,4 +1,5 @@import Foundation+import PeelPrivileged/// Finds the app a launchd job belongs to. Every clue is tried before a job is called orphaned, because/// one key that does not match is not enough reason to remove a job that an app may still need.@@ -7,6 +8,9 @@ public struct BackgroundItemOwnership: Sendable {public let bundleIdentifier: Stringpublic let name: String?public let isInstalled: Bool+ /// True when macOS registered the job for the app, or its program is signed by the app's team or sits+ /// inside the app. False when only a name points to the app: a label, or a bundle anyone can make.+ public var isConfirmed = true}private let apps: [InstalledApp]@@ -46,10 +50,12 @@ public struct BackgroundItemOwnership: Sendable {return Owner(bundleIdentifier: app.bundleIdentifier, name: app.name, isInstalled: true)}if let identifier = Self.bundleIdentifier(inProgramPath: program) {- return owner(forIdentifier: identifier)+ var owner = owner(forIdentifier: identifier)+ owner.isConfirmed = byIdentifier[identifier.lowercased()].map { proves(program, $0, team: team) } ?? false+ return owner}if let app = appMatching(label: label) {- return Owner(bundleIdentifier: app.bundleIdentifier, name: app.name, isInstalled: true)+ return Owner(bundleIdentifier: app.bundleIdentifier, name: app.name, isInstalled: true, isConfirmed: proves(program, app, team: team))}if let team, let candidates = byTeam[team], candidates.count == 1 {return Owner(bundleIdentifier: candidates[0].bundleIdentifier, name: candidates[0].name, isInstalled: true)@@ -57,7 +63,7 @@ public struct BackgroundItemOwnership: Sendable {// No installed app claims the job. An app the plist names that is gone is still returned, so the user// can see which app it was. That app is not installed, so it keeps nothing from being called orphaned.let gone = associated.first { byIdentifier[$0.lowercased()] == nil && AppInspector.applicationURL(forBundleIdentifier: $0) == nil }- return gone.map { Owner(bundleIdentifier: $0, name: nil, isInstalled: false) }+ return gone.map { Owner(bundleIdentifier: $0, name: nil, isInstalled: false, isConfirmed: false) }}/// Whether a job is orphaned: no installed app claims it, and its program is gone from disk or it names@@ -98,6 +104,13 @@ public struct BackgroundItemOwnership: Sendable {)}+ /// Whether `program` is `app`'s own: signed by its team, or inside its bundle.+ private func proves(_ program: String?, _ app: InstalledApp, team: String?) -> Bool {+ if let team, team == app.teamIdentifier { return true }+ guard let program else { return false }+ return PathComponents.isPath(PathPattern.comparablePath(of: URL(filePath: program)), inside: PathPattern.comparablePath(of: app.url))+ }+/// Returns the installed app whose bundle identifier is the label, or else the longest one the label/// starts with. Labels usually begin with the app's bundle identifier, as in `com.example.app.updater`.private func appMatching(label: String) -> InstalledApp? {diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swiftindex 4d9f02e4..d6898384 100644--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItems.swift@@ -94,7 +94,8 @@ public enum BackgroundItems {isOwnerInstalled: true,isOrphan: false,state: .notLoaded,- isDisabled: true+ isDisabled: true,+ isOwnerConfirmed: owner.isConfirmed)}}@@ -163,7 +164,8 @@ public enum BackgroundItems {isOwnerInstalled: owner?.isInstalled ?? false,isOrphan: ownership.isOrphan(label: job.label, program: job.program, owner: owner),state: loaded.state(of: job.label, kind),- isDisabled: loaded.override(of: job.label, kind) ?? job.isDisabled+ isDisabled: loaded.override(of: job.label, kind) ?? job.isDisabled,+ isOwnerConfirmed: owner?.isConfirmed ?? false))}}@@ -221,7 +223,8 @@ public enum BackgroundItems {isOwnerInstalled: owner?.isInstalled ?? false,isOrphan: ownership.isOrphan(label: candidate.label, program: program, owner: owner),state: loaded.state(of: candidate.label, candidate.kind),- isDisabled: loaded.override(of: candidate.label, candidate.kind) ?? false+ isDisabled: loaded.override(of: candidate.label, candidate.kind) ?? false,+ isOwnerConfirmed: owner?.isConfirmed ?? false)}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swiftindex 1f0d5284..fbb43f83 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/BackgroundItemOwnershipTests.swift@@ -67,6 +67,38 @@ struct BackgroundItemOwnershipTests {#expect(owner?.bundleIdentifier == "com.other.tool")}+ /// A label, or the bundle a program sits in, is a name anyone can give, so it proves an app's job only when the+ /// program is signed by that app's team or sits inside that very app. Otherwise the owner is a name alone, and+ /// the page says so.+ @Test func saysHowSureItIsOfAnOwner() throws {+ let directory = try TemporaryDirectory()+ let installed = try directory.directory("Applications/Example.app")+ try directory.file("Applications/Example.app/Contents/Info.plist", contents: PropertyListSerialization.data(+ fromPropertyList: ["CFBundleIdentifier": "com.example.app"], format: .xml, options: 0))+ try directory.file("tmp/Fake.app/Contents/Info.plist", contents: PropertyListSerialization.data(+ fromPropertyList: ["CFBundleIdentifier": "com.example.app"], format: .xml, options: 0))+ let ownership = BackgroundItemOwnership(+ installedApps: [InstalledApp(url: installed, bundleIdentifier: "com.example.app", name: "Example", teamIdentifier: "ABCDE12345"), app("com.other.tool", "Tool")],+ teamOfProgram: { Self.teams[$0] }+ )+ func owner(_ label: String, registeredBy: String? = nil, associated: [String] = [], program: String?) -> BackgroundItemOwnership.Owner? {+ ownership.owner(label: label, registeredBy: registeredBy, associated: associated, program: program)+ }++ #expect(owner("org.unrelated.label", registeredBy: "com.other.tool", program: nil)?.isConfirmed == true)+ #expect(owner("org.unrelated.label", associated: ["com.example.app"], program: "/usr/local/bin/example-helper")?.isConfirmed == true)+ #expect(owner("com.example.app.updater", program: "/usr/local/bin/example-helper")?.isConfirmed == true)+ #expect(owner("org.unrelated.label", program: installed.appending(path: "Contents/MacOS/helper").path(percentEncoded: false))?.isConfirmed == true)++ let impostor = try #require(owner("com.example.app.updater", program: "/usr/local/bin/impostor"))+ #expect(impostor.bundleIdentifier == "com.example.app")+ #expect(!impostor.isConfirmed)+ #expect(owner("com.other.tool.helper", program: nil)?.isConfirmed == false)+ let planted = try #require(owner("org.unrelated.label", program: directory.url.appending(path: "tmp/Fake.app/Contents/MacOS/x").path(percentEncoded: false)))+ #expect(planted.bundleIdentifier == "com.example.app")+ #expect(!planted.isConfirmed)+ }+@Test func fallsBackToTheLabelWhenNothingElseMatches() {let owner = ownership.owner(label: "com.other.tool.helper", associated: [], program: nil)#expect(owner?.bundleIdentifier == "com.other.tool")diff --git a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swiftindex 8f3c13c9..cf65924a 100644--- a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift+++ b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift@@ -35,6 +35,10 @@ struct BackgroundItemDetailView: View {Text("No longer installed").font(.caption).foregroundStyle(.secondary)+ } else if !item.isOwnerConfirmed {+ Text("Only its name points to this app.")+ .font(.caption)+ .foregroundStyle(.secondary)}}}diff --git a/Peel/Views/BackgroundItems/BackgroundItemList.swift b/Peel/Views/BackgroundItems/BackgroundItemList.swiftindex 1086658b..c8ab6781 100644--- a/Peel/Views/BackgroundItems/BackgroundItemList.swift+++ b/Peel/Views/BackgroundItems/BackgroundItemList.swift@@ -133,10 +133,16 @@ private struct BackgroundItemRow: View {.foregroundStyle(.orange).lineLimit(1)} else if let ownerName {- Text(ownerName)- .font(.caption)- .foregroundStyle(.secondary)- .lineLimit(1)+ Group {+ if item.isOwnerConfirmed {+ Text(ownerName)+ } else {+ Text("Named like \(ownerName)")+ }+ }+ .font(.caption)+ .foregroundStyle(.secondary)+ .lineLimit(1)}}}