mirror of
https://github.com/mas-cli/mas
synced 2024-11-25 04:50:24 +00:00
Merge pull request #422 from mas-cli/oudated-os
🐛 Don't consider an app outdated if the update can't be installed on the current OS
This commit is contained in:
commit
eafd2d5c7b
5 changed files with 71 additions and 11 deletions
|
@ -130,11 +130,11 @@
|
|||
"system": {
|
||||
"macos": {
|
||||
"monterey": {
|
||||
"HOMEBREW_VERSION": "3.2.9-73-g7e7bdca",
|
||||
"HOMEBREW_PREFIX": "/opt/homebrew",
|
||||
"Homebrew/homebrew-core": "42fd3eec28f71853a59e12f77bcaff2f103097b5",
|
||||
"CLT": "12.5.0.22.9",
|
||||
"Xcode": "12.5.1",
|
||||
"HOMEBREW_VERSION": "3.2.14-35-g9b42a10",
|
||||
"HOMEBREW_PREFIX": "/usr/local",
|
||||
"Homebrew/homebrew-core": "4119ab758ae132acdae47e218d718ff273a47997",
|
||||
"CLT": "13.0.0.0.1.1630607135",
|
||||
"Xcode": "13.0",
|
||||
"macOS": "12.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,16 +60,16 @@
|
|||
"repositoryURL": "https://github.com/apple/swift-argument-parser.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "83b23d940471b313427da226196661856f6ba3e0",
|
||||
"version": "0.4.4"
|
||||
"revision": "d2930e8fcf9c33162b9fcc1d522bc975e2d4179b",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-format",
|
||||
"repositoryURL": "https://github.com/apple/swift-format",
|
||||
"state": {
|
||||
"branch": "swift-5.4-branch",
|
||||
"revision": "9c15831b798d767c9af0927a931de5d557004936",
|
||||
"branch": "swift-5.5-branch",
|
||||
"revision": "f872223e16742fd97fabd319fbf4a939230cc796",
|
||||
"version": null
|
||||
}
|
||||
},
|
||||
|
@ -78,8 +78,8 @@
|
|||
"repositoryURL": "https://github.com/apple/swift-syntax",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "2fff9fc25cdc059379b6bd309377cfab45d8520c",
|
||||
"version": "0.50400.0"
|
||||
"revision": "75e60475d9d8fd5bbc16a12e0eaa2cb01b0c322e",
|
||||
"version": "0.50500.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@ struct SearchResult: Decodable {
|
|||
var bundleId: String
|
||||
var currentVersionReleaseDate: String
|
||||
var fileSizeBytes: String?
|
||||
var kind: String
|
||||
var minimumOsVersion: String
|
||||
var price: Double?
|
||||
var sellerName: String
|
||||
|
@ -23,6 +24,7 @@ struct SearchResult: Decodable {
|
|||
bundleId: String = "",
|
||||
currentVersionReleaseDate: String = "",
|
||||
fileSizeBytes: String = "0",
|
||||
kind: String = "",
|
||||
minimumOsVersion: String = "",
|
||||
price: Double = 0.0,
|
||||
sellerName: String = "",
|
||||
|
@ -35,6 +37,7 @@ struct SearchResult: Decodable {
|
|||
self.bundleId = bundleId
|
||||
self.currentVersionReleaseDate = currentVersionReleaseDate
|
||||
self.fileSizeBytes = fileSizeBytes
|
||||
self.kind = kind
|
||||
self.minimumOsVersion = minimumOsVersion
|
||||
self.price = price
|
||||
self.sellerName = sellerName
|
||||
|
|
|
@ -24,7 +24,21 @@ extension SoftwareProduct {
|
|||
appName.isEmpty ? bundleIdentifier : appName
|
||||
}
|
||||
|
||||
/// Determines whether the app is considered outdated. Updates that require a higher OS version are excluded.
|
||||
/// - Parameter storeApp: App from search result.
|
||||
/// - Returns: true if the app is outdated; false otherwise.
|
||||
func isOutdatedWhenComparedTo(_ storeApp: SearchResult) -> Bool {
|
||||
// Only look at min OS version if we have one, also only consider macOS apps
|
||||
// Replace string literal with MasStoreSearch.Entity once `search` branch is merged.
|
||||
if let osVersion = Version(tolerant: storeApp.minimumOsVersion), storeApp.kind == "mac-software" {
|
||||
let requiredVersion = OperatingSystemVersion(majorVersion: osVersion.major, minorVersion: osVersion.minor,
|
||||
patchVersion: osVersion.patch)
|
||||
// Don't consider an app outdated if the version in the app store requires a higher OS version.
|
||||
guard ProcessInfo.processInfo.isOperatingSystemAtLeast(requiredVersion) else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// The App Store does not enforce semantic versioning, but we assume most apps follow versioning
|
||||
// schemes that increase numerically over time.
|
||||
guard let semanticBundleVersion = Version(tolerant: bundleVersion),
|
||||
|
|
43
Tests/MasKitTests/Models/SoftwareProductSpec.swift
Normal file
43
Tests/MasKitTests/Models/SoftwareProductSpec.swift
Normal file
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// SoftwareProductSpec.swift
|
||||
// MasKitTests
|
||||
//
|
||||
// Created by Ben Chatelain on 9/30/21.
|
||||
// Copyright © 2018 mas-cli. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Nimble
|
||||
import Quick
|
||||
|
||||
@testable import MasKit
|
||||
|
||||
public class SoftwareProductSpec: QuickSpec {
|
||||
override public func spec() {
|
||||
beforeSuite {
|
||||
MasKit.initialize()
|
||||
}
|
||||
describe("software product") {
|
||||
let app = SoftwareProductMock(appName: "App", bundleIdentifier: "", bundlePath: "", bundleVersion: "1.0.0",
|
||||
itemIdentifier: 111)
|
||||
|
||||
let currentApp = SearchResult(kind: "mac-software", version: "1.0.0")
|
||||
let appUpdate = SearchResult(kind: "mac-software", version: "2.0.0")
|
||||
let higherOs = SearchResult(kind: "mac-software", minimumOsVersion: "99.0.0", version: "3.0.0")
|
||||
let updateIos = SearchResult(kind: "software", minimumOsVersion: "99.0.0", version: "3.0.0")
|
||||
|
||||
it("is not outdated when there is no new version available") {
|
||||
expect(app.isOutdatedWhenComparedTo(currentApp)) == false
|
||||
}
|
||||
it("is outdated when there is a new version available") {
|
||||
expect(app.isOutdatedWhenComparedTo(appUpdate)) == true
|
||||
}
|
||||
it("is not outdated when the new version requires a higher OS version") {
|
||||
expect(app.isOutdatedWhenComparedTo(higherOs)) == false
|
||||
}
|
||||
it("ignores minimum iOS version") {
|
||||
expect(app.isOutdatedWhenComparedTo(updateIos)) == true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue