From 380a6acfd1de5eb540f575c3f13096cc9b431d21 Mon Sep 17 00:00:00 2001 From: Joe Barbere Date: Tue, 14 Feb 2023 01:00:32 -0500 Subject: [PATCH] Use semver library for version checks (#843) Co-authored-by: Thomas Ricouard --- IceCubesApp.xcodeproj/project.pbxproj | 17 +++++++++++++++++ .../xcshareddata/swiftpm/Package.resolved | 9 +++++++++ Packages/Env/Package.swift | 2 ++ .../Env/Sources/Env/CurrentInstance.swift | 19 +++++++------------ 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/IceCubesApp.xcodeproj/project.pbxproj b/IceCubesApp.xcodeproj/project.pbxproj index fbc7218c..ab022b3b 100644 --- a/IceCubesApp.xcodeproj/project.pbxproj +++ b/IceCubesApp.xcodeproj/project.pbxproj @@ -82,6 +82,7 @@ 9FE3DB57296FEFCA00628CB0 /* AppAccount in Frameworks */ = {isa = PBXBuildFile; productRef = 9FE3DB56296FEFCA00628CB0 /* AppAccount */; }; C9B22677297F6C2E001F9EFE /* ContentSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9B22676297F6C2E001F9EFE /* ContentSettingsView.swift */; }; D08A9C3529956CFA00204A4A /* SwipeActionsSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08A9C3429956CFA00204A4A /* SwipeActionsSettingsView.swift */; }; + D8A16D0B299B4ACD00840104 /* SemVer in Frameworks */ = {isa = PBXBuildFile; productRef = D8A16D0A299B4ACD00840104 /* SemVer */; }; E92817FA298443D600875FD1 /* Models in Frameworks */ = {isa = PBXBuildFile; productRef = E92817F9298443D600875FD1 /* Models */; }; E92817FC298443D600875FD1 /* Network in Frameworks */ = {isa = PBXBuildFile; productRef = E92817FB298443D600875FD1 /* Network */; }; E92817FE29844DB700875FD1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E92817FD29844DB700875FD1 /* Assets.xcassets */; }; @@ -275,6 +276,7 @@ buildActionMask = 2147483647; files = ( 9F7335EF29674F7100AFF0BA /* QuickLook.framework in Frameworks */, + D8A16D0B299B4ACD00840104 /* SemVer in Frameworks */, 9F7335ED2967463400AFF0BA /* AVKit.framework in Frameworks */, 9F2A540C29699705009B2D7C /* RevenueCat in Frameworks */, 065FA1FE29866CD600012EA0 /* LRUCache in Frameworks */, @@ -591,6 +593,7 @@ 9F2A540B29699705009B2D7C /* RevenueCat */, 9FE3DB56296FEFCA00628CB0 /* AppAccount */, 065FA1FD29866CD600012EA0 /* LRUCache */, + D8A16D0A299B4ACD00840104 /* SemVer */, ); productName = IceCubesApp; productReference = 9FBFE639292A715500C250E9 /* IceCubesApp.app */; @@ -669,6 +672,7 @@ 9FAE4ACC29379A5A00772766 /* XCRemoteSwiftPackageReference "keychain-swift" */, 9F2A540829699705009B2D7C /* XCRemoteSwiftPackageReference "purchases-ios" */, 065FA1FC29866CD600012EA0 /* XCRemoteSwiftPackageReference "LRUCache" */, + D8A16D09299B4ACD00840104 /* XCRemoteSwiftPackageReference "semver" */, ); productRefGroup = 9FBFE63A292A715500C250E9 /* Products */; projectDirPath = ""; @@ -1355,6 +1359,14 @@ kind = branch; }; }; + D8A16D09299B4ACD00840104 /* XCRemoteSwiftPackageReference "semver" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/sersoft-gmbh/semver"; + requirement = { + kind = exactVersion; + version = 3.4.0; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -1473,6 +1485,11 @@ isa = XCSwiftPackageProductDependency; productName = AppAccount; }; + D8A16D0A299B4ACD00840104 /* SemVer */ = { + isa = XCSwiftPackageProductDependency; + package = D8A16D09299B4ACD00840104 /* XCRemoteSwiftPackageReference "semver" */; + productName = SemVer; + }; E92817F9298443D600875FD1 /* Models */ = { isa = XCSwiftPackageProductDependency; productName = Models; diff --git a/IceCubesApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/IceCubesApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index cfcdc057..066bbe0f 100644 --- a/IceCubesApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/IceCubesApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -63,6 +63,15 @@ "version" : "4.16.0" } }, + { + "identity" : "semver", + "kind" : "remoteSourceControl", + "location" : "https://github.com/sersoft-gmbh/semver", + "state" : { + "revision" : "92c23d5fa4a920b81a34d68594528c327cf599f1", + "version" : "3.4.0" + } + }, { "identity" : "sqlite.swift", "kind" : "remoteSourceControl", diff --git a/Packages/Env/Package.swift b/Packages/Env/Package.swift index 26cb788c..e02524b8 100644 --- a/Packages/Env/Package.swift +++ b/Packages/Env/Package.swift @@ -18,6 +18,7 @@ let package = Package( dependencies: [ .package(name: "Models", path: "../Models"), .package(name: "Network", path: "../Network"), + .package(url: "https://github.com/sersoft-gmbh/semver", from: "3.4.0"), .package(url: "https://github.com/evgenyneu/keychain-swift", branch: "master"), ], targets: [ @@ -26,6 +27,7 @@ let package = Package( dependencies: [ .product(name: "Models", package: "Models"), .product(name: "Network", package: "Network"), + .product(name: "SemVer", package: "semver"), .product(name: "KeychainSwift", package: "keychain-swift"), ] ), diff --git a/Packages/Env/Sources/Env/CurrentInstance.swift b/Packages/Env/Sources/Env/CurrentInstance.swift index 558f6346..eec6250d 100644 --- a/Packages/Env/Sources/Env/CurrentInstance.swift +++ b/Packages/Env/Sources/Env/CurrentInstance.swift @@ -1,6 +1,7 @@ import Foundation import Models import Network +import SemVer @MainActor public class CurrentInstance: ObservableObject { @@ -10,27 +11,21 @@ public class CurrentInstance: ObservableObject { public static let shared = CurrentInstance() - private var version: Float { - if let stringVersion = instance?.version { - if stringVersion.utf8.count > 2 { - return Float(stringVersion.prefix(3)) ?? 0 - } else { - return Float(stringVersion.prefix(1)) ?? 0 - } - } - return 0 + private var version: Version { + let stringVersion = instance?.version ?? "0" + return Version(stringVersion)! } public var isFiltersSupported: Bool { - version >= 4 + version >= Version("4")! } public var isEditSupported: Bool { - version >= 4 + version >= Version("4")! } public var isEditAltTextSupported: Bool { - version >= 4.1 + version >= Version("4.1")! } private init() {}