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.

Keep a round of update checks going when apps leave the list

Țugui Dragoș347baa85d42c
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index ec16dbde..2541985e 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -572,6 +572,13 @@ final class AppLibrary {
group.cancelAll()
continue
}
+ // Whatever comes of this answer, the next app is asked, so one that left the list costs no place.
+ if let app = pending.next() {
+ let earlier = updateStatuses[app.id]
+ _ = group.addTaskUnlessCancelled {
+ (app.id, await checker.answer(for: app, preference: preference, casks: casks, earlier: earlier))
+ }
+ }
// In a canceled round every pending request ends as a failure. Recording those would erase
// what was known and put off the next check for hours.
guard !Task.isCancelled else { continue }
@@ -615,12 +622,6 @@ final class AppLibrary {
notesToAsk.append(ReleaseNotesQuestion(app: app, answer: answer, version: version))
}
}
- if let app = pending.next() {
- let earlier = updateStatuses[app.id]
- _ = group.addTaskUnlessCancelled {
- (app.id, await checker.answer(for: app, preference: preference, casks: casks, earlier: earlier))
- }
- }
}
}
guard !Task.isCancelled, updateRounds.isCurrent(round) else { return }
diff --git a/PeelTests/AppLibraryTests.swift b/PeelTests/AppLibraryTests.swift
index f9dbd4ef..30a00d78 100644
--- a/PeelTests/AppLibraryTests.swift
+++ b/PeelTests/AppLibraryTests.swift
@@ -383,6 +383,28 @@ private nonisolated final class TestClock: Sendable {
#expect(memory["org.example.fed"] == nil, "its feed answers at the next round")
}
+ @Test func aRoundAsksEveryAppEvenWhenAppsLeaveTheListBeforeTheirAnswers() async throws {
+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
+ defer { try? FileManager.default.removeItem(at: folder) }
+ let bundles = try (1...9).map { try caskApp("App\($0)", in: folder, feed: "https://feed.example.com/appcast.xml") }
+ let made = try MadeUpDefaults()
+ defer { made.forget() }
+ AppcastProtocol.body.withLock {
+ $0 = Data(#"<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"><channel><item><enclosure url="https://feed.example.com/u.zip" sparkle:version="101" sparkle:shortVersionString="1.1" /></item></channel></rss>"#.utf8)
+ }
+ let library = library(with: made.defaults, notesIn: folder)
+ #expect(await library.reveal(Array(bundles.prefix(8))))
+ let asked = library.apps.filter { $0.name.hasPrefix("App") }.sorted { $0.name < $1.name }
+ for bundle in bundles.prefix(7) { try FileManager.default.removeItem(at: bundle) }
+ #expect(await library.reveal([bundles[8]]))
+
+ await library.checkForUpdates(asked, force: true)
+
+ let last = try #require(asked.last)
+ #expect(asked.count == 8 && last.name == "App8")
+ #expect(library.hasUpdate(last), "the eighth app was asked once the first seven left the list")
+ }
+
@Test func anAppPeelNeverChecksGetsNothingFromHomebrew() async throws {
let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
let bundle = try caskApp("Tool", in: folder)