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 the question about day-old answers for a round that can ask

Țugui Dragoșe08839c1ce89
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index c5b057c1..6166d526 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -651,8 +651,12 @@ final class AppLibrary {
// 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 }
guard !wanted.isEmpty else { return }
- // With no network at all, each request would wait out its whole time, and nothing is learned of any app.
- guard await updateChecker.canReachTheNetwork() else { return }
+ // With no network at all, each request would wait out its whole time, and nothing is learned of any app, so the
+ // first round that asks about answers a day old is still to come.
+ guard await updateChecker.canReachTheNetwork() else {
+ if isFirstRound { hasAskedSinceLaunch = false }
+ return
+ }
let asked = Dictionary(wanted.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })
let round = updateRounds.begin(wanted.map(\.id))
// However the round ends, no app is left marked as being checked by it.
diff --git a/PeelTests/AppLibraryTests.swift b/PeelTests/AppLibraryTests.swift
index 54de421a..f6744cfe 100644
--- a/PeelTests/AppLibraryTests.swift
+++ b/PeelTests/AppLibraryTests.swift
@@ -1,7 +1,7 @@
import Foundation
import Observation
@testable import Peel
-import PeelCore
+@testable import PeelCore
import Synchronization
import Testing
@@ -691,6 +691,38 @@ private nonisolated final class TestClock: Sendable {
#expect(library.hasUpdate(app))
}
+ @Test func aFirstRoundWithNoNetworkLeavesAnAnswerADayOldToTheNext() 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() }
+ AppcastProtocol.body.withLock { $0 = newerFeed }
+ let earlier = library(with: made.defaults, notesIn: folder)
+ #expect(await earlier.reveal([bundle]))
+ let app = try #require(earlier.apps.first { $0.bundleIdentifier == "org.example.fed" })
+ keepAnAnswerTwoDaysOld(about: app, in: made.defaults)
+ let configuration = URLSessionConfiguration.ephemeral
+ configuration.protocolClasses = [AppcastProtocol.self]
+ let isOnline = Mutex(false)
+ let library = AppLibrary(
+ defaults: made.defaults,
+ updateChecker: UpdateChecker(
+ session: URLSession(configuration: configuration), appStoreWindow: .appStore,
+ isOnline: { isOnline.withLock { $0 } }
+ ),
+ releaseNotesStore: ReleaseNotesStore(url: folder.appending(path: "release-notes.json"))
+ )
+ #expect(await library.reveal([bundle]))
+
+ await library.checkForUpdates([app])
+ #expect(!library.hasUpdate(app))
+
+ isOnline.withLock { $0 = true }
+ await library.checkForUpdates([app])
+ #expect(library.hasUpdate(app))
+ }
+
@Test func aLaterRoundLeavesAnAnswerADayOldToItsSchedule() 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")