Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Ask VS Code's service for its latest build, so the check sends no version
Țugui Dragoș4edcab9160bd
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex 5942084b..f2106a99 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -356,8 +356,8 @@ macOS asks the user to approve it once. It talks to the app over XPC.settings from. It asks on its own only while Check for app updates is on (`OwnUpdateCheck`), and the updateround of the other apps passes over Peel.- **Updates of other apps.** `UpdateChecker` asks each app's own feed (a Sparkle appcast, electron-updater's file, or,- for a stable build of VS Code, the service its `product.json` names, as VS Code asks it, `VSCodeUpdateService`), or- the App Store about an app from the App Store, and uses what Homebrew knows for an app a cask installed: first with+ for a stable build of VS Code, the latest build the service its `product.json` names offers, `VSCodeUpdateService`),+ or the App Store about an app from the App Store, and uses what Homebrew knows for an app a cask installed: first withAutomatic or Homebrew preferred, and under any choice once the app's own source can't answer, an "up to date" onlyfor a day after Homebrew last checked for new versions (`Homebrew.lastUpdateCheck`: while it reads its API, the dateof the definitions file it downloads or confirms, since a fetch of its own repository leaves them as they were;diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swiftindex a1adc28a..7f520c87 100644--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift@@ -284,18 +284,10 @@ public struct UpdateChecker: Sendable {private func vsCodeAnswer(installed: String, at url: URL) async -> UpdateAnswer {let reply = await fetchReply(url)- // The service answers 204, with nothing, while the build is the newest (`doIsLatestVersion`).- if reply.status == 204 { return UpdateAnswer(status: .upToDate) }guard let data = reply.data else { return UpdateAnswer(status: .failed, wasOffline: reply.wasOffline) }- switch VSCodeUpdateService.read(data) {- case .unreadable:- return UpdateAnswer(status: .failed)- case .nothingOffered:- return UpdateAnswer(status: .upToDate)- case .offered(let latest):- guard VersionComparison.isNewer(latest, than: installed) else { return UpdateAnswer(status: .upToDate) }- return UpdateAnswer(status: .updateAvailable(version: latest, source: .developer, releaseNotes: nil))- }+ guard let latest = VSCodeUpdateService.version(in: data) else { return UpdateAnswer(status: .failed) }+ guard VersionComparison.isNewer(latest, than: installed) else { return UpdateAnswer(status: .upToDate) }+ return UpdateAnswer(status: .updateAvailable(version: latest, source: .developer, releaseNotes: nil))}/// Asks the App Store about `app`, but only when the app has an App Store receipt, whoever calls this.diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/VSCodeUpdateService.swift b/Packages/PeelCore/Sources/PeelCore/Updates/VSCodeUpdateService.swiftindex f062e630..c4facbd3 100644--- a/Packages/PeelCore/Sources/PeelCore/Updates/VSCodeUpdateService.swift+++ b/Packages/PeelCore/Sources/PeelCore/Updates/VSCodeUpdateService.swift@@ -6,31 +6,20 @@ enum VSCodeUpdateService {/// An editor built on VS Code names a service of its own, whose answers Peel doesn't know.static let service = "https://update.code.visualstudio.com"- enum Reading: Equatable {- case unreadable- case nothingOffered- case offered(version: String)- }-- /// The address VS Code asks when you check for updates (`createUpdateURL`), from its `product.json`: the build's- /// platform, its quality and the commit it was made from. Only a stable build, since an Insiders build keeps its- /// version from one build to the next.+ /// The address of the latest stable build for the installed build's platform, from its `product.json`. VS Code+ /// asks about the commit it was built from, which names its version, so Peel asks for the latest build instead.+ /// Only a stable build, since an Insiders build keeps its version from one build to the next.static func feedURL(product: [String: Any], runsOnAppleSilicon: Bool) -> URL? {- guard product["updateUrl"] as? String == service, product["quality"] as? String == "stable",- let commit = product["commit"] as? String, commit.wholeMatch(of: /[0-9a-f]{40}/) != nil- else { return nil }+ guard product["updateUrl"] as? String == service, product["quality"] as? String == "stable" else { return nil }let platform = product["darwinUniversalAssetId"] as? String ?? (runsOnAppleSilicon ? "darwin-arm64" : "darwin")guard platform.wholeMatch(of: /[a-z0-9-]+/) != nil else { return nil }- return URL(string: "\(service)/api/update/\(platform)/stable/\(commit)?u=none")+ return URL(string: "\(service)/api/update/\(platform)/stable/latest")}- /// A reply as VS Code reads one (`checkForUpdateNoDownload`): it offers a build only when it names the download,- /// the commit and the version.- static func read(_ data: Data) -> Reading {- guard let reply = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] else { return .unreadable }- guard reply["url"] is String, reply["version"] is String, let version = reply["productVersion"] as? String,- !version.isEmpty- else { return .nothingOffered }- return .offered(version: version)+ /// The version a reply gives the latest build, its `productVersion`: its `version` is the commit.+ static func version(in data: Data) -> String? {+ let reply = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any]+ guard let version = reply?["productVersion"] as? String, !version.isEmpty else { return nil }+ return version}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/InventoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/InventoryTests.swiftindex 9af7e66c..dcf034c8 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/InventoryTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/InventoryTests.swift@@ -25,7 +25,7 @@ struct InventoryTests {/// receipt inside the bundle says App Store.@Test func namesWhereEachAppCameFrom() {let cask = HomebrewPackage(name: "bear", kind: .cask, installedVersion: "2.0", appNames: ["Bear.app"])- let service = "https://update.code.visualstudio.com/api/update/darwin-arm64/stable/\(String(repeating: "0", count: 40))"+ let service = "https://update.code.visualstudio.com/api/update/darwin-arm64/stable/latest"let inventory = Inventory.build(apps: [app("Bear", bundleIdentifier: "net.shinyfrog.bear"),diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdateCheckerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdateCheckerTests.swiftindex 5022d495..c3ac3ccd 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdateCheckerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdateCheckerTests.swift@@ -686,8 +686,8 @@ private final class DroppedProtocol: URLProtocol, @unchecked Sendable {#expect(await checker.answer(for: sparkleApp()).notes == nil, "nothing waits for an app that is up to date")}- @Test func readsVSCodesServiceAsVSCodeDoes() async throws {- let address = "https://update.code.visualstudio.com/api/update/darwin-arm64/stable/e646868227c3e3a9e3f24277c8c7220be42c0be7?u=none"+ @Test func comparesTheLatestBuildVSCodesServiceOffersWithTheInstalledOne() async throws {+ let address = "https://update.code.visualstudio.com/api/update/darwin-arm64/stable/latest"let code = InstalledApp(url: URL(filePath: "/Applications/Visual Studio Code.app"), bundleIdentifier: "com.microsoft.VSCode",name: "Visual Studio Code", version: "1.143.1", updateFeed: .vsCode(try #require(URL(string: address)))@@ -696,17 +696,17 @@ private final class DroppedProtocol: URLProtocol, @unchecked Sendable {#"{"url":"https://example.com/VSCode-darwin-arm64.zip","version":"2c33b50b16c472efe58357d1d2a8a5414bc23fbf","productVersion":"\#(version)"}"#}- reply("update.code.visualstudio.com", status: 204, "")- #expect(await checker.status(for: code) == .upToDate)- #expect(CannedProtocol.addresses.withLock { $0.last } == address)reply("update.code.visualstudio.com", offer("1.144.0"))#expect(await checker.status(for: code) == .updateAvailable(version: "1.144.0", source: .developer))- reply("update.code.visualstudio.com", offer("1.143.0"))- #expect(await checker.status(for: code) == .upToDate)- reply("update.code.visualstudio.com", #"{"productVersion":"1.144.0"}"#)- #expect(await checker.status(for: code) == .upToDate, "no download named")- reply("update.code.visualstudio.com", "<html></html>")- #expect(await checker.status(for: code) == .failed)+ #expect(CannedProtocol.addresses.withLock { $0.last } == address)+ for version in ["1.143.1", "1.143.0"] {+ reply("update.code.visualstudio.com", offer(version))+ #expect(await checker.status(for: code) == .upToDate, "\(version)")+ }+ for (status, body) in [(200, #"{"url":"https://example.com/VSCode-darwin-arm64.zip"}"#), (200, "<html></html>"), (204, "")] {+ reply("update.code.visualstudio.com", status: status, body)+ #expect(await checker.status(for: code) == .failed, "\(status) \(body)")+ }}@Test func anElectronReleaseTheAppWontOfferThisMacIsNoUpdate() async {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swiftindex f10cda59..302fef30 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift@@ -405,7 +405,7 @@ struct UpdateFeedDetectionTests {"commit": "e646868227c3e3a9e3f24277c8c7220be42c0be7", "darwinUniversalAssetId": "darwin-universal"}"""#let app = try #require(AppInspector.inspect(try bundle(info: [:], files: ["Resources/app/product.json": product], in: folder)))- let address = "https://update.code.visualstudio.com/api/update/darwin-universal/stable/e646868227c3e3a9e3f24277c8c7220be42c0be7?u=none"+ let address = "https://update.code.visualstudio.com/api/update/darwin-universal/stable/latest"#expect(app.updateFeed == .vsCode(try #require(URL(string: address))))}@@ -414,13 +414,11 @@ struct UpdateFeedDetectionTests {"updateUrl": "https://update.code.visualstudio.com", "quality": "stable","commit": "e646868227c3e3a9e3f24277c8c7220be42c0be7",]- let address = { (platform: String) in- "https://update.code.visualstudio.com/api/update/\(platform)/stable/e646868227c3e3a9e3f24277c8c7220be42c0be7?u=none"- }+ let address = { (platform: String) in "https://update.code.visualstudio.com/api/update/\(platform)/stable/latest" }#expect(VSCodeUpdateService.feedURL(product: product, runsOnAppleSilicon: true)?.absoluteString == address("darwin-arm64"))#expect(VSCodeUpdateService.feedURL(product: product, runsOnAppleSilicon: false)?.absoluteString == address("darwin"))- for (key, value) in [("quality", "insider"), ("updateUrl", "https://updates.example.com"), ("commit", "HEAD")] {+ for (key, value) in [("quality", "insider"), ("updateUrl", "https://updates.example.com")] {var other = productother[key] = value#expect(VSCodeUpdateService.feedURL(product: other, runsOnAppleSilicon: true) == nil, "\(key)")