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.

List and uninstall an app whose Info.plist names no identifier

Țugui Dragoș3e04e5a4e779
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index 4bebf23f..b00c5202 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -14,7 +14,9 @@ struct AppsCommand: AsyncParsableCommand {
if output.json {
try Output.json(apps.map(AppRecord.init))
} else {
- Output.table([["NAME", "VERSION", "IDENTIFIER", "PATH"]] + apps.map { [$0.name, $0.version ?? "", $0.bundleIdentifier, Output.path($0.url)] })
+ Output.table([["NAME", "VERSION", "IDENTIFIER", "PATH"]] + apps.map {
+ [$0.name, $0.version ?? "", $0.bundleIdentifier ?? "", Output.path($0.url)]
+ })
}
if let note = Output.unreadableNote(for: catalog) { Output.note(note) }
}
@@ -374,7 +376,8 @@ struct UninstallCommand: AsyncParsableCommand {
private static func whileRunning(_ target: InstalledApp, among apps: [InstalledApp]) async -> CommandFailure? {
let running = await RunningCopies.belonging(to: target, among: RunningCopies.current, installedApps: apps)
guard !running.isEmpty else { return nil }
- let identifiers = Set(running.map(\.bundleIdentifier)).sorted().map(Output.plain)
+ let identifiers = Set(running.compactMap { $0.bundleIdentifier ?? $0.bundleURL.map(Output.path) })
+ .sorted().map(Output.plain)
return CommandFailure("Quit \(Output.plain(target.name)) first. Still running: \(identifiers.joined(separator: ", ")).")
}
@@ -465,7 +468,7 @@ struct UninstallCommand: AsyncParsableCommand {
/// Throws when Peel never resets the privacy permissions of `target`. Called for `--reset-privacy` before
/// anything is listed: skipping the reset quietly would remove the app and leave its permissions on record.
static func refuseIfPrivacyCannotBeReset(_ target: InstalledApp) throws {
- guard !PrivacyReset.isAllowed(bundleIdentifier: target.bundleIdentifier) else { return }
+ guard !PrivacyReset.isAllowed(for: target) else { return }
throw CommandFailure("Peel never resets privacy permissions for \(Output.plain(target.name)). Leave out --reset-privacy to remove it anyway.")
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift
index ddec760e..1ff5dfc4 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/ExclusionCommands.swift
@@ -21,10 +21,10 @@ struct ExclusionsCommand: AsyncParsableCommand {
private static let unreadable = "Peel couldn't read its exclusions file, so it won't change it. Open Peel and click Start Over in Settings > Exclusions."
- /// Returns the bundle identifier of `app`, found by path, bundle identifier, or name, as the other commands do.
- static func identifier(of app: String, among apps: [InstalledApp]? = nil) async throws -> String {
+ /// Returns the app `query` names, found by path, bundle identifier, or name, as the other commands do.
+ static func app(_ query: String, among apps: [InstalledApp]? = nil) async throws -> InstalledApp {
let installed = if let apps { apps } else { await AppCatalog.installedApps() }
- return try AppLookup.app(matching: app, in: installed).bundleIdentifier
+ return try AppLookup.app(matching: query, in: installed)
}
/// Changes the saved list with `transform`, read again and written under the file's lock, so what the app or
@@ -104,12 +104,14 @@ struct ExclusionsCommand: AsyncParsableCommand {
func run(in store: ExclusionStore, among apps: [InstalledApp]? = nil) async throws {
_ = try await ExclusionsCommand.current(in: store)
// The app is looked up before the list is changed, since looking it up can take a while.
+ // An app with no identifier is left alone by where it is.
var identifier: String?
+ var added = paths.map(URL.init(argument:))
if let app {
- identifier = try await ExclusionsCommand.identifier(of: app, among: apps)
+ let found = try await ExclusionsCommand.app(app, among: apps)
+ if let found = found.bundleIdentifier { identifier = found } else { added.append(found.url) }
}
- let added = paths.map(URL.init(argument:))
- try await ExclusionsCommand.change(in: store) { [identifier] exclusions in
+ try await ExclusionsCommand.change(in: store) { [identifier, added] exclusions in
exclusions.add(added)
if let identifier { exclusions.bundleIdentifiers.insert(identifier) }
}
@@ -138,22 +140,26 @@ struct ExclusionsCommand: AsyncParsableCommand {
func run(in store: ExclusionStore, among apps: [InstalledApp]? = nil) async throws {
let before = try await ExclusionsCommand.current(in: store)
- let removed = paths.map(URL.init(argument:))
+ var removed = paths.map(URL.init(argument:))
// `app` comes off exactly as written, so an app that isn't installed can still come off the list. Only
// when the list has no such identifier is `app` looked up among the installed apps.
var identifiers: Set<String> = []
if let app {
if before.bundleIdentifiers.contains(app) {
identifiers.insert(app)
- } else if let identifier = try? await ExclusionsCommand.identifier(of: app, among: apps) {
- identifiers.insert(identifier)
+ } else if let found = try? await ExclusionsCommand.app(app, among: apps) {
+ if let identifier = found.bundleIdentifier {
+ identifiers.insert(identifier)
+ } else {
+ removed.append(found.url)
+ }
}
}
var remaining = before
guard remaining.remove(removed) || !before.bundleIdentifiers.isDisjoint(with: identifiers) else {
throw CommandFailure("Peel wasn't leaving that alone. See `peel exclusions list`.")
}
- try await ExclusionsCommand.change(in: store) { [identifiers] exclusions in
+ try await ExclusionsCommand.change(in: store) { [identifiers, removed] exclusions in
exclusions.remove(removed)
exclusions.bundleIdentifiers.subtract(identifiers)
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index eaa811f7..676dbcdb 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -70,7 +70,7 @@ struct OrphansCommand: AsyncParsableCommand {
// The same signals the app uses (the apps Peel remembers and the apps running), so both judge these
// files alike. The memory of apps is only read here, never written.
let remembered = await AppMemory().load()
- let running = Set(await RunningCopies.current.map(\.bundleIdentifier))
+ let running = Set(await RunningCopies.current.compactMap(\.bundleIdentifier))
let exclusions = await UnreadableExclusions.load()
let scanner = OrphanScanner(exclusions: exclusions)
let scan = await ProgressLine.counting {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
index f544ee86..220a97c5 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
@@ -53,7 +53,7 @@ enum AppLookup {
}
// Two bundles can share an identifier: a copy in `~/Applications` beside one in `/Applications`, or a
// beta beside the release. Taking the first match would remove whichever sorted first, so this throws.
- let byIdentifier = apps.filter { $0.bundleIdentifier.caseInsensitiveCompare(query) == .orderedSame }
+ let byIdentifier = apps.filter { $0.bundleIdentifier?.caseInsensitiveCompare(query) == .orderedSame }
switch byIdentifier.count {
case 0: break
case 1: return byIdentifier[0]
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Records.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Records.swift
index 2eb41223..db5968aa 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Records.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Records.swift
@@ -3,7 +3,7 @@ import PeelCore
struct AppRecord: Encodable {
let name: String
- let bundleIdentifier: String
+ let bundleIdentifier: String?
let version: String?
let path: String
let isFromAppStore: Bool
@@ -24,8 +24,8 @@ struct AppRecord: Encodable {
case isFromAppStore
}
- /// Encodes a missing version as `null`. The synthesized encoding would leave the key out, and a script needs
- /// every record to have the same keys.
+ /// Encodes a missing identifier or version as `null`. The synthesized encoding would leave the key out, and a
+ /// script needs every record to have the same keys.
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(name, forKey: .name)
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
index b840fd6e..fd88d371 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift
@@ -66,11 +66,8 @@ public enum AppInspector {
public static func inspect(_ url: URL) -> InstalledApp? {
let layout = AppBundleLayout(of: url)
let contents = layout.infoFolder
- guard
- let info = infoDictionary(in: contents),
- let bundleIdentifier = info["CFBundleIdentifier"] as? String,
- !bundleIdentifier.isEmpty
- else { return nil }
+ guard let info = infoDictionary(in: contents) else { return nil }
+ let bundleIdentifier = info["CFBundleIdentifier"] as? String
let signing = signingInformation(for: layout.signedBundle)
let executable = (info["CFBundleExecutable"] as? String).map { layout.executableFolder.appending(path: $0) }
@@ -106,7 +103,7 @@ public enum AppInspector {
isFromAppStore: isFromAppStore,
isSystemProtected: isSystemProtected
),
- webApp: WebApp.of(identifier: bundleIdentifier, info: info)
+ webApp: bundleIdentifier.flatMap { WebApp.of(identifier: $0, info: info) }
)
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppListFilter.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppListFilter.swift
index 26f83851..630cee36 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppListFilter.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppListFilter.swift
@@ -32,7 +32,8 @@ public struct AppListFilter: Sendable, Hashable {
public func keeps(
_ app: InstalledApp, source: AppSource, developer appsDeveloper: String?, isUnused: Bool
) -> Bool {
- if !text.isEmpty, !SearchText.matches(app.name, text), !SearchText.matches(app.bundleIdentifier, text),
+ if !text.isEmpty, !SearchText.matches(app.name, text),
+ !(app.bundleIdentifier.map { SearchText.matches($0, text) } ?? false),
!(appsDeveloper.map { SearchText.matches($0, text) } ?? false) {
return false
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppMemory.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppMemory.swift
index 2a3ee61f..a03b3782 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppMemory.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppMemory.swift
@@ -64,9 +64,10 @@ public struct AppMemory: Sendable {
(known ?? []).map { ($0.bundleIdentifier, $0) },
uniquingKeysWith: { first, _ in first }
)
- for app in apps where !app.bundleIdentifier.isEmpty && !app.isSystemProtected {
- byIdentifier[app.bundleIdentifier] = RememberedApp(
- bundleIdentifier: app.bundleIdentifier,
+ for app in apps where !app.isSystemProtected {
+ guard let identifier = app.bundleIdentifier else { continue }
+ byIdentifier[identifier] = RememberedApp(
+ bundleIdentifier: identifier,
name: app.name,
teamIdentifier: app.teamIdentifier,
lastSeen: now,
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swift b/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swift
index 24e52954..ea1b4175 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swift
@@ -3,7 +3,8 @@ internal import PeelPrivileged
public struct InstalledApp: Sendable, Hashable, Identifiable {
public let url: URL
- public let bundleIdentifier: String
+ /// Nil for an app whose Info.plist names none, which macOS still opens.
+ public let bundleIdentifier: String?
public let name: String
public let bundleName: String?
public let version: String?
@@ -45,7 +46,7 @@ public struct InstalledApp: Sendable, Hashable, Identifiable {
public init(
url: URL,
- bundleIdentifier: String,
+ bundleIdentifier: String?,
name: String,
bundleName: String? = nil,
version: String? = nil,
@@ -65,7 +66,7 @@ public struct InstalledApp: Sendable, Hashable, Identifiable {
webApp: WebApp? = nil
) {
self.url = url
- self.bundleIdentifier = bundleIdentifier
+ self.bundleIdentifier = bundleIdentifier.flatMap { $0.isEmpty ? nil : $0 }
self.name = name
self.bundleName = bundleName
self.version = version
@@ -84,12 +85,25 @@ public struct InstalledApp: Sendable, Hashable, Identifiable {
self.webApp = webApp
self.updateFeed = updateFeed
let path = PathPattern.comparablePath(of: url)
- isPeelItself = Self.isPeel(bundleIdentifier, at: path)
+ isPeelItself = Self.isPeel(self.bundleIdentifier, at: path)
isTheRunningCopy = path == Self.runningBundle
}
public var id: URL { url }
+ /// The apps that have an identifier, grouped by it.
+ public static func byIdentifier(_ apps: [InstalledApp]) -> [String: [InstalledApp]] {
+ Dictionary(grouping: apps.compactMap { app in app.bundleIdentifier.map { ($0, app) } }, by: \.0)
+ .mapValues { $0.map(\.1) }
+ }
+
+ /// How Peel names the app where it records whose a file is (`LeftoverMatch.sharedWith`): its identifier, or else
+ /// where it is.
+ public var reference: String { bundleIdentifier ?? PathPattern.comparablePath(of: url) }
+
+ /// Whether Apple made the app, as its identifier says. An app with no identifier is somebody else's.
+ var isApples: Bool { bundleIdentifier.map(ProtectedData.isApplesName) ?? false }
+
/// Whether this is a web app Safari made (`SafariWebApp`), whose identifier names it and nothing of Apple's.
public var isASafariWebApp: Bool { webApp == .safari }
@@ -99,7 +113,7 @@ public struct InstalledApp: Sendable, Hashable, Identifiable {
/// suffix", and Setapp installs apps in an `Applications/Setapp` folder, the system's or the user's.
public var isFromSetapp: Bool {
let folder = url.deletingLastPathComponent()
- return bundleIdentifier.lowercased().hasSuffix("-setapp")
+ return bundleIdentifier?.lowercased().hasSuffix("-setapp") == true
|| (folder.lastPathComponent == "Setapp" && folder.deletingLastPathComponent().lastPathComponent == "Applications")
}
@@ -131,10 +145,11 @@ public struct InstalledApp: Sendable, Hashable, Identifiable {
private static let runningBundle = PathPattern.comparablePath(of: Bundle.main.bundleURL)
- private static func isPeel(_ bundleIdentifier: String, at path: String) -> Bool {
+ private static func isPeel(_ bundleIdentifier: String?, at path: String) -> Bool {
let own = HelperIdentity.appIdentifier.lowercased()
- let identifier = bundleIdentifier.lowercased()
- if identifier == own || identifier.hasPrefix(own + ".") { return true }
+ if let identifier = bundleIdentifier?.lowercased(), identifier == own || identifier.hasPrefix(own + ".") {
+ return true
+ }
return PathComponents.isPath(runningBundle, inside: path)
}
@@ -166,10 +181,12 @@ public struct InstalledApp: Sendable, Hashable, Identifiable {
/// developer its signature names (`BraveSoftware` for "Brave Software, Inc.").
var ownFolderNames: Set<String> {
var folders = Set(matchingNames.filter(Naming.isSignificant).map(Naming.normalized))
- folders.insert(Naming.normalized(bundleIdentifier))
- if let vendor = Identifier.vendor(of: bundleIdentifier.lowercased()) {
- folders.insert(Naming.normalized(vendor))
- folders.insert(Naming.normalized(String(vendor.split(separator: ".").last ?? "")))
+ if let bundleIdentifier {
+ folders.insert(Naming.normalized(bundleIdentifier))
+ if let vendor = Identifier.vendor(of: bundleIdentifier.lowercased()) {
+ folders.insert(Naming.normalized(vendor))
+ folders.insert(Naming.normalized(String(vendor.split(separator: ".").last ?? "")))
+ }
}
let words = (developer ?? "").split { !$0.isLetter && !$0.isNumber }.map { $0.lowercased() }
for end in words.indices { folders.insert(words[...end].joined()) }
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/Inventory.swift b/Packages/PeelCore/Sources/PeelCore/Apps/Inventory.swift
index 73a1476f..93f6e14c 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/Inventory.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/Inventory.swift
@@ -4,7 +4,7 @@ public import Foundation
/// elsewhere, to set up a new Mac the same way or to keep a record of what was on this one.
public struct InventoryEntry: Sendable, Hashable, Codable {
public let name: String
- public let bundleIdentifier: String
+ public let bundleIdentifier: String?
public let version: String?
public let build: String?
/// Where the app came from: "Homebrew", "App Store", "Setapp", "Sparkle", "Electron", "Downloaded", or "Unknown".
@@ -134,7 +134,7 @@ public struct Inventory: Sendable {
let rows = entries.map { entry in
[
entry.name,
- entry.bundleIdentifier,
+ entry.bundleIdentifier ?? "",
entry.version ?? "",
entry.build ?? "",
entry.source,
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/RunningCopies.swift b/Packages/PeelCore/Sources/PeelCore/Apps/RunningCopies.swift
index afbb4fa3..b848324f 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/RunningCopies.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/RunningCopies.swift
@@ -6,10 +6,10 @@ internal import PeelPrivileged
public enum RunningCopies {
public struct Process: Sendable, Hashable {
public let identifier: pid_t
- public let bundleIdentifier: String
+ public let bundleIdentifier: String?
public let bundleURL: URL?
- public init(identifier: pid_t, bundleIdentifier: String, bundleURL: URL?) {
+ public init(identifier: pid_t, bundleIdentifier: String?, bundleURL: URL?) {
self.identifier = identifier
self.bundleIdentifier = bundleIdentifier
self.bundleURL = bundleURL
@@ -19,9 +19,12 @@ public enum RunningCopies {
@MainActor
public static var current: [Process] {
NSWorkspace.shared.runningApplications.compactMap { running in
- running.bundleIdentifier.map {
- Process(identifier: running.processIdentifier, bundleIdentifier: $0, bundleURL: running.bundleURL)
- }
+ guard running.bundleIdentifier != nil || running.bundleURL != nil else { return nil }
+ return Process(
+ identifier: running.processIdentifier,
+ bundleIdentifier: running.bundleIdentifier,
+ bundleURL: running.bundleURL
+ )
}
}
@@ -42,18 +45,18 @@ public enum RunningCopies {
environment: SearchEnvironment = .current
) -> [Process] {
let bundle = PathPattern.comparablePath(of: app.url)
- let identifier = app.bundleIdentifier.lowercased()
+ let identifier = app.bundleIdentifier?.lowercased()
let embedded = Set(app.embeddedBundleIdentifiers.map { $0.lowercased() })
let others = installedApps
.filter { PathPattern.comparablePath(of: $0.url) != bundle }
- .filter { $0.bundleIdentifier.lowercased() != identifier }
- .map { $0.bundleIdentifier.lowercased() }
+ .compactMap { $0.bundleIdentifier?.lowercased() }
+ .filter { $0 != identifier }
return running.filter { process in
let place = process.bundleURL.map(PathPattern.comparablePath)
- if let place, PathComponents.isPath(place, inside: bundle) { return true }
- let name = process.bundleIdentifier.lowercased()
- if name == identifier { return sharingItsSettings || place == nil || place == bundle }
+ if let place, PathComponents.isPath(place, atOrInside: bundle) { return true }
+ guard let identifier, let name = process.bundleIdentifier?.lowercased() else { return false }
+ if name == identifier { return sharingItsSettings || place == nil }
guard embedded.contains(name) || name.hasPrefix(identifier + ".") else { return false }
if let place, environment.keepsOnItsOwn(appAt: place) { return false }
// Leaves out what another installed app owns: its own identifier, or one that extends an identifier
diff --git a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift
index 42ec91b4..2f861b0d 100644
--- a/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift
+++ b/Packages/PeelCore/Sources/PeelCore/BackgroundItems/BackgroundItemOwnership.swift
@@ -5,7 +5,7 @@ import PeelPrivileged
/// one key that does not match is not enough reason to remove a job that an app may still need.
public struct BackgroundItemOwnership: Sendable {
public struct Owner: Sendable, Hashable {
- public let bundleIdentifier: String
+ public let bundleIdentifier: String?
public let name: String?
/// Where the app is, or nil when it is gone.
public let url: URL?
@@ -30,7 +30,7 @@ public struct BackgroundItemOwnership: Sendable {
self.teamOfProgram = teamOfProgram
apps = installedApps
byIdentifier = Dictionary(
- installedApps.map { ($0.bundleIdentifier.lowercased(), $0) },
+ installedApps.compactMap { app in app.bundleIdentifier.map { ($0.lowercased(), app) } },
uniquingKeysWith: { first, _ in first }
)
byTeam = Dictionary(grouping: installedApps.compactMap { app in app.teamIdentifier.map { ($0, app) } }, by: \.0)
@@ -138,9 +138,9 @@ public struct BackgroundItemOwnership: Sendable {
private func appMatching(label: String) -> InstalledApp? {
let lowercased = label.lowercased()
if let exact = byIdentifier[lowercased] { return exact }
- return apps
- .filter { lowercased.hasPrefix($0.bundleIdentifier.lowercased() + ".") }
- .max { $0.bundleIdentifier.count < $1.bundleIdentifier.count }
+ return byIdentifier
+ .filter { lowercased.hasPrefix($0.key + ".") }
+ .max { $0.key.count < $1.key.count }?.value
}
static func bundleIdentifier(inProgramPath path: String?) -> String? {
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index 3e27584c..827030e8 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -1170,7 +1170,8 @@ public enum DeveloperCaches {
let codeCache = chromium + "content/browser/storage_partition_impl.cc#L1587-L1595"
let exists = { (url: URL) in FileManager.default.fileExists(atPath: url.path(percentEncoded: false)) }
return apps.compactMap { app in
- guard let name = app.bundleName, !name.isEmpty, !name.contains("/"), !covered.contains(name.lowercased()),
+ guard let identifier = app.bundleIdentifier, let name = app.bundleName, !name.isEmpty, !name.contains("/"),
+ !covered.contains(name.lowercased()),
exists(app.url.appending(path: "Contents/Frameworks/Electron Framework.framework"))
else { return nil }
let data = "Library/Application Support/\(name)"
@@ -1184,8 +1185,8 @@ public enum DeveloperCaches {
Folder("\(data)/\($0)", .cache, source: electron + "electron_browser_client.cc#L1206-L1222")
}
return Definition(
- id: "electron.\(app.bundleIdentifier)", name: app.name, systemImage: "macwindow",
- appBundleIdentifiers: [app.bundleIdentifier], folders: folders
+ id: "electron.\(identifier)", name: app.name, systemImage: "macwindow",
+ appBundleIdentifiers: [identifier], folders: folders
)
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/CaskEvidence.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/CaskEvidence.swift
index 5d24d221..cc62cf08 100644
--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/CaskEvidence.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/CaskEvidence.swift
@@ -104,20 +104,20 @@ public struct CaskEvidence: Sendable, Hashable {
/// identifier, or list the app's installer receipt while it is on the Mac (`HomebrewPackage.noting(receipts:)`).
static func proves(_ cask: HomebrewPackage, isThe app: InstalledApp) -> Bool {
guard cask.kind == .cask else { return false }
- let identifier = app.bundleIdentifier.lowercased()
+ let identifier = app.bundleIdentifier?.lowercased()
let quits = cask.quitIdentifiers.map { $0.lowercased() }
// A bundle's file name is whatever its maker called it, and two real casks install a `Caffeine.app`.
// So the name counts unless the cask quits identifiers and every one of them is some other maker's.
let bundleName = app.url.lastPathComponent
if cask.appNames.contains(where: { $0.caseInsensitiveCompare(bundleName) == .orderedSame }) {
- let maker = Identifier.vendor(of: identifier)
+ let maker = identifier.flatMap(Identifier.vendor(of:))
if quits.isEmpty || quits.contains(where: { maker != nil && Identifier.vendor(of: $0) == maker }) {
return true
}
}
- guard !identifier.isEmpty else { return false }
+ guard let identifier else { return false }
if quits.contains(identifier) { return true }
return cask.receiptsOnThisMac.contains { PackageReceipts.proves($0, isThe: identifier) }
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
index 2d139b7d..2666915e 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
@@ -42,10 +42,10 @@ struct LeftoverMatcher: Sendable {
var sharedWith: Set<String> = []
var otherCopies: [URL] = []
func share(with other: Profile) {
- if other.identifier == target.identifier {
+ if other.isACopy(of: target) {
otherCopies.append(other.url)
} else {
- sharedWith.insert(other.bundleIdentifier)
+ sharedWith.insert(other.reference)
}
}
// An app inside the item goes with it, such as an agent or an update an app keeps in its own folder.
@@ -95,8 +95,9 @@ struct LeftoverMatcher: Sendable {
/// count as a rival for `com.google.Chrome.canary`. macOS is asked about each prefix of `key` with more
/// components than the app's identifier. An app found inside this bundle is the app's own helper, not a rival.
private func appsElsewhere(answeringTo key: String) -> [String] {
+ guard let identifier = target.identifier else { return [] }
let parts = key.split(separator: ".", omittingEmptySubsequences: false)
- let own = target.bundleIdentifier.split(separator: ".").count
+ let own = identifier.split(separator: ".").count
guard parts.count > own else { return [] }
return ((own + 1)...parts.count).compactMap { length in
let identifier = parts.prefix(length).joined(separator: ".")
@@ -125,8 +126,8 @@ struct LeftoverMatcher: Sendable {
let candidate = Candidate(Self.key(from: fileName, kind: kind))
let claiming = others.filter { $0.evidence(for: candidate) != nil }
return (
- claiming.filter { $0.identifier != target.identifier }.map(\.bundleIdentifier).sorted(),
- claiming.filter { $0.identifier == target.identifier }.map(\.url)
+ claiming.filter { !$0.isACopy(of: target) }.map(\.reference).sorted(),
+ claiming.filter { $0.isACopy(of: target) }.map(\.url)
)
}
@@ -288,8 +289,8 @@ extension LeftoverMatcher {
let url: URL
/// Where the bundle is, spelled to be compared (`PathPattern.comparablePath`).
let path: String
- let bundleIdentifier: String
- let identifier: String
+ let reference: String
+ let identifier: String?
let embeddedIdentifiers: [EmbeddedIdentifier]
let prefixes: [String]
let applicationGroups: Set<String>
@@ -304,16 +305,16 @@ extension LeftoverMatcher {
init(_ app: InstalledApp) {
url = app.url
path = PathPattern.comparablePath(of: app.url)
- bundleIdentifier = app.bundleIdentifier
- identifier = app.bundleIdentifier.lowercased()
- let vendor = Identifier.vendor(of: identifier)
+ reference = app.reference
+ identifier = app.bundleIdentifier?.lowercased()
+ let vendor = identifier.flatMap(Identifier.vendor(of:))
embeddedIdentifiers = app.embeddedBundleIdentifiers.map {
EmbeddedIdentifier(
value: $0.lowercased(),
sharesVendor: vendor != nil && Identifier.vendor(of: $0) == vendor
)
}
- prefixes = ([identifier] + embeddedIdentifiers.map(\.value))
+ prefixes = ([identifier].compactMap(\.self) + embeddedIdentifiers.map(\.value))
.filter { Identifier.componentCount(of: $0) >= 3 }
.map { $0 + "." }
applicationGroups = Set(app.applicationGroups.map { $0.lowercased() })
@@ -326,6 +327,11 @@ extension LeftoverMatcher {
isASafariWebApp = app.isASafariWebApp
}
+ /// Whether this is another copy of `other`: the same app, known by its identifier, somewhere else.
+ func isACopy(of other: Profile) -> Bool {
+ identifier != nil && identifier == other.identifier
+ }
+
func isSibling(of other: Profile) -> Bool {
if let vendorPrefix, vendorPrefix == other.vendorPrefix { return true }
if let teamPrefix, teamPrefix == other.teamPrefix { return true }
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
index bd35d302..127346a8 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
@@ -64,13 +64,14 @@ public struct LeftoverScanner: Sendable {
/// Spotlight names the maker's apps and Launch Services says where each is installed, so a copy inside a backup
/// never counts.
private func appsElsewhere(like app: InstalledApp, besides known: [InstalledApp]) async -> [InstalledApp] {
- let own = app.bundleIdentifier.lowercased()
- let makers = await AppInspector.indexedIdentifiers(beginningWith: Self.makersPrefixes(of: app.bundleIdentifier))
- let identifiers = [app.bundleIdentifier] + makers.filter { $0.lowercased() != own }.sorted()
+ guard let identifier = app.bundleIdentifier else { return [] }
+ let own = identifier.lowercased()
+ let makers = await AppInspector.indexedIdentifiers(beginningWith: Self.makersPrefixes(of: identifier))
+ let identifiers = [identifier] + makers.filter { $0.lowercased() != own }.sorted()
let wanted = Set(identifiers.map { $0.lowercased() })
let bundle = PathPattern.comparablePath(of: PathPattern.canonical(app.url))
let listed = Set(
- known.filter { wanted.contains($0.bundleIdentifier.lowercased()) }
+ known.filter { $0.bundleIdentifier.map { wanted.contains($0.lowercased()) } ?? false }
.map { PathPattern.comparablePath(of: PathPattern.canonical($0.url)) }
)
return identifiers.flatMap(AppInspector.applicationURLs).filter { url in
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
index ddab783b..7a9ab0f2 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
@@ -56,7 +56,7 @@ public struct OrphanScanner: Sendable {
) async -> OrphanScan {
let systemApps = if let systemApps { systemApps } else { await AppCatalog.systemApps.value }
let (installedApps, gone) = Self.split(remembered, installedApps: installedApps)
- let here = Set(installedApps.map { $0.bundleIdentifier.lowercased() })
+ let here = Set(installedApps.compactMap { $0.bundleIdentifier?.lowercased() })
let goneApps = gone.map { $0.bundleIdentifier.lowercased() }
let ownership = AppOwnership(
installedApps: installedApps + systemApps, goneApps: goneApps, isRegisteredApp: isRegisteredApp
@@ -141,10 +141,10 @@ public struct OrphanScanner: Sendable {
static func split(
_ remembered: [RememberedApp], installedApps: [InstalledApp]
) -> (installed: [InstalledApp], gone: [RememberedApp]) {
- let listed = Set(installedApps.map { $0.bundleIdentifier.lowercased() })
+ let listed = Set(installedApps.compactMap { $0.bundleIdentifier?.lowercased() })
let unlisted = remembered.filter { !listed.contains($0.bundleIdentifier.lowercased()) }
let outOfSight = unlisted.compactMap { $0.stillInstalled() }
- let here = listed.union(outOfSight.map { $0.bundleIdentifier.lowercased() })
+ let here = listed.union(outOfSight.compactMap { $0.bundleIdentifier?.lowercased() })
return (installedApps + outOfSight, unlisted.filter { !here.contains($0.bundleIdentifier.lowercased()) })
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift b/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift
index 8fffe5e3..7196d7ac 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/AppReset.swift
@@ -137,7 +137,7 @@ public struct AppReset: Sendable {
app,
installedApps: installedApps
)
- let keepsAppData = dataIsNeverOffered.contains(app.bundleIdentifier)
+ let keepsAppData = app.bundleIdentifier.map(dataIsNeverOffered.contains) ?? false
// A container held back because of the documents or a wallet's keys inside it is still looked into: a reset
// never touches `Documents`, never offers a folder that holds keys, and the settings beside them are what a
// reset is for.
@@ -206,7 +206,8 @@ public struct AppReset: Sendable {
guard preferences.isRealFolder else { return items }
// Only the file named after the app, or after the container when it is a helper's: that is the file
// `defaults` reads. A name that merely starts the same (`com.foo.AppOther`) belongs to another app.
- let names = Set([app.bundleIdentifier, container.lastPathComponent].map { $0.lowercased() + ".plist" })
+ let names = Set(([app.bundleIdentifier] + [container.lastPathComponent]).compactMap { $0?.lowercased() })
+ .map { $0 + ".plist" }
let contents = (try? FileManager.default.contentsOfDirectory(
at: preferences,
includingPropertiesForKeys: [.isSymbolicLinkKey]
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift
index 08dc70be..4edca106 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift
@@ -8,10 +8,10 @@ public struct BulkUninstallation: Sendable {
public let size: Int64
public let kind: SearchLocation.Kind?
public let requiresPrivileges: Bool
- /// The bundle identifiers of the chosen apps this item belongs to.
+ /// The chosen apps this item belongs to, by `InstalledApp.reference`.
public let apps: [String]
public let match: LeftoverMatch?
- /// The bundle identifiers of apps outside the selection that also claim this item.
+ /// The apps outside the selection that also claim this item, by `InstalledApp.reference`.
public let sharedWithOthers: [String]
/// Other copies of a chosen app, not chosen themselves, that use this item too.
public var otherCopies: [URL] = []
@@ -116,7 +116,7 @@ public struct BulkUninstallation: Sendable {
/// includes what it shares with another chosen app: it goes on using it.
public func suggestedSelection(canUseHelper: Bool) -> Set<URL> {
let staying = Set(
- uninstallations.filter { $0.appStays(canUseHelper: canUseHelper) }.map(\.app.bundleIdentifier)
+ uninstallations.filter { $0.appStays(canUseHelper: canUseHelper) }.map(\.app.reference)
)
return Set(items.filter { item in
item.isRecommended && (canUseHelper || !item.requiresPrivileges)
@@ -136,18 +136,18 @@ public struct BulkUninstallation: Sendable {
}.map(\.url))
}
- /// The files of the app with `identifier`: its leftovers, and what it shares with another chosen app. Two copies
- /// of an app share these, and each has a bundle of its own.
- public func files(of identifier: String) -> Set<URL> {
- Set(items.filter { !$0.isApplication && $0.apps.contains(identifier) }.map(\.url))
+ /// The files of the app `reference` names (`InstalledApp.reference`): its leftovers, and what it shares with
+ /// another chosen app. Two copies of an app share these, and each has a bundle of its own.
+ public func files(of reference: String) -> Set<URL> {
+ Set(items.filter { !$0.isApplication && $0.apps.contains(reference) }.map(\.url))
}
- /// The bundle identifiers of the chosen apps that stay: each one with a copy whose bundle is not selected. That
+ /// The chosen apps that stay, by `InstalledApp.reference`: each one with a copy whose bundle is not selected. That
/// includes an app that cannot go (`Uninstallation.appStays(canUseHelper:)`), since its bundle never is, and
/// leaves out a copy already in the Trash, which stays nowhere.
public func staying(selected: Set<URL>) -> Set<String> {
Set(
- uninstallations.filter { !$0.isAppInTheTrash && !selected.contains($0.app.url) }.map(\.app.bundleIdentifier)
+ uninstallations.filter { !$0.isAppInTheTrash && !selected.contains($0.app.url) }.map(\.app.reference)
)
}
@@ -164,14 +164,14 @@ public struct BulkUninstallation: Sendable {
let order = removalOrder(of: selection)
let apps = Set(items.filter(\.isApplication).map(\.url))
let owners = Dictionary(items.map { ($0.url, $0.apps) }, uniquingKeysWith: { first, _ in first })
- let identifiers = Dictionary(
- uninstallations.map { ($0.app.url, $0.app.bundleIdentifier) },
+ let references = Dictionary(
+ uninstallations.map { ($0.app.url, $0.app.reference) },
uniquingKeysWith: { first, _ in first }
)
return await service.trash(
apps: order.filter(apps.contains),
thenFiles: { stayed in
- let kept = Set(stayed.compactMap { identifiers[$0] })
+ let kept = Set(stayed.compactMap { references[$0] })
return order.filter { !apps.contains($0) && !(owners[$0] ?? []).contains(where: kept.contains) }
},
usingHelperFor: privilegedURLs,
@@ -185,24 +185,24 @@ public struct BulkUninstallation: Sendable {
let failed = Set(result.failures.map(\.url))
return apps.filter { app in
selection.contains(app.url) && failed.contains(app.url)
- && !files(of: app.bundleIdentifier).isDisjoint(with: selection)
+ && !files(of: app.reference).isDisjoint(with: selection)
}
}
/// The chosen apps `urls` belong to: an app whose bundle is among them, and an app with a file of its own among
- /// them. A file names the app by its identifier, which another copy of it shares, so only a bundle names a copy.
+ /// them. A file names the app by its reference, which another copy of it shares, so only a bundle names a copy.
public func apps(owning urls: some Sequence<URL>) -> [InstalledApp] {
let paths = Set(urls.map(PathPattern.comparablePath))
let owners = Set(items.filter { paths.contains(PathPattern.comparablePath(of: $0.url)) }.flatMap(\.apps))
- let copied = Set(Dictionary(grouping: apps, by: \.bundleIdentifier).filter { $0.value.count > 1 }.keys)
+ let copied = Set(Dictionary(grouping: apps, by: \.reference).filter { $0.value.count > 1 }.keys)
return apps.filter { app in
paths.contains(PathPattern.comparablePath(of: app.url))
- || (owners.contains(app.bundleIdentifier) && !copied.contains(app.bundleIdentifier))
+ || (owners.contains(app.reference) && !copied.contains(app.reference))
}
}
static func merge(_ uninstallations: [Uninstallation]) -> [Item] {
- let chosen = Set(uninstallations.map(\.app.bundleIdentifier))
+ let chosen = Set(uninstallations.map(\.app.reference))
let chosenBundles = Set(uninstallations.map { PathPattern.comparablePath(of: $0.app.url) })
var byURL: [URL: Item] = [:]
var order: [URL] = []
@@ -235,14 +235,14 @@ public struct BulkUninstallation: Sendable {
}
for uninstallation in uninstallations {
- let identifier = uninstallation.app.bundleIdentifier
+ let reference = uninstallation.app.reference
for leftover in uninstallation.scan.leftovers {
add(Item(
url: leftover.url,
size: leftover.size,
kind: leftover.kind,
requiresPrivileges: leftover.requiresPrivileges,
- apps: [identifier],
+ apps: [reference],
match: leftover.match,
sharedWithOthers: leftover.match.sharedWith.filter { !chosen.contains($0) },
otherCopies: leftover.match.otherCopies.filter {
@@ -261,7 +261,7 @@ public struct BulkUninstallation: Sendable {
size: uninstallation.appSize,
kind: nil,
requiresPrivileges: uninstallation.appRequiresPrivileges,
- apps: [identifier],
+ apps: [reference],
match: nil,
sharedWithOthers: [],
isExcluded: uninstallation.isExcluded,
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/MakersFolders.swift b/Packages/PeelCore/Sources/PeelCore/Removal/MakersFolders.swift
index 1935db2e..2b4f63a1 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/MakersFolders.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/MakersFolders.swift
@@ -14,7 +14,7 @@ struct MakersFolders {
/// The folder names of each app and its maker (`InstalledApp.ownFolderNames`). Never Apple's.
static func names(of apps: [InstalledApp]) -> Set<String> {
- Set(apps.filter { !ProtectedData.isApplesName($0.bundleIdentifier) }.flatMap(\.ownFolderNames))
+ Set(apps.filter { !$0.isApples }.flatMap(\.ownFolderNames))
}
/// Deepest first. A folder with another name stops the walk, since it may be any app's.
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/MakersUninstaller.swift b/Packages/PeelCore/Sources/PeelCore/Removal/MakersUninstaller.swift
index 9ce07520..df0f9cd0 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/MakersUninstaller.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/MakersUninstaller.swift
@@ -64,8 +64,7 @@ public struct MakersUninstaller: Sendable, Hashable {
/// the maker documents them. An identifier alone is what a bundle says of itself, and would let any app keep Peel
/// away from it.
static func of(_ app: InstalledApp) -> MakersUninstaller? {
- guard let team = app.teamIdentifier else { return nil }
- let identifier = app.bundleIdentifier.lowercased()
+ guard let team = app.teamIdentifier, let identifier = app.bundleIdentifier?.lowercased() else { return nil }
guard let product = known.first(where: { product in
product.team == team && product.identifiers.contains { identifier == $0 || identifier.hasPrefix($0 + ".") }
}), let instructions = URL(string: product.page) else { return nil }
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/PreferenceBackup.swift b/Packages/PeelCore/Sources/PeelCore/Removal/PreferenceBackup.swift
index fa0cb4fb..e1514be0 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/PreferenceBackup.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/PreferenceBackup.swift
@@ -47,7 +47,8 @@ public enum PreferenceBackup {
run: Run
) async -> Saved {
let domains = PreferenceCleanup.domains(for: urls, ownedBy: app.bundleIdentifier)
- return await save(domains, of: app.bundleIdentifier, in: directory, through: service, run: run)
+ guard let identifier = app.bundleIdentifier else { return domains.isEmpty ? .nothingToSave : .failed }
+ return await save(domains, of: identifier, in: directory, through: service, run: run)
}
/// Exports every one of `candidates` that exists into a new folder in `directory`, named for `bundleIdentifier`.
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/PrivacyReset.swift b/Packages/PeelCore/Sources/PeelCore/Removal/PrivacyReset.swift
index f229c64a..ce4b0543 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/PrivacyReset.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/PrivacyReset.swift
@@ -43,7 +43,11 @@ public enum PrivacyReset {
) async -> [(app: InstalledApp, result: Result)] {
var results: [(app: InstalledApp, result: Result)] = []
for app in goingNow(apps, with: service) {
- results.append((app, await reset(bundleIdentifier: app.bundleIdentifier)))
+ guard let identifier = app.bundleIdentifier else {
+ results.append((app, .refused))
+ continue
+ }
+ results.append((app, await reset(bundleIdentifier: identifier)))
}
return results
}
@@ -70,7 +74,7 @@ public enum PrivacyReset {
/// Returns the apps a removal resets: those whose own bundle is selected and that `isAllowed` accepts. An app
/// whose leftovers alone are removed stays installed, and nobody asked to reset it.
public static func apps(among apps: [InstalledApp], moving selected: Set<URL>) -> [InstalledApp] {
- apps.filter { selected.contains($0.url) && isAllowed(bundleIdentifier: $0.bundleIdentifier) }
+ apps.filter { selected.contains($0.url) && isAllowed(for: $0) }
}
/// Interprets `tccutil`'s exit status and output. Kept apart from running it so it can be tested.
@@ -80,6 +84,11 @@ public enum PrivacyReset {
return .failed(output)
}
+ /// True when `app` has an identifier that may be handed to `tccutil`.
+ public static func isAllowed(for app: InstalledApp) -> Bool {
+ app.bundleIdentifier.map(isAllowed(bundleIdentifier:)) ?? false
+ }
+
/// True when `bundleIdentifier` may be handed to `tccutil`. Apple's own apps and every part of Peel are
/// refused, and any other identifier must read as exactly one app's (`Identifier.isValid`). This matters
/// because `tccutil reset All` with no identifier resets every app.
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/UninstallSelection.swift b/Packages/PeelCore/Sources/PeelCore/Removal/UninstallSelection.swift
index 78271dcc..ad99b4b2 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/UninstallSelection.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/UninstallSelection.swift
@@ -17,9 +17,9 @@ public struct UninstallSelection: Sendable {
}
private var kept = KeptSelection()
- /// Whether each app stayed at the last change, by bundle identifier.
+ /// Whether each app stayed at the last change, by `InstalledApp.reference`.
private var stayed: [String: Bool] = [:]
- /// The files each app the person keeps had selected when they kept it, by bundle identifier.
+ /// The files each app the person keeps had selected when they kept it, by `InstalledApp.reference`.
private var setAside: [String: Set<URL>] = [:]
/// What a checkbox can select as of the last update.
public private(set) var selectable: Set<URL> = []
@@ -38,7 +38,7 @@ public struct UninstallSelection: Sendable {
)
return update(
selected,
- apps: [uninstallation.app.bundleIdentifier: app],
+ apps: [uninstallation.app.reference: app],
selectable: uninstallation.selectable(canUseHelper: canUseHelper),
suggested: uninstallation.suggestedSelection(canUseHelper: canUseHelper)
)
@@ -48,13 +48,13 @@ public struct UninstallSelection: Sendable {
let selectable = bulk.selectable(canUseHelper: canUseHelper)
var apps: [String: App] = [:]
for uninstallation in bulk.uninstallations {
- let identifier = uninstallation.app.bundleIdentifier
+ let reference = uninstallation.app.reference
let bundle = uninstallation.app.url
let isKept = kept.hasOffered(bundle) && selectable.contains(bundle) && !selected.contains(bundle)
- var app = apps[identifier] ?? App(stays: false, files: bulk.files(of: identifier), bundles: [])
+ var app = apps[reference] ?? App(stays: false, files: bulk.files(of: reference), bundles: [])
app.stays = app.stays || uninstallation.appStays(canUseHelper: canUseHelper) || isKept
app.bundles.insert(bundle)
- apps[identifier] = app
+ apps[reference] = app
}
return update(
selected,
@@ -74,20 +74,20 @@ public struct UninstallSelection: Sendable {
) -> Set<URL> {
let staying = bulk.staying(selected: selected)
var result = selected
- for identifier in bulk.staying(selected: previous).symmetricDifference(staying) {
- let files = bulk.files(of: identifier)
- if staying.contains(identifier) {
- setAside[identifier] = result.intersection(files)
+ for reference in bulk.staying(selected: previous).symmetricDifference(staying) {
+ let files = bulk.files(of: reference)
+ if staying.contains(reference) {
+ setAside[reference] = result.intersection(files)
result.subtract(files)
} else {
- result.formUnion((setAside.removeValue(forKey: identifier) ?? []).intersection(selectable))
+ result.formUnion((setAside.removeValue(forKey: reference) ?? []).intersection(selectable))
}
- stayed[identifier] = staying.contains(identifier)
+ stayed[reference] = staying.contains(reference)
}
return result
}
- /// `apps` says, for each app by bundle identifier, whether it stays now and what it holds.
+ /// `apps` says, for each app by `InstalledApp.reference`, whether it stays now and what it holds.
private mutating func update(
_ selected: Set<URL>,
apps: [String: App],
@@ -96,11 +96,11 @@ public struct UninstallSelection: Sendable {
) -> Set<URL> {
var suggested = suggested
let isAsMade = selected == kept.made
- for (identifier, app) in apps {
+ for (reference, app) in apps {
if app.stays {
suggested.subtract(app.files)
}
- guard let before = stayed[identifier], before != app.stays else { continue }
+ guard let before = stayed[reference], before != app.stays else { continue }
let holds = app.files.union(app.bundles)
if app.stays || isAsMade {
kept.forget(holds)
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
index 2eb16182..69622c05 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
@@ -106,9 +106,11 @@ public struct Uninstallation: Sendable {
environment: SearchEnvironment,
pkgutil: PackageReceipts.Pkgutil = PackageReceipts.pkgutil
) async -> [Leftover] {
- let identifier = app.bundleIdentifier.lowercased()
- let identifiers = Set(installedApps.map { $0.bundleIdentifier.lowercased() } + [identifier])
- let named = receipts.filter { PackageReceipts.owner(of: $0, among: identifiers) == identifier }
+ let identifier = app.bundleIdentifier?.lowercased()
+ let identifiers = Set((installedApps.map(\.bundleIdentifier) + [identifier]).compactMap { $0?.lowercased() })
+ let named = identifier.map { own in
+ receipts.filter { PackageReceipts.owner(of: $0, among: identifiers) == own }
+ } ?? []
let wroteOnlyTheApp = await PackageReceipts.receipts(writingOnly: app.url, pkgutil: pkgutil)
.filter { !named.contains($0.lowercased()) }
var leftovers: [Leftover] = []
@@ -152,11 +154,11 @@ public struct Uninstallation: Sendable {
!isTheApp(PathPattern.comparablePath(of: other.url))
&& CaskEvidence.installedCask(for: other, in: casks)?.id == cask.id
}
- let sharedWith = Set(otherApps.map(\.bundleIdentifier) + others.map { target in
+ let sharedWith = Set(otherApps.map(\.reference) + others.map { target in
let installed = installedApps.first {
PathPattern.comparablePath(of: $0.url).caseInsensitiveCompare(target) == .orderedSame
}
- return installed?.bundleIdentifier ?? Bundle(url: URL(filePath: target))?.bundleIdentifier ?? target
+ return installed?.reference ?? Bundle(url: URL(filePath: target))?.bundleIdentifier ?? target
})
let home = environment.homeDirectory.path(percentEncoded: false)
let leftover = await LeftoverScanner.leftover(
@@ -319,9 +321,11 @@ public struct Uninstallation: Sendable {
private func isUnreviewedOwn(_ leftover: Leftover) -> Bool {
let match = leftover.match
- let namespace = app.bundleIdentifier.lowercased() + "."
+ let isInItsNamespace = app.bundleIdentifier.map {
+ leftover.url.lastPathComponent.lowercased().hasPrefix($0.lowercased() + ".")
+ } ?? false
return match.sharedWith.isEmpty && match.heldBack == nil && match.confidence >= .likely
- && (match.confidence == .certain || leftover.url.lastPathComponent.lowercased().hasPrefix(namespace))
+ && (match.confidence == .certain || isInItsNamespace)
}
/// How many items could move once selected, and their total size: what a section header shows and the
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
index 70e82320..294db732 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
@@ -200,10 +200,12 @@ public enum SpaceRemoval {
for process in running {
let bundle = process.bundleURL?.deletingPathExtension().lastPathComponent
// Folders on disk carry the bundle's file name. The user sees the app's name as Finder shows it.
- let displayed = process.bundleURL.map(AppInspector.displayName) ?? process.bundleIdentifier
+ guard let displayed = process.bundleURL.map(AppInspector.displayName) ?? process.bundleIdentifier else {
+ continue
+ }
let spellings = [
process.bundleIdentifier,
- process.bundleIdentifier.split(separator: ".").last.map(String.init),
+ process.bundleIdentifier?.split(separator: ".").last.map(String.init),
bundle,
].compactMap(\.self) + (process.bundleURL.map(AppInspector.applicationGroups) ?? [])
for spelling in spellings where Naming.isSignificant(spelling) {
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
index 1306287a..4be3a7ef 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/Exclusions.swift
@@ -216,7 +216,7 @@ public struct Exclusions: Sendable, Codable, Hashable {
}
public func excludes(_ app: InstalledApp) -> Bool {
- excludes(bundleIdentifier: app.bundleIdentifier) || excludes(app.url)
+ app.bundleIdentifier.map(excludes(bundleIdentifier:)) == true || excludes(app.url)
}
/// True when `brew uninstall` would delete something excluded: an app the package installs (`apps` are the
@@ -227,7 +227,7 @@ public struct Exclusions: Sendable, Codable, Hashable {
guard isKnown else { return true }
let targets = package.appTargets.map { URL(filePath: $0, directoryHint: .isDirectory) } + apps.map(\.url)
if targets.contains(where: { excludes($0) || holds($0) }) { return true }
- if apps.contains(where: { excludes(bundleIdentifier: $0.bundleIdentifier) }) { return true }
+ if apps.contains(where: { $0.bundleIdentifier.map(excludes(bundleIdentifier:)) == true }) { return true }
if package.quitIdentifiers.contains(where: { excludes(bundleIdentifier: $0) }) { return true }
guard let prefix else { return false }
let own = prefix
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotesMemory.swift b/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotesMemory.swift
index abb676e1..ee248dae 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotesMemory.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotesMemory.swift
@@ -26,8 +26,10 @@ public struct ReleaseNotesMemory: Sendable, Equatable, Codable {
/// Whether the notes of the update `status` names are to be asked for: only an update that waits for the person,
/// never a version they skipped or an app they told Peel to leave alone.
public func asks(about status: UpdateStatus?, of app: InstalledApp, with preferences: UpdatePreferences) -> Bool {
- guard preferences.isWaiting(status, for: app), let version = status?.version else { return false }
- return asks(app.bundleIdentifier, version: version)
+ guard preferences.isWaiting(status, for: app), let version = status?.version,
+ let identifier = app.bundleIdentifier
+ else { return false }
+ return asks(identifier, version: version)
}
public mutating func record(_ lookup: ReleaseNotesLookup, of identifier: String, version: String) {
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/TeamRegistry.swift b/Packages/PeelCore/Sources/PeelCore/Updates/TeamRegistry.swift
index 745d5f87..71db2ebf 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/TeamRegistry.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/TeamRegistry.swift
@@ -62,8 +62,7 @@ public struct TeamRegistry: Sendable {
var entries = stored
var changes: [Change] = []
- for (identifier, copies) in Dictionary(grouping: apps, by: \.bundleIdentifier)
- .sorted(by: { $0.key < $1.key }) {
+ for (identifier, copies) in InstalledApp.byIdentifier(apps).sorted(by: { $0.key < $1.key }) {
let teams = Set(copies.compactMap(\.teamIdentifier).filter { !$0.isEmpty })
guard var entry = entries[identifier] else {
if let first = teams.sorted().first { entries[identifier] = Entry(team: first) }
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift
index b9132947..c0267431 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift
@@ -158,11 +158,13 @@ public struct UpdateChecker: Sendable {
/// Asks the App Store about `app`, but only when the app has an App Store receipt, whoever calls this.
/// Asking about other apps would send Apple, one identifier at a time, the list of installed apps.
private func appStoreAnswer(for app: InstalledApp) async -> UpdateAnswer {
- guard app.isFromAppStore, let installed = app.version else { return UpdateAnswer(status: .unsupported) }
- var reply = await lookup(app.bundleIdentifier, in: country)
+ guard app.isFromAppStore, let installed = app.version, let identifier = app.bundleIdentifier else {
+ return UpdateAnswer(status: .unsupported)
+ }
+ var reply = await lookup(identifier, in: country)
// A two-letter region with no store, such as Antarctica (AQ), is also refused with HTTP 400.
if reply.status == 400, country != "us" {
- reply = await lookup(app.bundleIdentifier, in: "us")
+ reply = await lookup(identifier, in: "us")
}
guard let data = reply.data else { return UpdateAnswer(status: .failed) }
switch AppStoreLookup.answer(in: data) {
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateMemory.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateMemory.swift
index 2b211745..54cce8e1 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateMemory.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateMemory.swift
@@ -48,7 +48,7 @@ public struct UpdateMemory: Codable, Equatable, Sendable {
for apps: [InstalledApp],
now: Date = .now
) -> [String: UpdateMemory] {
- let installed = Dictionary(grouping: apps, by: \.bundleIdentifier)
+ let installed = InstalledApp.byIdentifier(apps)
return memory.filter { identifier, entry in
guard let copies = installed[identifier] else {
return entry.schedule.due.addingTimeInterval(longestAbsence) > now
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdatePreferences.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdatePreferences.swift
index add5d668..1ef60ceb 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdatePreferences.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdatePreferences.swift
@@ -26,14 +26,14 @@ public struct UpdatePreferences: Sendable, Hashable {
}
public func isIgnored(_ app: InstalledApp) -> Bool {
- ignoredIdentifiers.contains(app.bundleIdentifier)
+ app.bundleIdentifier.map(ignoredIdentifiers.contains) ?? false
}
/// Whether `status` is an update worth showing: the app is not ignored and that version was not skipped.
/// The app list, the menu bar count, the notification, and the command line all ask this, so they agree.
public func isWaiting(_ status: UpdateStatus?, for app: InstalledApp) -> Bool {
guard case .updateAvailable(let version, _, _) = status else { return false }
- return !isIgnored(app) && skippedVersions[app.bundleIdentifier] != version
+ return !isIgnored(app) && app.bundleIdentifier.flatMap { skippedVersions[$0] } != version
}
/// The answer an app's page shows. An update the user muted, by skipping that version or by telling Peel never
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
index 745af068..ce4011ab 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppInspectorTests.swift
@@ -233,10 +233,20 @@ struct AppInspectorTests {
#expect(AppInspector.inspect(directory.url.appending(path: "Empty.app"))?.version == "7")
}
- @Test func rejectsFoldersWithoutBundleIdentifier() throws {
+ @Test func readsAnAppWhoseInfoPlistNamesNoIdentifier() throws {
let directory = try TemporaryDirectory()
- try plist(["CFBundleName": "Broken"], at: "Broken.app/Contents/Info.plist", in: directory)
- #expect(AppInspector.inspect(directory.url.appending(path: "Broken.app")) == nil)
+ try plist(["CFBundleName": "Plain Editor", "CFBundleVersion": "4.0"], at: "Plain Editor.app/Contents/Info.plist", in: directory)
+ try plist(["CFBundleIdentifier": ""], at: "Empty.app/Contents/Info.plist", in: directory)
+ try directory.directory("Folder.app/Contents")
+
+ let app = try #require(AppInspector.inspect(directory.url.appending(path: "Plain Editor.app")))
+
+ #expect(app.bundleIdentifier == nil)
+ #expect(app.name == "Plain Editor")
+ #expect(app.version == "4.0")
+ #expect(app.reference == PathPattern.comparablePath(of: directory.url.appending(path: "Plain Editor.app")))
+ #expect(AppInspector.inspect(directory.url.appending(path: "Empty.app"))?.bundleIdentifier == nil)
+ #expect(AppInspector.inspect(directory.url.appending(path: "Folder.app")) == nil)
}
@Test func marksSystemAppsAsProtected() throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift
index d1636d8f..56e02d3c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift
@@ -79,10 +79,10 @@ struct BulkUninstallationTests {
])
#expect(bulk.staying(selected: [notes.url, copy.url, mail.url]).isEmpty)
- #expect(bulk.staying(selected: [notes.url, mail.url]) == [notes.bundleIdentifier])
- #expect(bulk.staying(selected: [notes.url, copy.url]) == [mail.bundleIdentifier])
- #expect(bulk.files(of: notes.bundleIdentifier) == [own.url, shared.url])
- #expect(bulk.files(of: mail.bundleIdentifier) == [shared.url])
+ #expect(bulk.staying(selected: [notes.url, mail.url]) == [notes.reference])
+ #expect(bulk.staying(selected: [notes.url, copy.url]) == [mail.reference])
+ #expect(bulk.files(of: notes.reference) == [own.url, shared.url])
+ #expect(bulk.files(of: mail.reference) == [shared.url])
}
/// Two copies of one app share its files. Choosing one of them among several apps leaves what the other copy
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift
index cf7b0005..9d9ac094 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ExclusionCommandTests.swift
@@ -63,6 +63,21 @@ struct ExclusionCommandTests {
#expect(await saved(store).excludes(editor))
}
+ @Test func addsAndRemovesAnAppWithNoIdentifierByItsPlace() async throws {
+ let directory = try TemporaryDirectory()
+ let store = store(in: directory)
+ let plain = InstalledApp(
+ url: try directory.directory("Applications/Plain Editor.app"), bundleIdentifier: nil, name: "Plain Editor"
+ )
+
+ try await add(["--app", "Plain Editor"], in: store, among: [plain])
+
+ #expect(await saved(store).bundleIdentifiers.isEmpty)
+ #expect(await saved(store).excludes(plain))
+ try await remove(["--app", "Plain Editor"], in: store, among: [plain])
+ #expect(await saved(store).isEmpty)
+ }
+
@Test func refusesAnAppItCannotFind() async throws {
let directory = try TemporaryDirectory()
let store = store(in: directory)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
index d9b58b79..f35dce74 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverMatcherTests.swift
@@ -109,6 +109,19 @@ struct LeftoverMatcherTests {
#expect(updater.isRecommended)
}
+ @Test func appsWithNoIdentifierAreNotCopiesOfEachOther() throws {
+ let editor = InstalledApp(url: URL(filePath: "/Applications/Plain Editor.app"), bundleIdentifier: nil, name: "Plain Editor")
+ let other = InstalledApp(url: URL(filePath: "/Users/me/Applications/Plain Editor.app"), bundleIdentifier: nil, name: "Plain Editor")
+
+ let alone = try #require(match("Plain Editor", in: .applicationSupport, for: editor))
+ let both = try #require(match("Plain Editor", in: .applicationSupport, for: editor, with: [other]))
+
+ #expect(alone.reason == .name)
+ #expect(alone.isRecommended)
+ #expect(both.otherCopies.isEmpty)
+ #expect(both.sharedWith == [other.reference])
+ }
+
/// An app that sits inside the item goes with it, so it keeps none of it: an agent or an update the app keeps in
/// its own support folder does not make that folder shared. The same apps kept anywhere else do.
@Test func anAppInsideTheItemKeepsNoneOfIt() throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesMemoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesMemoryTests.swift
index 83a7adfd..65298032 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesMemoryTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesMemoryTests.swift
@@ -39,9 +39,9 @@ struct ReleaseNotesMemoryTests {
)
let update = UpdateStatus.updateAvailable(version: "2.0")
let memory = ReleaseNotesMemory()
- let skipped = UpdatePreferences(skippedVersions: [app.bundleIdentifier: "2.0"])
- let skippedBefore = UpdatePreferences(skippedVersions: [app.bundleIdentifier: "1.9"])
- let ignored = UpdatePreferences(ignoredIdentifiers: [app.bundleIdentifier])
+ let skipped = UpdatePreferences(skippedVersions: ["org.example.editor": "2.0"])
+ let skippedBefore = UpdatePreferences(skippedVersions: ["org.example.editor": "1.9"])
+ let ignored = UpdatePreferences(ignoredIdentifiers: ["org.example.editor"])
#expect(memory.asks(about: update, of: app, with: UpdatePreferences()))
#expect(!memory.asks(about: update, of: app, with: skipped))
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift
index 94135c90..00a5291f 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHygieneTests.swift
@@ -703,6 +703,14 @@ struct PrivacyResetTests {
#expect(await PrivacyReset.reset(bundleIdentifier: "") == .refused)
}
+ /// `tccutil reset All` with no identifier resets every app, so an app that names none is never reset.
+ @Test func neverResetsAnAppWithNoIdentifier() {
+ let editor = InstalledApp(url: URL(filePath: "/Applications/Plain Editor.app"), bundleIdentifier: nil, name: "Plain Editor")
+
+ #expect(!PrivacyReset.isAllowed(for: editor))
+ #expect(PrivacyReset.apps(among: [editor], moving: [editor.url]).isEmpty)
+ }
+
/// A removal resets only the apps it moves. An app whose leftovers alone are selected stays installed, and
/// the user did not ask to reset it. The same rule applies to one app and to several.
@Test func resetsOnlyTheAppsThatAreThemselvesSelected() {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift
index 45958808..91829cc6 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RunningCopiesTests.swift
@@ -20,7 +20,8 @@ struct RunningCopiesTests {
}
private func belonging(_ running: [RunningCopies.Process]) -> [String] {
- RunningCopies.belonging(to: chrome, among: running, installedApps: [chrome, canary]).map(\.bundleIdentifier)
+ RunningCopies.belonging(to: chrome, among: running, installedApps: [chrome, canary])
+ .compactMap(\.bundleIdentifier)
}
/// What runs from inside the app counts whatever its name begins with. A slash and a combining mark after it
@@ -41,6 +42,17 @@ struct RunningCopiesTests {
]) == ["com.google.Chrome", "com.google.Chrome.helper", "com.google.Keystone.Agent", "com.google.Chrome.framework.AlertNotificationService"])
}
+ @Test func anAppWithNoIdentifierIsKnownByWhereItRuns() {
+ let editor = InstalledApp(url: URL(filePath: "/Applications/Plain Editor.app"), bundleIdentifier: nil, name: "Plain Editor")
+ let running = [
+ RunningCopies.Process(identifier: 1, bundleIdentifier: nil, bundleURL: URL(filePath: "/Applications/Plain Editor.app")),
+ RunningCopies.Process(identifier: 2, bundleIdentifier: nil, bundleURL: URL(filePath: "/Applications/Other.app")),
+ RunningCopies.Process(identifier: 3, bundleIdentifier: "org.example.other", bundleURL: nil),
+ ]
+
+ #expect(RunningCopies.belonging(to: editor, among: running, installedApps: [editor]).map(\.identifier) == [1])
+ }
+
/// Chrome Canary continues Chrome's identifier and is another installed app, not a helper of Chrome's.
@Test func leavesAnotherInstalledAppWhoseNameContinuesThisOne() {
#expect(belonging([
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallSelectionTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallSelectionTests.swift
index c9f036fb..7bec95f7 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallSelectionTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallSelectionTests.swift
@@ -167,7 +167,7 @@ struct UninstallSelectionTests {
let selected = choices.personChanged(from: suggested, to: suggested.subtracting([other.url]), in: bulk)
#expect(selected == [app.url, own.url])
- #expect(bulk.staying(selected: selected) == [other.bundleIdentifier])
+ #expect(bulk.staying(selected: selected) == [other.reference])
}
/// Selecting the bundle again brings back the app's files as they were, and nothing more: a file the person had
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
index 31390598..7b0f6a58 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
@@ -182,11 +182,11 @@ struct UninstallationTests {
#expect(beyond.suggestedSelection(canUseHelper: true).isEmpty, "the helper may not move the app")
let other = InstalledApp(url: URL(filePath: "/Applications/Other.app"), bundleIdentifier: "com.example.other", name: "Other")
- let shared = leftover("shared", sharedWith: [other.bundleIdentifier])
+ let shared = leftover("shared", sharedWith: [other.reference])
let otherPlan = Uninstallation(
app: other, appSize: 10_000, appRequiresPrivileges: false,
scan: LeftoverScan(
- leftovers: [leftover("com.example.other"), leftover("shared", sharedWith: [app.bundleIdentifier])],
+ leftovers: [leftover("com.example.other"), leftover("shared", sharedWith: [app.reference])],
unreadableLocations: []
)
)
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index 73477096..ae9ff09a 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -326,7 +326,8 @@ final class AppLibrary {
/// Restores the update answers saved by earlier runs, for apps still at the build they describe.
private func recall() {
for app in apps {
- guard let remembered = memory[app.bundleIdentifier], remembered.describes(app) else { continue }
+ guard let identifier = app.bundleIdentifier, let remembered = memory[identifier], remembered.describes(app)
+ else { continue }
updateStatuses[app.id] = remembered.status
if let checked = remembered.checked {
lastUpdateChecks[app.id] = checked
@@ -384,7 +385,7 @@ final class AppLibrary {
}
func developer(of app: InstalledApp) -> String? {
- appDevelopers.developer(of: app, remembered: memory[app.bundleIdentifier]?.developer)
+ appDevelopers.developer(of: app, remembered: app.bundleIdentifier.flatMap { memory[$0]?.developer })
}
var developers: [String] {
@@ -502,14 +503,17 @@ final class AppLibrary {
// its own, so even Rescan on an app's page only rescans files.
guard UserDefaults.standard.object(forKey: SettingsKey.checksForAppUpdates) as? Bool ?? true else { return }
let now = Date.now
+ // An app is checked on a schedule kept by its identifier, so an app with none is left to Homebrew's answer.
let wanted = targets.filter { app in
- guard !isIgnored(app), !appsInATrash.contains(app.id) else { return false }
+ guard let identifier = app.bundleIdentifier, !isIgnored(app), !appsInATrash.contains(app.id) else {
+ return false
+ }
guard !force else { return true }
// Already being checked by another round: a second answer could double the wait for the next check.
guard !appsCheckingForUpdates.contains(app.id) else { return false }
// An update whose notes were never asked for is checked once now rather than on its next turn.
let notesWait = releaseNotes.asks(about: updateStatuses[app.id], of: app, with: updatePreferences)
- return memory[app.bundleIdentifier]?.schedule.isDue(at: now) ?? true || notesWait
+ return memory[identifier]?.schedule.isDue(at: now) ?? true || notesWait
}
// The list's own entry, not the caller's: a page that was open through an upgrade still holds the old build.
.map { app in apps.first { $0.id == app.id } ?? app }
@@ -554,7 +558,7 @@ final class AppLibrary {
if status != .failed {
lastUpdateChecks[id] = .now
}
- let identifier = app.bundleIdentifier
+ guard let identifier = app.bundleIdentifier else { continue }
memory[identifier] = UpdateMemory(
status: kept,
schedule: UpdateSchedule.next(after: status, following: memory[identifier]?.schedule),
@@ -582,8 +586,8 @@ final class AppLibrary {
await ask(notesToAsk, checker: checker)
var waiting: [String: String] = [:]
for app in apps {
- if let version = updateStatuses[app.id]?.version {
- waiting[app.bundleIdentifier] = version
+ if let version = updateStatuses[app.id]?.version, let identifier = app.bundleIdentifier {
+ waiting[identifier] = version
}
}
releaseNotes.keep(only: waiting)
@@ -594,7 +598,8 @@ final class AppLibrary {
/// What is new in the update `app` is waiting for, when it is known.
func releaseNotes(of app: InstalledApp) -> ReleaseNotes? {
- updateStatuses[app.id]?.version.flatMap { releaseNotes.notes(of: app.bundleIdentifier, version: $0) }
+ guard let identifier = app.bundleIdentifier else { return nil }
+ return updateStatuses[app.id]?.version.flatMap { releaseNotes.notes(of: identifier, version: $0) }
}
/// An update whose answer did not say what is new in it.
@@ -616,7 +621,9 @@ final class AppLibrary {
askNext()
}
while let (question, lookup) = await group.next() {
- releaseNotes.record(lookup, of: question.app.bundleIdentifier, version: question.version)
+ if let identifier = question.app.bundleIdentifier {
+ releaseNotes.record(lookup, of: identifier, version: question.version)
+ }
askNext()
}
}
@@ -693,22 +700,24 @@ final class AppLibrary {
}
func setIgnored(_ isIgnored: Bool, for app: InstalledApp) {
+ guard let identifier = app.bundleIdentifier else { return }
var identifiers = ignoredIdentifiers
if isIgnored {
- identifiers.insert(app.bundleIdentifier)
+ identifiers.insert(identifier)
} else {
- identifiers.remove(app.bundleIdentifier)
+ identifiers.remove(identifier)
}
ignoredIdentifiers = identifiers
UserDefaults.standard.set(Array(identifiers).sorted(), forKey: SettingsKey.ignoredUpdateApps)
}
func skippedVersion(for app: InstalledApp) -> String? {
- skippedVersions[app.bundleIdentifier]
+ app.bundleIdentifier.flatMap { skippedVersions[$0] }
}
func skip(version: String, for app: InstalledApp) {
- skippedVersions[app.bundleIdentifier] = version
+ guard let identifier = app.bundleIdentifier else { return }
+ skippedVersions[identifier] = version
UserDefaults.standard.set(skippedVersions, forKey: SettingsKey.skippedUpdateVersions)
}
@@ -761,7 +770,7 @@ final class AppLibrary {
updateStatuses = updateStatuses.filter { !outlived.contains($0.key) }
lastUpdateChecks = lastUpdateChecks.filter { !outlived.contains($0.key) }
for app in apps where outlived.contains(app.id) {
- memory[app.bundleIdentifier] = nil
+ if let identifier = app.bundleIdentifier { memory[identifier] = nil }
}
UpdateMemoryStore.save(memory)
}
@@ -799,8 +808,9 @@ final class AppLibrary {
}
func acknowledgeTeamChange(for app: InstalledApp) async {
- teamChanges.removeValue(forKey: app.bundleIdentifier)
- if let problem = await teamRegistry.acknowledge(app.bundleIdentifier) {
+ guard let identifier = app.bundleIdentifier else { return }
+ teamChanges.removeValue(forKey: identifier)
+ if let problem = await teamRegistry.acknowledge(identifier) {
teamRecordProblem = problem
}
}
@@ -852,18 +862,19 @@ final class AppLibrary {
AppCatalog.app(at: url, among: apps)
}
- /// The name of the app with `bundleIdentifier`: the listed app's, or the one Finder shows for an app macOS knows
- /// elsewhere, such as a helper or a Nightly build on another disk. The identifier itself when macOS knows none.
- func name(forBundleIdentifier bundleIdentifier: String) -> String {
+ /// The name of the app `reference` names (`InstalledApp.reference`): the listed app's, or the one Finder shows
+ /// for an app macOS knows elsewhere by that identifier, such as a helper or a Nightly build on another disk. The
+ /// reference itself when macOS knows none.
+ func name(forReference reference: String) -> String {
if lastNames?.revision != revision {
lastNames = (
revision,
- Dictionary(apps.map { ($0.bundleIdentifier, $0.name) }, uniquingKeysWith: { first, _ in first })
+ Dictionary(apps.map { ($0.reference, $0.name) }, uniquingKeysWith: { first, _ in first })
)
}
- if let name = lastNames?.names[bundleIdentifier] { return name }
- let name = AppInspector.knownName(forBundleIdentifier: bundleIdentifier)
- lastNames?.names[bundleIdentifier] = name
+ if let name = lastNames?.names[reference] { return name }
+ let name = AppInspector.knownName(forBundleIdentifier: reference)
+ lastNames?.names[reference] = name
return name
}
}
diff --git a/Peel/Model/BulkRemovalPlan.swift b/Peel/Model/BulkRemovalPlan.swift
index 8d84df10..df7d48d6 100644
--- a/Peel/Model/BulkRemovalPlan.swift
+++ b/Peel/Model/BulkRemovalPlan.swift
@@ -65,7 +65,7 @@ final class BulkRemovalPlan {
var runningProcesses: [NSRunningApplication] {
let running = RunningCopies.current
let owners = Set(items.filter { selectedURLs.contains($0.url) }.flatMap(\.apps))
- return apps.filter { owners.contains($0.bundleIdentifier) }.flatMap { app in
+ return apps.filter { owners.contains($0.reference) }.flatMap { app in
RunningCopies.belonging(to: app, among: running, installedApps: installedApps)
.compactMap { NSRunningApplication(processIdentifier: $0.identifier) }
}
diff --git a/Peel/Model/OrphanLibrary.swift b/Peel/Model/OrphanLibrary.swift
index 3c678e87..b3de4bc7 100644
--- a/Peel/Model/OrphanLibrary.swift
+++ b/Peel/Model/OrphanLibrary.swift
@@ -63,8 +63,9 @@ final class OrphanLibrary {
/// Takes `group` out of the list, as the person said it belongs to `app`. Nothing moves, and the group stays
/// listed when the choice could not be saved.
func give(_ group: OrphanGroup, to app: InstalledApp) {
- guard OrphanOwners().give(group.identifier, to: app.bundleIdentifier), let scan else { return }
- owners[group.identifier.lowercased()] = app.bundleIdentifier
+ guard let identifier = app.bundleIdentifier, OrphanOwners().give(group.identifier, to: identifier), let scan
+ else { return }
+ owners[group.identifier.lowercased()] = identifier
self.scan = scan.without(group.id)
selectedURLs.subtract(group.items.map(\.url))
if selection == group.id { selection = nil }
diff --git a/Peel/Model/ResetPlan.swift b/Peel/Model/ResetPlan.swift
index 3cf83dd6..173b6796 100644
--- a/Peel/Model/ResetPlan.swift
+++ b/Peel/Model/ResetPlan.swift
@@ -61,7 +61,7 @@ final class ResetPlan {
}
var canResetPrivacy: Bool {
- PrivacyReset.isAllowed(bundleIdentifier: app.bundleIdentifier)
+ PrivacyReset.isAllowed(for: app)
}
/// Nothing is, until the scan has said what the reset would take: `performReset()` has nothing to go on before.
@@ -121,18 +121,22 @@ final class ResetPlan {
askedToMove = urls.count
didClearSettings = reset.clearsSettings(moving: result.trashed.map(\.originalURL))
// The app stays installed, so `tccutil` still finds it after the move.
- privacy =
- resetsPrivacy && canResetPrivacy ? await PrivacyReset.reset(bundleIdentifier: app.bundleIdentifier) : nil
+ privacy = nil
+ if resetsPrivacy, canResetPrivacy, let identifier = app.bundleIdentifier {
+ privacy = await PrivacyReset.reset(bundleIdentifier: identifier)
+ }
didReset = true
return result
}
/// Puts the settings saved in `backup` back, unless the app is open, which would write its own over them.
func putSettingsBack(from backup: URL) async -> PreferenceBackup.Restored {
- await QuitGuard.shared.run {
+ // A copy is saved under the app's identifier, so an app with none has no copy to put back.
+ guard let identifier = app.bundleIdentifier else { return .notSaved }
+ return await QuitGuard.shared.run {
await PreferenceBackup.restore(
from: backup,
- of: app.bundleIdentifier,
+ of: identifier,
exclusions: ExclusionsStore.shared.exclusions
) { @MainActor in
self.refreshRunningState()
diff --git a/Peel/Navigation/PeelIntents.swift b/Peel/Navigation/PeelIntents.swift
index 8e6f8157..cc0c2359 100644
--- a/Peel/Navigation/PeelIntents.swift
+++ b/Peel/Navigation/PeelIntents.swift
@@ -98,7 +98,8 @@ struct ShowInPeel: AppIntent {
}
/// An installed app, as Shortcuts and Spotlight offer it: chosen from the apps on the Mac rather than typed by
-/// hand. Its `id` is the bundle identifier, so a Shortcut keeps working after the app moves.
+/// hand. Its `id` is the app's reference: its bundle identifier, so a Shortcut keeps working after the app moves, or
+/// where it is when it has none.
struct InstalledAppEntity: AppEntity {
static let typeDisplayRepresentation = TypeDisplayRepresentation(name: "App")
static let defaultQuery = InstalledAppQuery()
@@ -111,7 +112,7 @@ struct InstalledAppEntity: AppEntity {
}
init(_ app: InstalledApp) {
- id = app.bundleIdentifier
+ id = app.reference
name = app.name
}
}
@@ -119,7 +120,7 @@ struct InstalledAppEntity: AppEntity {
struct InstalledAppQuery: EntityStringQuery {
func entities(for identifiers: [String]) async throws -> [InstalledAppEntity] {
let wanted = Set(identifiers)
- return await AppCatalog.installedApps().filter { wanted.contains($0.bundleIdentifier) }
+ return await AppCatalog.installedApps().filter { wanted.contains($0.reference) }
.map(InstalledAppEntity.init)
}
@@ -127,7 +128,7 @@ struct InstalledAppQuery: EntityStringQuery {
await AppCatalog.installedApps()
.filter { app in
app.names.contains { SearchText.matches($0, string) }
- || SearchText.matches(app.bundleIdentifier, string)
+ || app.bundleIdentifier.map { SearchText.matches($0, string) } == true
}
.map(InstalledAppEntity.init)
}
@@ -156,7 +157,7 @@ struct ShowLeftoversInPeel: AppIntent {
func perform() async throws -> some IntentResult {
// Checked again here, because the app may have been removed after it was chosen. The error lets the
// Shortcut handle that case, instead of opening an empty page.
- guard let installed = await AppCatalog.installedApps().first(where: { $0.bundleIdentifier == app.id }) else {
+ guard let installed = await AppCatalog.installedApps().first(where: { $0.reference == app.id }) else {
throw NoSuchApp(name: app.name)
}
Navigator.shared.requestedApp = installed.url
@@ -165,7 +166,7 @@ struct ShowLeftoversInPeel: AppIntent {
}
}
-/// The error a Shortcut gets when the app it names is not installed. The app is matched by bundle identifier, so
+/// The error a Shortcut gets when the app it names is not installed. The app is matched by its reference, so
/// another app with the same name does not count. `AppIntentError(description:)` needs macOS 27 and Peel runs on
/// macOS 26, so the message is this error's own `localizedStringResource`.
struct NoSuchApp: Error, CustomLocalizedStringResourceConvertible {
diff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swift
index 0c62b449..73944dc2 100644
--- a/Peel/Views/AppDetailView.swift
+++ b/Peel/Views/AppDetailView.swift
@@ -43,7 +43,9 @@ struct AppDetailView: View {
}
.confirmationDialog(Text("Reset privacy permissions for \(plan.app.name)?"), isPresented: $isConfirmingPrivacyReset) {
Button("Reset", role: .destructive) {
- Task { privacyReset = await PrivacyReset.reset(bundleIdentifier: plan.app.bundleIdentifier) }
+ if let identifier = plan.app.bundleIdentifier {
+ Task { privacyReset = await PrivacyReset.reset(bundleIdentifier: identifier) }
+ }
}
Button("Cancel", role: .cancel) {}
} message: {
@@ -132,7 +134,7 @@ struct AppDetailView: View {
.listRowSeparator(.hidden)
}
if case .browser(let identifier) = plan.app.webApp {
- let browser = library.name(forBundleIdentifier: identifier)
+ let browser = library.name(forReference: identifier)
Notice(
title: Text("A web app of \(browser)"),
detail: Text("Moving it to the Trash takes away only this shortcut, and the app stays in \(browser), which can make the shortcut again. To remove the app itself, uninstall it in \(browser), which takes the shortcut away too."),
@@ -140,7 +142,7 @@ struct AppDetailView: View {
) {}
.listRowSeparator(.hidden)
}
- if let change = library.teamChanges[plan.app.bundleIdentifier] {
+ if let change = plan.app.bundleIdentifier.flatMap({ library.teamChanges[$0] }) {
Notice(
title: change.current.isEmpty ? Text("No developer signs this app anymore") : Text("This app is signed by someone else now"),
detail: change.current.isEmpty
@@ -177,7 +179,7 @@ struct AppDetailView: View {
recommendedSection
reviewSection
- if PrivacyReset.isAllowed(bundleIdentifier: plan.app.bundleIdentifier), !plan.isAppInTheTrash {
+ if PrivacyReset.isAllowed(for: plan.app), !plan.isAppInTheTrash {
PrivacyResetRow(isOn: $resetsPrivacy, detail: PrivacyResetRow.beforeTheMove)
}
if plan.hasDockTile, plan.removedElsewhere == nil {
@@ -395,7 +397,7 @@ struct AppDetailView: View {
private func warning(for leftover: Leftover) -> String? {
var lines: [String] = []
if leftover.match.isShared {
- let users = leftover.match.sharedWith.map(library.name(forBundleIdentifier:))
+ let users = leftover.match.sharedWith.map(library.name(forReference:))
+ leftover.match.otherCopies.map(\.abbreviatedPath)
lines.append(String(localized: "Also used by \(users.formatted(.list(type: .and)))"))
}
diff --git a/Peel/Views/AppHeader.swift b/Peel/Views/AppHeader.swift
index 59ce8346..69670f5c 100644
--- a/Peel/Views/AppHeader.swift
+++ b/Peel/Views/AppHeader.swift
@@ -44,13 +44,17 @@ struct AppHeader<Actions: View>: View {
private var identity: some View {
FlowLayout(spacing: 6) {
HStack(spacing: 5) {
- Text(app.bundleIdentifier)
- .lineLimit(1)
- .truncationMode(.middle)
- .textSelection(.enabled)
+ if let identifier = app.bundleIdentifier {
+ Text(identifier)
+ .lineLimit(1)
+ .truncationMode(.middle)
+ .textSelection(.enabled)
+ }
if let version = app.version {
- Text(verbatim: "·")
- .accessibilityHidden(true)
+ if app.bundleIdentifier != nil {
+ Text(verbatim: "·")
+ .accessibilityHidden(true)
+ }
if let waitingVersion {
StatusLabel(
title: Text(verbatim: "\(version) → \(waitingVersion)"),
diff --git a/Peel/Views/AppList.swift b/Peel/Views/AppList.swift
index eb15e16d..be86a787 100644
--- a/Peel/Views/AppList.swift
+++ b/Peel/Views/AppList.swift
@@ -102,7 +102,7 @@ struct AppList: View {
size: library.sizes[app.id],
isUnmeasured: library.unmeasured.contains(app.id),
sharesStorage: library.sharingStorage.contains(app.id),
- teamChange: library.teamChanges[app.bundleIdentifier],
+ teamChange: app.bundleIdentifier.flatMap { library.teamChanges[$0] },
sort: library.sort,
hasUpdate: library.hasUpdate(app),
isPicked: library.picked.contains(app.id),
diff --git a/Peel/Views/AppPageHeader.swift b/Peel/Views/AppPageHeader.swift
index ff6d8075..ba85d493 100644
--- a/Peel/Views/AppPageHeader.swift
+++ b/Peel/Views/AppPageHeader.swift
@@ -112,7 +112,7 @@ struct AppPageHeader: View {
Button("Show in Finder") {
NSWorkspace.shared.activateFileViewerSelecting([plan.app.url])
}
- if PrivacyReset.isAllowed(bundleIdentifier: plan.app.bundleIdentifier), !plan.isAppInTheTrash {
+ if PrivacyReset.isAllowed(for: plan.app), !plan.isAppInTheTrash {
Divider()
Button("Reset Privacy Permissions\u{2026}") { isConfirmingPrivacyReset = true }
.disabled(plan.isExcluded)
diff --git a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
index 1fde02df..1f0347c3 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemDetailView.swift
@@ -34,7 +34,7 @@ struct BackgroundItemDetailView: View {
if let owner = item.ownerBundleIdentifier {
LabeledContent("Added by") {
VStack(alignment: .trailing, spacing: 1) {
- Text(verbatim: item.ownerName ?? library.name(forBundleIdentifier: owner))
+ Text(verbatim: item.ownerName ?? library.name(forReference: owner))
if !item.isOwnerInstalled {
Text("No longer installed")
.font(.caption)
diff --git a/Peel/Views/BackgroundItems/BackgroundItemList.swift b/Peel/Views/BackgroundItems/BackgroundItemList.swift
index 0005bcbf..fdd8936a 100644
--- a/Peel/Views/BackgroundItems/BackgroundItemList.swift
+++ b/Peel/Views/BackgroundItems/BackgroundItemList.swift
@@ -146,7 +146,7 @@ struct BackgroundItemList: View {
/// The owner's name as the item's page gives it: the name found with the owner, which knows an app outside the
/// scanned folders, and else the installed app's.
private func ownerName(of item: BackgroundItem) -> String? {
- item.ownerBundleIdentifier.map { item.ownerName ?? library.name(forBundleIdentifier: $0) }
+ item.ownerBundleIdentifier.map { item.ownerName ?? library.name(forReference: $0) }
}
}
diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swift
index 9d6de520..990dd302 100644
--- a/Peel/Views/MultipleAppsView.swift
+++ b/Peel/Views/MultipleAppsView.swift
@@ -94,8 +94,7 @@ struct MultipleAppsView: View {
}
if plan.apps.contains(where: {
- PrivacyReset.isAllowed(bundleIdentifier: $0.bundleIdentifier)
- && !plan.appsInTheTrash.contains($0.url)
+ PrivacyReset.isAllowed(for: $0) && !plan.appsInTheTrash.contains($0.url)
}) {
PrivacyResetRow(isOn: $resetsPrivacy, detail: PrivacyResetRow.beforeTheMove)
}
@@ -247,7 +246,7 @@ struct MultipleAppsView: View {
/// The names of the apps with these bundle identifiers, as a list.
private func names(of identifiers: [String]) -> String {
- identifiers.map(library.name(forBundleIdentifier:)).formatted(.list(type: .and))
+ identifiers.map(library.name(forReference:)).formatted(.list(type: .and))
}
/// The warning in a row's note, in the same words an app's own page uses: which other apps use the item,
@@ -259,7 +258,7 @@ struct MultipleAppsView: View {
lines.append(String(localized: "Not selected: it stays with \(names(of: keptBy))."))
}
let users =
- item.sharedWithOthers.map(library.name(forBundleIdentifier:)) + item.otherCopies.map(\.abbreviatedPath)
+ item.sharedWithOthers.map(library.name(forReference:)) + item.otherCopies.map(\.abbreviatedPath)
if !users.isEmpty {
lines.append(String(localized: "Also used by \(users.formatted(.list(type: .and)))"))
}
diff --git a/Peel/Views/Orphans/OrphanList.swift b/Peel/Views/Orphans/OrphanList.swift
index accc8786..e1a92136 100644
--- a/Peel/Views/Orphans/OrphanList.swift
+++ b/Peel/Views/Orphans/OrphanList.swift
@@ -20,7 +20,9 @@ struct OrphanList: View {
.contextMenu(forSelectionType: OrphanGroup.ID.self) { ids in
if ids.count == 1, let group = filtered.first(where: { ids.contains($0.id) }) {
Menu("This Belongs To") {
- let apps = library.apps.sorted { $0.name.localizedStandardCompare($1.name) == .orderedAscending }
+ // What a group belongs to is kept by the app's identifier.
+ let apps = library.apps.filter { $0.bundleIdentifier != nil }
+ .sorted { $0.name.localizedStandardCompare($1.name) == .orderedAscending }
ForEach(apps) { app in
Button(app.name) { orphans.give(group, to: app) }
}
diff --git a/Peel/Views/Settings/ExclusionsSettingsView.swift b/Peel/Views/Settings/ExclusionsSettingsView.swift
index b2d852ab..2e7bd2ee 100644
--- a/Peel/Views/Settings/ExclusionsSettingsView.swift
+++ b/Peel/Views/Settings/ExclusionsSettingsView.swift
@@ -120,13 +120,21 @@ struct ExclusionsSettingsView: View {
}
HStack {
Menu {
+ // An app with no identifier is left alone by where it is, as its Control-click menu does.
ForEach(
- library.apps.filter {
- !exclusions.exclusions.excludes(bundleIdentifier: $0.bundleIdentifier)
+ library.apps.filter { app in
+ app.bundleIdentifier.map { !exclusions.exclusions.excludes(bundleIdentifier: $0) }
+ ?? !exclusions.exclusions.excludes(app.url)
}
) { app in
Button(app.name) {
- Task { await exclusions.add(bundleIdentifier: app.bundleIdentifier) }
+ Task {
+ if let identifier = app.bundleIdentifier {
+ await exclusions.add(bundleIdentifier: identifier)
+ } else {
+ await exclusions.add(paths: [app.url])
+ }
+ }
}
}
} label: {
diff --git a/Peel/Views/Settings/SavedSettingsSection.swift b/Peel/Views/Settings/SavedSettingsSection.swift
index 2266ff26..11c63033 100644
--- a/Peel/Views/Settings/SavedSettingsSection.swift
+++ b/Peel/Views/Settings/SavedSettingsSection.swift
@@ -39,15 +39,15 @@ struct SavedSettingsSection: View {
}
.confirmationDialog(putBackQuestion, isPresented: isAskingToPutBack, presenting: copyToPutBack) { copy in
Button("Put Back") {
- Task { await putBack(copy, named: library.name(forBundleIdentifier: copy.bundleIdentifier)) }
+ Task { await putBack(copy, named: library.name(forReference: copy.bundleIdentifier)) }
}
Button("Cancel", role: .cancel) {}
} message: { copy in
- Text("Peel first saves the settings \(library.name(forBundleIdentifier: copy.bundleIdentifier)) has now, as a copy of their own, then puts these in their place.")
+ Text("Peel first saves the settings \(library.name(forReference: copy.bundleIdentifier)) has now, as a copy of their own, then puts these in their place.")
}
.confirmationDialog(trashQuestion, isPresented: isAskingToTrash, presenting: copyToTrash) { copy in
Button("Move to Trash") {
- Task { await moveToTrash(copy, named: library.name(forBundleIdentifier: copy.bundleIdentifier)) }
+ Task { await moveToTrash(copy, named: library.name(forReference: copy.bundleIdentifier)) }
}
Button("Cancel", role: .cancel) {}
}
@@ -59,7 +59,7 @@ struct SavedSettingsSection: View {
}
private func row(for copy: PreferenceBackup.Copy) -> some View {
- let name = library.name(forBundleIdentifier: copy.bundleIdentifier)
+ let name = library.name(forReference: copy.bundleIdentifier)
let isOpen = openApps.contains(copy.bundleIdentifier)
return LabeledContent {
HStack(spacing: 8) {
@@ -165,13 +165,13 @@ struct SavedSettingsSection: View {
private var trashQuestion: Text {
guard let copy = copyToTrash else { return Text(verbatim: "") }
- let name = library.name(forBundleIdentifier: copy.bundleIdentifier)
+ let name = library.name(forReference: copy.bundleIdentifier)
return Text("Move the settings saved for \(name) on \(copy.date, format: .dateTime.day().month().year().hour().minute()) to the Trash?")
}
private var putBackQuestion: Text {
guard let copy = copyToPutBack else { return Text(verbatim: "") }
- let name = library.name(forBundleIdentifier: copy.bundleIdentifier)
+ let name = library.name(forReference: copy.bundleIdentifier)
return Text("Put back the settings saved for \(name) on \(copy.date, format: .dateTime.day().month().year().hour().minute())?")
}