Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Keep Chrome's native messaging folders while Brave is installed
Țugui Dragoș6060d8fcce28
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swiftindex 267fe012..cae80652 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift@@ -192,6 +192,14 @@ public struct LeftoverMatch: Sendable, Hashable {)}+ /// Returns the same match, shared with `apps` as well.+ func sharing(with apps: [String]) -> LeftoverMatch {+ LeftoverMatch(+ reason: reason, confidence: confidence, sharedWith: Set(sharedWith).union(apps).sorted(),+ otherCopies: otherCopies, heldBack: heldBack, isAWord: isAWord+ )+ }+/// Returns the same match, no surer than `ceiling`.func atMost(_ ceiling: MatchConfidence) -> LeftoverMatch {LeftoverMatch(@@ -236,6 +244,13 @@ public struct Leftover: Sendable, Hashable, Identifiable {public var id: URL { url }+ func sharing(with apps: [String]) -> Leftover {+ Leftover(+ url: url, kind: kind, match: match.sharing(with: apps), size: size, isMeasured: isMeasured,+ requiresPrivileges: requiresPrivileges, holdsDamagedSettings: holdsDamagedSettings+ )+ }+/// Returns the same leftover, held back for `reason`: shown, but never selected. A reason that already blocks/// the move stays, since it outranks one that only leaves the item unselected.func heldBack(_ reason: HoldBack) -> Leftover {diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swiftindex 2666915e..88da93af 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift@@ -31,6 +31,12 @@ struct LeftoverMatcher: Sendable {self.registeredApp = registeredApp}+ /// The other installed apps that read `location` too (`SearchLocation.alsoReadBy`). A copy of this app is this app.+ func installedApps(alsoReading location: SearchLocation) -> [String] {+ others.filter { !$0.isACopy(of: target) && location.isAlsoRead(byAppKnownAs: $0.identifier) }+ .map(\.reference).sorted()+ }+/// This app's claim on the item called `fileName` in a location of `kind`, found at `url` when the caller knows it.func match(fileName: String, kind: SearchLocation.Kind, at url: URL? = nil) -> LeftoverMatch? {let key = Self.key(from: fileName, kind: kind)diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swiftindex 127346a8..49a9af6a 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift@@ -127,7 +127,15 @@ public struct LeftoverScanner: Sendable {unreadableLocations.append(location)}}- let leftovers = Self.merged(found)+ // A folder another installed app reads too, or one around it, is that app's as well.+ let alsoRead = environment.locations.filter { !$0.alsoReadBy.isEmpty }+ let leftovers = Self.merged(found).map { leftover in+ let item = PathPattern.comparablePath(of: leftover.url)+ let readers = alsoRead+ .filter { PathComponents.isPath(PathPattern.comparablePath(of: $0.url), atOrInside: item) }+ .flatMap(matcher.installedApps(alsoReading:))+ return readers.isEmpty ? leftover : leftover.sharing(with: readers)+ }let byPath: (SearchLocation, SearchLocation) -> Bool = {$0.url.path(percentEncoded: false) < $1.url.path(percentEncoded: false)diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/SearchLocation.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/SearchLocation.swiftindex d61d1e90..0c6a3249 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/SearchLocation.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/SearchLocation.swift@@ -67,21 +67,33 @@ public struct SearchLocation: Sendable, Hashable {/// At the top of a Library, the names that same Library searches as places of their own, which it never offers/// whole: `Preferences` is looked inside and never moved.let skipped: Set<String>+ /// For a browser's native messaging folder, the apps that read it besides the browser it is named for, each+ /// known by an identifier that is theirs or that theirs continues after a dot.+ let alsoReadBy: [String]public init(kind: Kind, url: URL) {self.init(kind: kind, url: url, skipped: [])}- init(kind: Kind, url: URL, skipped: Set<String>) {+ init(kind: Kind, url: URL, skipped: Set<String> = [], alsoReadBy: [String] = []) {self.kind = kindself.url = urlself.skipped = skipped+ self.alsoReadBy = alsoReadBy}/// True when this location looks at an entry with this name.func considers(fileName: String) -> Bool {kind.considers(fileName: fileName) && !skipped.contains(fileName)}++ func isAlsoRead(byAppKnownAs identifier: String?) -> Bool {+ guard let identifier = identifier?.lowercased() else { return false }+ return alsoReadBy.contains { reader in+ let reader = reader.lowercased()+ return identifier == reader || identifier.hasPrefix(reader + ".")+ }+ }}extension SearchLocation.Kind {@@ -226,8 +238,14 @@ public struct SearchEnvironment: Sendable {}let hosts = [(userLibrary, Self.nativeMessagingHosts.user), (localLibrary, Self.nativeMessagingHosts.local)]locations += hosts.flatMap { library, folders in- folders.map { library.appending(path: $0, directoryHint: .isDirectory) }- }.map { SearchLocation(kind: .nativeMessagingHosts, url: $0) }+ folders.map { folder in+ SearchLocation(+ kind: .nativeMessagingHosts,+ url: library.appending(path: folder.path, directoryHint: .isDirectory),+ alsoReadBy: folder.alsoReadBy+ )+ }+ }locations.append(SearchLocation(kind: .safariWebApps, url: SafariWebApp.containers(inLibrary: userLibrary)))locations.append(SearchLocation(kind: .sharedFolder,@@ -242,13 +260,30 @@ public struct SearchEnvironment: Sendable {return locations}+ /// A folder browsers read native messaging manifests from, with the apps that read it besides its own browser.+ struct NativeMessagingFolder: Sendable, ExpressibleByStringLiteral {+ let path: String+ var alsoReadBy: [String] = []++ init(stringLiteral path: String) {+ self.path = path+ }++ init(_ path: String, alsoReadBy: [String]) {+ self.path = path+ self.alsoReadBy = alsoReadBy+ }+ }+/// Each browser's own documentation: Chrome's and Chromium's "Native messaging", MDN's "Native manifests" for/// Firefox, and Microsoft's "Native messaging" for Edge and its Beta, Dev, and Canary channels. Chrome's other/// channels keep theirs in their own user data folder (Chromium's `docs/user_data_dir.md`), and Chrome for- /// Testing has its own in `/Library` (`chrome/common/chrome_paths.cc`).- static let nativeMessagingHosts = (+ /// Testing has its own in `/Library` (`chrome/common/chrome_paths.cc`). Every build of Brave reads Chrome's two+ /// on the Mac, where other apps leave their manifests (brave-core `app/brave_main_delegate.cc` at+ /// 5e268a047e51ba615c536db3aabbb782eb34550c, and its `app/theme/*/BRANDING` for each build's identifier).+ static let nativeMessagingHosts: (user: [NativeMessagingFolder], local: [NativeMessagingFolder]) = (user: [- "Application Support/Google/Chrome/NativeMessagingHosts",+ NativeMessagingFolder("Application Support/Google/Chrome/NativeMessagingHosts", alsoReadBy: ["com.brave.Browser"]),"Application Support/Google/Chrome Beta/NativeMessagingHosts","Application Support/Google/Chrome Dev/NativeMessagingHosts","Application Support/Google/Chrome Canary/NativeMessagingHosts",@@ -261,7 +296,7 @@ public struct SearchEnvironment: Sendable {"Application Support/Microsoft Edge Canary/NativeMessagingHosts",],local: [- "Google/Chrome/NativeMessagingHosts",+ NativeMessagingFolder("Google/Chrome/NativeMessagingHosts", alsoReadBy: ["com.brave.Browser"]),"Google/ChromeForTesting/NativeMessagingHosts","Application Support/Chromium/NativeMessagingHosts","Application Support/Mozilla/NativeMessagingHosts",diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swiftindex 3b54668e..3a4bc261 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift@@ -84,6 +84,35 @@ struct LeftoverScannerTests {name: "Tunewell")+ /// Brave reads the native messaging manifests other apps leave in Chrome's folders, whichever of its builds it is.+ @Test func chromesFoldersThatBraveReadsAreSharedWithBrave() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Application Support/Google/Chrome/NativeMessagingHosts/org.example.host.json")+ try directory.file("home/Library/Application Support/Google/Chrome/Default/Preferences", bytes: 4096)+ try directory.file("root/Library/Google/Chrome/NativeMessagingHosts/org.example.host.json")+ let chrome = InstalledApp(+ url: URL(filePath: "/Applications/Google Chrome.app"), bundleIdentifier: "com.google.Chrome", name: "Google Chrome",+ bundleName: "Chrome"+ )+ let brave = InstalledApp(+ url: URL(filePath: "/Applications/Brave Browser Beta.app"), bundleIdentifier: "com.brave.Browser.beta",+ name: "Brave Browser Beta"+ )+ let scanner = LeftoverScanner(environment: environment(in: directory))+ func sharing(besides others: [InstalledApp]) async -> [String: [String]] {+ let matcher = LeftoverMatcher(app: chrome, installedApps: [chrome] + others) { _ in nil }+ let leftovers = await scanner.scan(chrome, matcher: matcher).leftovers+ return Dictionary(uniqueKeysWithValues: leftovers.compactMap { leftover in+ let path = leftover.url.path(percentEncoded: false)+ guard path.hasSuffix("Google/Chrome") || path.hasSuffix("Google/Chrome/") else { return nil }+ return (path.contains("/home/") ? "user" : "local", leftover.match.sharedWith)+ })+ }++ #expect(await sharing(besides: [brave]) == ["user": ["com.brave.Browser.beta"], "local": ["com.brave.Browser.beta"]])+ #expect(await sharing(besides: []) == ["user": [], "local": []])+ }+private func environment(in directory: borrowing TemporaryDirectory) -> SearchEnvironment {SearchEnvironment(homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),diff --git a/SAFETY.md b/SAFETY.mdindex 7b295d01..37890f98 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -241,11 +241,13 @@ The first three happen after a move, and only for what really moved:Only matches Peel is `certain` or `likely` about, and only when nothing else installed on the Mac uses them.-- **Shared means left unselected.** Anything another app uses is shown and left unselected, and so is what another- copy of the app uses: one macOS knows anywhere, such as an older copy in Downloads or one on another disk, named- by where it is. An app of the same maker kept outside the Applications folders, such as a Nightly build on another- disk, counts like one inside them, and so does one Peel saw installed before: the files named for a Nightly you- removed are its, not this app's, and Orphaned Files lists them under it.+- **Shared means left unselected.** Anything another app uses is shown and left unselected, and so is what another copy+ of the app uses: one macOS knows anywhere, such as an older copy in Downloads or one on another disk, named by where+ it is. An app of the same maker kept outside the Applications folders, such as a Nightly build on another disk, counts+ like one inside them, and so does one Peel saw installed before: the files named for a Nightly you removed are its,+ not this app's, and Orphaned Files lists them under it. A browser's folder another installed browser reads too is+ shared with it: every build of Brave reads the native messaging manifests other apps, such as a password manager,+ leave in Chrome's folders, so uninstalling Chrome leaves them while Brave is installed.- **A name alone is a guess.** Something matched by the app's name alone inside a folder named for neither the appnor its maker, such as another app's, one of Apple's, or a command-line tool's, is shown and never selected, since afolder of that name may be that program's own; so is something matched by name alone at the top of your home folder