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.

Forget an update Homebrew no longer reports as soon as Homebrew is read

Țugui Dragoș9f73ca08a830
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateFeed.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateFeed.swift
index 17b66c3a..4ba18c31 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateFeed.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateFeed.swift
@@ -50,10 +50,13 @@ public enum UpdateStatus: Sendable, Hashable, Codable {
if case .updateAvailable(_, let source, _) = self { source } else { nil }
}
- /// Whether this answer still holds for an app, given whether Homebrew counts the app as its own now: an update
- /// Homebrew reported is about its cask, and says nothing once the app is not Homebrew's.
- public func holds(whileHomebrews isHomebrews: Bool) -> Bool {
- source != .homebrew || isHomebrews
+ /// Whether this answer still holds for an app, given what Homebrew says of the app now, nil where the app isn't
+ /// Homebrew's or Homebrew says nothing that counts: an update Homebrew reported holds only while Homebrew reports
+ /// one.
+ public func holds(whileHomebrewSays homebrew: UpdateStatus?) -> Bool {
+ guard source == .homebrew else { return true }
+ if case .updateAvailable = homebrew { return true }
+ return false
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift
index 36db28a0..0f617f67 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift
@@ -666,15 +666,17 @@ struct UpdateSourceTests {
#expect(status(behind, checked) == update)
}
- @Test func anUpdateHomebrewReportedHoldsOnlyWhileTheAppIsHomebrews() {
+ @Test func anUpdateHomebrewReportedHoldsOnlyWhileHomebrewReportsOne() {
let homebrew = UpdateStatus.updateAvailable(version: "2.0", source: .homebrew)
- #expect(homebrew.holds(whileHomebrews: true))
- #expect(!homebrew.holds(whileHomebrews: false))
-
- #expect(UpdateStatus.updateAvailable(version: "2.0", source: .developer).holds(whileHomebrews: false))
- #expect(UpdateStatus.updateAvailable(version: "2.0", source: .appStore).holds(whileHomebrews: false))
- #expect(UpdateStatus.upToDate.holds(whileHomebrews: false))
- #expect(UpdateStatus.failed.holds(whileHomebrews: false))
+ #expect(homebrew.holds(whileHomebrewSays: homebrew))
+ #expect(homebrew.holds(whileHomebrewSays: .updateAvailable(version: "2.1", source: .homebrew)))
+ #expect(!homebrew.holds(whileHomebrewSays: .upToDate))
+ #expect(!homebrew.holds(whileHomebrewSays: nil))
+
+ #expect(UpdateStatus.updateAvailable(version: "2.0", source: .developer).holds(whileHomebrewSays: nil))
+ #expect(UpdateStatus.updateAvailable(version: "2.0", source: .appStore).holds(whileHomebrewSays: .upToDate))
+ #expect(UpdateStatus.upToDate.holds(whileHomebrewSays: nil))
+ #expect(UpdateStatus.failed.holds(whileHomebrewSays: nil))
}
@Test func showsAHomebrewVersionWithoutWhatTheDownloadNeeds() {
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index 4b0c3aa7..875340bb 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -793,10 +793,15 @@ final class AppLibrary {
applyHomebrewStatuses()
}
- /// Forgets an update Homebrew reported for an app it no longer counts as its own, saved answer included, so the
- /// app is due and its own feed answers at the next round.
+ /// Forgets an update Homebrew reported and no longer reports, for an app it no longer counts as its own or whose
+ /// cask is no longer behind, saved answer included, so the app is due and its own feed answers at the next round.
+ /// One that stands in for the app's own source is decided again from that source's answer instead.
private func forgetUpdatesHomebrewNoLongerOffers() {
- let outlived = Set(updateStatuses.filter { !$0.value.holds(whileHomebrews: homebrewApps[$0.key] != nil) }.keys)
+ let outlived = Set(apps.filter { app in
+ guard let status = updateStatuses[app.id], remembered(app)?.standsInFor == nil else { return false }
+ let homebrew = homebrewApps[app.id] == nil ? nil : updateChecker.homebrewStatus(for: app, casks: casks)
+ return !status.holds(whileHomebrewSays: homebrew)
+ }.map(\.id))
guard !outlived.isEmpty else { return }
updateStatuses = updateStatuses.filter { !outlived.contains($0.key) }
lastUpdateChecks = lastUpdateChecks.filter { !outlived.contains($0.key) }
@@ -814,16 +819,21 @@ final class AppLibrary {
private func applyHomebrewStatuses() {
let preference = updateSource
for app in apps where isAskedAboutUpdates(app) {
- let remembered = app.bundleIdentifier.flatMap { memory[$0] }.flatMap { $0.describes(app) ? $0 : nil }
- guard homebrewApps[app.id] != nil || remembered?.standsInFor != nil else { continue }
+ let saved = remembered(app)
+ guard homebrewApps[app.id] != nil || saved?.standsInFor != nil else { continue }
let decided = updateChecker.statusWithoutAsking(
- for: app, preference: preference, casks: casks, known: remembered.map { $0.standsInFor ?? $0.status }
+ for: app, preference: preference, casks: casks, known: saved.map { $0.standsInFor ?? $0.status }
)
guard let decided, decided != updateStatuses[app.id] else { continue }
updateStatuses[app.id] = decided
}
}
+ /// The answer saved for `app`, while it is about the build installed.
+ private func remembered(_ app: InstalledApp) -> UpdateMemory? {
+ app.bundleIdentifier.flatMap { memory[$0] }.flatMap { $0.describes(app) ? $0 : nil }
+ }
+
/// Whether update checks ask about `app`. Never about Peel's own copies, which Sparkle keeps current, checking
/// the one running, nor about an app the user told Peel never to check or a copy in a Trash.
private func isAskedAboutUpdates(_ app: InstalledApp) -> Bool {
diff --git a/PeelTests/AppLibraryTests.swift b/PeelTests/AppLibraryTests.swift
index 4a83c2aa..45ff16cd 100644
--- a/PeelTests/AppLibraryTests.swift
+++ b/PeelTests/AppLibraryTests.swift
@@ -361,6 +361,30 @@ private nonisolated final class TestClock: Sendable {
#expect(library.shownUpdateStatus(of: app) == .failed)
}
+ @Test func anUpdateHomebrewNoLongerReportsGoesAsSoonAsHomebrewIsRead() async throws {
+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
+ let bundle = try caskApp("Fed", in: folder, feed: "https://feed.example.com/appcast.xml")
+ defer { try? FileManager.default.removeItem(at: folder) }
+ let made = try MadeUpDefaults()
+ defer { made.forget() }
+ let library = library(with: made.defaults, notesIn: folder, clock: TestClock(homebrewChecked + 60 * 60))
+
+ #expect(await library.reveal([bundle]))
+ let app = try #require(library.apps.first { $0.bundleIdentifier == "org.example.fed" })
+ library.loadHomebrewCasks([cask("Fed", latest: "2.0", checked: homebrewChecked)], knowsItsOwnApps: true)
+ await library.checkForUpdates([app], force: true)
+ #expect(library.shownUpdateStatus(of: app)?.version == "2.0")
+
+ library.loadHomebrewCasks([cask("Fed", latest: "2.1", checked: homebrewChecked)], knowsItsOwnApps: true)
+ #expect(library.shownUpdateStatus(of: app)?.version == "2.1")
+
+ library.loadHomebrewCasks([cask("Fed", checked: homebrewChecked)], knowsItsOwnApps: true)
+ #expect(library.shownUpdateStatus(of: app) == nil)
+ let saved = try #require(made.defaults.data(forKey: SettingsKey.updateMemory))
+ let memory = try JSONDecoder().decode([String: UpdateMemory].self, from: saved)
+ #expect(memory["org.example.fed"] == nil, "its feed answers at the next round")
+ }
+
@Test func anAppPeelNeverChecksGetsNothingFromHomebrew() async throws {
let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
let bundle = try caskApp("Tool", in: folder)