Parses AppVersion.minOSVersion/maxOSVersion from source JSON

This commit is contained in:
nythepegasus
2024-05-09 00:20:30 -04:00
committed by ny
parent d2f0409452
commit 4667841c8d

View File

@@ -54,6 +54,8 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
case localizedDescription case localizedDescription
case downloadURL case downloadURL
case size case size
case minOSVersion
case maxOSVersion
} }
public required init(from decoder: Decoder) throws public required init(from decoder: Decoder) throws
@@ -72,6 +74,9 @@ public class AppVersion: NSManagedObject, Decodable, Fetchable
self.downloadURL = try container.decode(URL.self, forKey: .downloadURL) self.downloadURL = try container.decode(URL.self, forKey: .downloadURL)
self.size = try container.decode(Int64.self, forKey: .size) self.size = try container.decode(Int64.self, forKey: .size)
self._minOSVersion = try container.decodeIfPresent(String.self, forKey: .minOSVersion)
self._maxOSVersion = try container.decodeIfPresent(String.self, forKey: .maxOSVersion)
} }
catch catch
{ {
@@ -115,6 +120,11 @@ public extension AppVersion
} }
var isSupported: Bool { var isSupported: Bool {
if let minOSVersion = self.minOSVersion, !ProcessInfo.processInfo.isOperatingSystemAtLeast(minOSVersion) {
return false
} else if let maxOSVersion = self.maxOSVersion, ProcessInfo.processInfo.operatingSystemVersion > maxOSVersion {
return false
}
return true return true
} }
} }