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.

Ask what is new only for an update that waits

Țugui Dragoșa9f02e07af33
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotesMemory.swift b/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotesMemory.swift
index af1fce60..abb676e1 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotesMemory.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/ReleaseNotesMemory.swift
@@ -23,6 +23,13 @@ public struct ReleaseNotesMemory: Sendable, Equatable, Codable {
entries[identifier]?.version != version
}
+ /// 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)
+ }
+
public mutating func record(_ lookup: ReleaseNotesLookup, of identifier: String, version: String) {
switch lookup {
case .found(let notes): entries[identifier] = Entry(version: version, notes: notes)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesMemoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesMemoryTests.swift
index 6f3e9a04..83a7adfd 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesMemoryTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ReleaseNotesMemoryTests.swift
@@ -33,6 +33,23 @@ struct ReleaseNotesMemoryTests {
#expect(memory.asks("org.example.viewer", version: "5.0"))
}
+ @Test func asksOnlyAboutAnUpdateThatWaits() {
+ let app = InstalledApp(
+ url: URL(filePath: "/Applications/Editor.app"), bundleIdentifier: "org.example.editor", name: "Editor"
+ )
+ 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])
+
+ #expect(memory.asks(about: update, of: app, with: UpdatePreferences()))
+ #expect(!memory.asks(about: update, of: app, with: skipped))
+ #expect(memory.asks(about: update, of: app, with: skippedBefore))
+ #expect(!memory.asks(about: update, of: app, with: ignored))
+ #expect(!memory.asks(about: .upToDate, of: app, with: UpdatePreferences()))
+ }
+
@Test func keepsTheNotesAcrossLaunches() async throws {
let directory = try TemporaryDirectory()
let store = ReleaseNotesStore(url: directory.url.appending(path: "Peel/release-notes.json"))
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index 8e2373c5..73477096 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -508,8 +508,8 @@ final class AppLibrary {
// 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 = updateStatuses[app.id]?.version.map { releaseNotes.asks(app.bundleIdentifier, version: $0) }
- return memory[app.bundleIdentifier]?.schedule.isDue(at: now) ?? true || notesWait == true
+ let notesWait = releaseNotes.asks(about: updateStatuses[app.id], of: app, with: updatePreferences)
+ return memory[app.bundleIdentifier]?.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 }
@@ -566,7 +566,7 @@ final class AppLibrary {
if case .updateAvailable(let version, _, _) = kept, answer.status == kept {
if let notes = answer.notes {
releaseNotes.record(.found(notes), of: identifier, version: version)
- } else if releaseNotes.asks(identifier, version: version) {
+ } else if releaseNotes.asks(about: kept, of: app, with: updatePreferences) {
notesToAsk.append(ReleaseNotesQuestion(app: app, answer: answer, version: version))
}
}