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
Test how the Applications list names each app's developer
Țugui Dragoșd15f088f5b32
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppDevelopers.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppDevelopers.swiftnew file mode 100644index 00000000..197a86d3--- /dev/null+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppDevelopers.swift@@ -0,0 +1,29 @@+import Foundation++/// Who makes each app, as the Applications list names them. The signature names a Developer ID app or one of+/// Apple's. An App Store app, which Apple signs again, takes the name of another installed app of its team, or else+/// the name the App Store gave at the last update check.+public struct AppDevelopers: Sendable {+ private let byTeam: [String: String]++ public init(_ apps: [InstalledApp]) {+ byTeam = Dictionary(+ apps.compactMap { app in app.developer.flatMap { name in app.teamIdentifier.map { ($0, name) } } },+ uniquingKeysWith: { first, _ in first }+ )+ }++ /// `remembered` is what the App Store answered for the app.+ public func developer(of app: InstalledApp, remembered: String?) -> String? {+ app.developer ?? app.teamIdentifier.flatMap { byTeam[$0] } ?? remembered+ }++ /// The developers with two or more apps among `names`, one per app, for the list's filter, and `chosen` even when+ /// none of its apps remain, since it is what empties the list. A developer with one app is left out to keep the+ /// menu short: search finds that app by its developer anyway.+ public static func offered(_ names: [String], chosen: String?) -> [String] {+ let counts = Dictionary(names.map { ($0, 1) }, uniquingKeysWith: +)+ return Set(counts.filter { $0.value > 1 }.map(\.key) + [chosen].compactMap(\.self))+ .sorted { $0.localizedStandardCompare($1) == .orderedAscending }+ }+}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppDevelopersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppDevelopersTests.swiftnew file mode 100644index 00000000..53fb7529--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppDevelopersTests.swift@@ -0,0 +1,32 @@+import Foundation+@testable import PeelCore+import Testing++struct AppDevelopersTests {+ private func app(_ name: String, team: String? = nil, developer: String? = nil) -> InstalledApp {+ InstalledApp(+ url: URL(filePath: "/Applications/\(name).app"), bundleIdentifier: "org.example.\(name.lowercased())",+ name: name, teamIdentifier: team, developer: developer+ )+ }++ @Test func namesAnAppFromItsSignatureThenItsTeamThenTheAppStore() {+ let signed = app("Studio", team: "ABCDE12345", developer: "Example Inc.")+ let storeCopy = app("Notes Plus", team: "ABCDE12345")+ let unsigned = app("Tool")+ let developers = AppDevelopers([signed, storeCopy, unsigned])++ #expect(developers.developer(of: signed, remembered: "Someone Else") == "Example Inc.")+ #expect(developers.developer(of: storeCopy, remembered: nil) == "Example Inc.")+ #expect(developers.developer(of: unsigned, remembered: "Tool Makers") == "Tool Makers")+ #expect(developers.developer(of: unsigned, remembered: nil) == nil)+ }++ @Test func offersTheDevelopersOfTwoOrMoreAppsAndTheOneChosen() {+ let names = ["Example Inc.", "zeta", "Example Inc.", "Alpha", "Alpha", "Solo"]++ #expect(AppDevelopers.offered(names, chosen: nil) == ["Alpha", "Example Inc."])+ #expect(AppDevelopers.offered(names, chosen: "Gone") == ["Alpha", "Example Inc.", "Gone"])+ #expect(AppDevelopers.offered(names, chosen: "Alpha") == ["Alpha", "Example Inc."])+ }+}diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swiftindex 6af269eb..5faf02d3 100644--- a/Peel/Model/AppLibrary.swift+++ b/Peel/Model/AppLibrary.swift@@ -381,30 +381,19 @@ final class AppLibrary {return homebrewApps[app.id] != nil ? .homebrew : .direct}- /// The app's developer. The signature names it for a Developer ID app or one of Apple's. An App Store app,- /// which Apple signs again, takes the name from another installed app of its team, or else the name the- /// App Store gave at the last update check.func developer(of app: InstalledApp) -> String? {- app.developer ?? app.teamIdentifier.flatMap { developersByTeam[$0] } ?? memory[app.bundleIdentifier]?.developer+ appDevelopers.developer(of: app, remembered: memory[app.bundleIdentifier]?.developer)}- /// The developers with two or more apps, for the list's filter. A developer with one app is left out to- /// keep the menu short, and search finds that app by its developer anyway. The chosen developer stays- /// listed even when none of its apps remain, since it is what empties the list.var developers: [String] {- let counts = Dictionary(apps.compactMap(developer(of:)).map { ($0, 1) }, uniquingKeysWith: +)- return Set(counts.filter { $0.value > 1 }.map(\.key) + [selectedDeveloper].compactMap(\.self))- .sorted { $0.localizedStandardCompare($1) == .orderedAscending }+ AppDevelopers.offered(apps.compactMap(developer(of:)), chosen: selectedDeveloper)}- private var developersByTeam: [String: String] {- if let lastTeams, lastTeams.revision == revision { return lastTeams.names }- let names = Dictionary(- apps.compactMap { app in app.developer.flatMap { name in app.teamIdentifier.map { ($0, name) } } },- uniquingKeysWith: { first, _ in first }- )- lastTeams = (revision, names)- return names+ private var appDevelopers: AppDevelopers {+ if let lastTeams, lastTeams.revision == revision { return lastTeams.developers }+ let developers = AppDevelopers(apps)+ lastTeams = (revision, developers)+ return developers}/// The cask this app was installed from, which is the name `brew upgrade` has to be given.@@ -421,7 +410,7 @@ final class AppLibrary {@ObservationIgnored private var lastVisible: (key: VisibleKey, apps: VisibleApps)?@ObservationIgnored private var lastExcluded: (revision: Int, exclusions: Exclusions, ids: Set<InstalledApp.ID>)?@ObservationIgnored private var lastNames: (revision: Int, names: [String: String])?- @ObservationIgnored private var lastTeams: (revision: Int, names: [String: String])?+ @ObservationIgnored private var lastTeams: (revision: Int, developers: AppDevelopers)?/// The apps the user excluded. Worked out again only when the apps or the exclusions change, since each/// check resolves the app's path on disk.