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 the rule that tells an app opened again from an updated one
Țugui Dragoș4e024d914581
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swift b/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swiftindex 579d4e0b..20c07ab5 100644--- a/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swift+++ b/Packages/PeelCore/Sources/PeelCore/Apps/InstalledApp.swift@@ -34,6 +34,13 @@ public struct InstalledApp: Sendable, Hashable, Identifiable {/// Whether this is the very bundle the running code was started from: the copy of Peel that is running.public let isTheRunningCopy: Bool+ /// Whether `other`, a reading of the same path, is the same build. Not `==`: the date an app was last opened+ /// changes every time it is opened, which is no reason to forget its size or check it for updates again.+ public func isTheSameBuild(as other: InstalledApp) -> Bool {+ version == other.version && buildVersion == other.buildVersion && architectures == other.architectures+ && teamIdentifier == other.teamIdentifier+ }+public init(url: URL,bundleIdentifier: String,diff --git a/Packages/PeelCore/Tests/PeelCoreTests/InstalledAppTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/InstalledAppTests.swiftindex b658b8b8..725194c6 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/InstalledAppTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/InstalledAppTests.swift@@ -31,4 +31,22 @@ struct InstalledAppTests {#expect(!around.isTheRunningCopy)#expect(!other.isTheRunningCopy)}++ @Test func anAppOpenedAgainIsTheSameBuildAndAnUpdateIsNot() {+ func app(version: String = "2.0", build: String = "200", team: String = "ABCDE12345",+ architectures: Set<Architecture> = [.arm64], opened: Date? = nil) -> InstalledApp {+ InstalledApp(+ url: URL(filePath: "/Applications/Example.app"), bundleIdentifier: "org.example.app", name: "Example",+ version: version, buildVersion: build, teamIdentifier: team, architectures: architectures,+ lastUsedDate: opened+ )+ }+ let before = app()++ #expect(before.isTheSameBuild(as: app(opened: .now)))+ #expect(!before.isTheSameBuild(as: app(version: "2.1")))+ #expect(!before.isTheSameBuild(as: app(build: "201")))+ #expect(!before.isTheSameBuild(as: app(team: "ZYXWV98765")))+ #expect(!before.isTheSameBuild(as: app(architectures: [.arm64, .x86_64])))+ }}diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swiftindex 6fd64a1d..6af269eb 100644--- a/Peel/Model/AppLibrary.swift+++ b/Peel/Model/AppLibrary.swift@@ -292,7 +292,7 @@ final class AppLibrary {appsInATrash = Set(revealed.filter { trash.isInsideATrash($0.url) }.map(\.id))let listed = AppCatalog.sorted(found + revealed)let previous = Dictionary(apps.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })- let changed = listed.filter { app in previous[app.id].map { !Self.isTheSameBuild($0, app) } ?? false }+ let changed = listed.filter { app in previous[app.id].map { !$0.isTheSameBuild(as: app) } ?? false }let present = Set(listed.map(\.id))IconCache.forget(previous.keys.filter { !present.contains($0) } + changed.map(\.url))apps = listed@@ -336,15 +336,6 @@ final class AppLibrary {}}- /// Whether two readings of the same path are the same build. Deliberately not `==`: `lastUsedDate`- /// changes every time an app is opened, which is no reason to forget its size or check for updates again.- private static func isTheSameBuild(_ before: InstalledApp, _ after: InstalledApp) -> Bool {- before.version == after.version- && before.buildVersion == after.buildVersion- && before.architectures == after.architectures- && before.teamIdentifier == after.teamIdentifier- }-/// Measures the apps with no size yet. Each bundle needs a walk of every file, so sizes arrive after the list./// A bundle that could not be measured is asked once more after `remeasureDelay`: a walk that ran out of time/// goes on, and its answer is kept for the next question.@@ -369,7 +360,7 @@ final class AppLibrary {// A walk given up because the list changed says nothing about the bundle, and a bundle replaced// while it was walked is another build, so neither answer is kept.if !Task.isCancelled, let app = measured[id],- apps.contains(where: { $0.id == id && Self.isTheSameBuild($0, app) }) {+ apps.contains(where: { $0.id == id && $0.isTheSameBuild(as: app) }) {if let size {sizes[id] = sizeunmeasured.remove(id)@@ -571,7 +562,7 @@ final class AppLibrary {// what was known and put off the next check for hours.guard !Task.isCancelled else { continue }// The answer describes the build that was asked about, which may have been replaced since.- guard let app = asked[id], apps.contains(where: { $0.id == id && Self.isTheSameBuild($0, app) }) else {+ guard let app = asked[id], apps.contains(where: { $0.id == id && $0.isTheSameBuild(as: app) }) else {continue}let kept = status.following(updateStatuses[id])@@ -762,7 +753,7 @@ final class AppLibrary {/// How the last upgrade of `app` went, while `app` is still the build it left.func upgrade(of app: InstalledApp) -> Upgrade? {- upgrades[app.id].flatMap { Self.isTheSameBuild($0.app, app) ? $0 : nil }+ upgrades[app.id].flatMap { $0.app.isTheSameBuild(as: app) ? $0 : nil }}func record(_ upgrade: Upgrade?, of app: InstalledApp) {