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.

Updates ignore releases an Intel Mac can't run

Țugui Dragoșc0ee17147f11
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/Appcast.swift b/Packages/PeelCore/Sources/PeelCore/Updates/Appcast.swift
index 89415b1f..bd7ffc38 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/Appcast.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/Appcast.swift
@@ -8,6 +8,8 @@ struct AppcastItem: Equatable {
var channel: String?
/// `sparkle:os` on the enclosure. A feed shared with WinSparkle lists Windows builds beside the Mac's.
var system: String?
+ /// `sparkle:hardwareRequirements`, in lowercase. Sparkle knows one: `arm64`, a release for Apple silicon only.
+ var hardwareRequirements: Set<String> = []
var releaseNotes: URL?
var displayVersion: String? {
@@ -19,15 +21,16 @@ enum Appcast {
enum Reading: Equatable {
case latest(AppcastItem)
/// The feed was read, but none of its items is a release for the running system: each is on a named
- /// channel, is for another operating system, needs a newer or older macOS, or has no version. This counts
- /// as up to date, not as a failed check.
+ /// channel, is for another operating system, needs a newer or older macOS or Apple silicon, or has no
+ /// version. This counts as up to date, not as a failed check.
case nothingForThisMac
case unreadable
}
/// Finds the newest release that runs on `systemVersion`. Like Sparkle, it skips items on a named channel,
- /// items for another operating system, and items that need a newer or older macOS.
- static func read(_ data: Data, systemVersion: String) -> Reading {
+ /// items for another operating system, items that need a newer or older macOS, and, on an Intel Mac, items
+ /// that need Apple silicon. Sparkle offers those under Rosetta, which only an Apple silicon Mac has.
+ static func read(_ data: Data, systemVersion: String, isAppleSilicon: Bool) -> Reading {
let delegate = ParserDelegate()
let parser = XMLParser(data: data)
parser.delegate = delegate
@@ -37,6 +40,7 @@ enum Appcast {
guard item.channel == nil, item.displayVersion != nil, item.system == nil || item.system == "macos" else { return false }
if let minimum = item.minimumSystemVersion, VersionComparison.isNewer(minimum, than: systemVersion) { return false }
if let maximum = item.maximumSystemVersion, VersionComparison.isNewer(systemVersion, than: maximum) { return false }
+ if !isAppleSilicon, item.hardwareRequirements.contains("arm64") { return false }
return true
}
return releases.max(by: isOlder).map(Reading.latest) ?? .nothingForThisMac
@@ -122,6 +126,9 @@ enum Appcast {
current?.maximumSystemVersion = value
case "sparkle:channel" where !value.isEmpty:
current?.channel = value
+ case "sparkle:hardwareRequirements":
+ let separators = CharacterSet.whitespaces.union(CharacterSet(charactersIn: ","))
+ current?.hardwareRequirements = Set(value.lowercased().components(separatedBy: separators).filter { !$0.isEmpty })
case "sparkle:releaseNotesLink", "releaseNotesLink", "sparkle:fullReleaseNotesLink", "link":
if current != nil, let url = URL(string: value), url.scheme == "https",
notes[elementName]?.contains(where: { $0.language == noteLanguage }) != true {
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift
index cd98ed5f..aa512f62 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift
@@ -23,6 +23,7 @@ public struct UpdateChecker: Sendable {
private let session: URLSession
private let country: String
private let systemVersion: String
+ private let isAppleSilicon = HostArchitecture.isAppleSilicon
public init(session: URLSession? = nil, locale: Locale = .current) {
self.session = session ?? URLSession(configuration: Self.configuration)
@@ -97,7 +98,7 @@ public struct UpdateChecker: Sendable {
private func sparkleStatus(for app: InstalledApp, at url: URL) async -> UpdateStatus {
guard let data = await fetch(url) else { return .failed }
let item: AppcastItem
- switch Appcast.read(data, systemVersion: systemVersion) {
+ switch Appcast.read(data, systemVersion: systemVersion, isAppleSilicon: isAppleSilicon) {
case .unreadable: return .failed
case .nothingForThisMac: return .upToDate
case .latest(let latest): item = latest
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdateCheckerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdateCheckerTests.swift
index 25194ed9..b6279916 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdateCheckerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdateCheckerTests.swift
@@ -105,6 +105,14 @@ private final class CannedProtocol: URLProtocol, @unchecked Sendable {
#expect(await checker.status(for: sparkleApp()) == .upToDate)
}
+ /// A release for Apple silicon only is an update on this Mac when it has Apple silicon, and nothing at all when
+ /// it has an Intel processor.
+ @Test func aReleaseForAppleSiliconIsAnUpdateOnlyOnAppleSilicon() async {
+ reply("feed.example.com", appcast("<item><sparkle:version>200</sparkle:version><sparkle:shortVersionString>2.0</sparkle:shortVersionString><sparkle:hardwareRequirements>arm64</sparkle:hardwareRequirements></item>"))
+ let expected: UpdateStatus = HostArchitecture.isAppleSilicon ? .updateAvailable(version: "2.0", source: .developer, releaseNotes: nil) : .upToDate
+ #expect(await checker.status(for: sparkleApp()) == expected)
+ }
+
/// Many apps installed with Homebrew carry no update feed of their own. In the automatic mode, Homebrew's
/// answer is used for them rather than "Can't check for updates".
@Test func automaticFallsBackToWhatHomebrewKnows() async {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift
index 8865006d..f87d839d 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift
@@ -24,7 +24,7 @@ struct VersionComparisonTests {
struct AppcastTests {
private func latestItem(in feed: String, systemVersion: String = "26.7.0") -> AppcastItem? {
- if case .latest(let item) = Appcast.read(Data(feed.utf8), systemVersion: systemVersion) { item } else { nil }
+ if case .latest(let item) = Appcast.read(Data(feed.utf8), systemVersion: systemVersion, isAppleSilicon: true) { item } else { nil }
}
/// A feed shared with WinSparkle lists a Windows build beside the Mac one, and the last release for an
@@ -41,14 +41,41 @@ struct AppcastTests {
#expect(try #require(latestItem(in: feed)).version == "500")
}
+ /// Sparkle does not offer an Intel Mac a release that lists `arm64` among its hardware requirements, so neither
+ /// does Peel. The list is split at spaces and commas and read without case, as Sparkle reads it.
+ @Test func skipsAReleaseForAppleSiliconOnAnIntelMac() throws {
+ let feed = """
+ <rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"><channel>
+ <item><sparkle:version>600</sparkle:version><sparkle:hardwareRequirements>ARM64</sparkle:hardwareRequirements></item>
+ <item><sparkle:version>550</sparkle:version><sparkle:hardwareRequirements>metal,arm64</sparkle:hardwareRequirements></item>
+ <item><sparkle:version>500</sparkle:version><sparkle:hardwareRequirements>metal</sparkle:hardwareRequirements></item>
+ </channel></rss>
+ """
+ let read = { (isAppleSilicon: Bool) in Appcast.read(Data(feed.utf8), systemVersion: "26.7.0", isAppleSilicon: isAppleSilicon) }
+ guard case .latest(let onIntel) = read(false), case .latest(let onAppleSilicon) = read(true) else {
+ Issue.record("the feed was not read")
+ return
+ }
+ #expect(onIntel.version == "500")
+ #expect(onAppleSilicon.version == "600")
+ #expect(onAppleSilicon.hardwareRequirements == ["arm64"])
+
+ let onlyForAppleSilicon = """
+ <rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"><channel>
+ <item><sparkle:version>600</sparkle:version><sparkle:hardwareRequirements>arm64 metal</sparkle:hardwareRequirements></item>
+ </channel></rss>
+ """
+ #expect(Appcast.read(Data(onlyForAppleSilicon.utf8), systemVersion: "26.7.0", isAppleSilicon: false) == .nothingForThisMac)
+ }
+
@Test func tellsAHealthyFeedWithNothingForThisMacFromOneItCannotRead() {
let future = """
<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"><channel>
<item><sparkle:version>4</sparkle:version><sparkle:minimumSystemVersion>99.0</sparkle:minimumSystemVersion></item>
</channel></rss>
"""
- #expect(Appcast.read(Data(future.utf8), systemVersion: "26.7.0") == .nothingForThisMac)
- #expect(Appcast.read(Data("<rss><channel>".utf8), systemVersion: "26.7.0") == .unreadable)
+ #expect(Appcast.read(Data(future.utf8), systemVersion: "26.7.0", isAppleSilicon: true) == .nothingForThisMac)
+ #expect(Appcast.read(Data("<rss><channel>".utf8), systemVersion: "26.7.0", isAppleSilicon: true) == .unreadable)
}
/// Sparkle reads the version from the enclosure's attribute first, and from the element only when there is
@@ -410,7 +437,7 @@ struct UpdateSourceTests {
<sparkle:releaseNotesLink>https://example.com/notes.html</sparkle:releaseNotesLink>
</item></channel></rss>
"""
- guard case .latest(let item) = Appcast.read(Data(feed.utf8), systemVersion: "26.0.0") else {
+ guard case .latest(let item) = Appcast.read(Data(feed.utf8), systemVersion: "26.0.0", isAppleSilicon: true) else {
Issue.record("the feed was not read")
return
}