diff --git a/Package.resolved b/Package.resolved index cc7ad8c..dcbff31 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Alamofire/Alamofire", "state" : { - "revision" : "3dc6a42c7727c49bf26508e29b0a0b35f9c7e1ad", - "version" : "5.8.1" + "revision" : "723fa5a6c65812aec4a0d7cc432ee198883b6e00", + "version" : "5.9.0" } }, { @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/CocoaLumberjack/CocoaLumberjack", "state" : { - "revision" : "363ed23d19a931809ea834a7d722da830353806a", - "version" : "3.8.2" + "revision" : "4b8714a7fb84d42393314ce897127b3939885ec3", + "version" : "3.8.5" } }, { @@ -32,8 +32,17 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Infomaniak/ios-login", "state" : { - "revision" : "904c1ac39b4db56212302b464a0b2e023d9b5791", - "version" : "6.0.0" + "revision" : "94dee9d95d92c5fbe152476b78b04985fbddaa7c", + "version" : "6.0.1" + } + }, + { + "identity" : "osinfo", + "kind" : "remoteSourceControl", + "location" : "https://github.com/MarcoEidinger/OSInfo.git", + "state" : { + "revision" : "54fd6673923ef5966268918152235b0e15ed057c", + "version" : "1.0.1" } }, { @@ -41,8 +50,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/realm/realm-core.git", "state" : { - "revision" : "7227d6a447821c28895daa099b6c7cd4c99d461b", - "version" : "13.25.1" + "revision" : "a5e87a39cffdcc591f3203c11cfca68100d0b9a6", + "version" : "13.26.0" } }, { @@ -50,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/realm/realm-swift", "state" : { - "revision" : "836cc4b8619886f979f8961c3f592a82b0741591", - "version" : "10.45.3" + "revision" : "7a2f7d41ffa409978a6b5e475c2ee57f08222705", + "version" : "10.48.0" } }, { @@ -59,17 +68,17 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/getsentry/sentry-cocoa", "state" : { - "revision" : "3b9a8e69ca296bd8cd0e317ad7a448e5daf4a342", - "version" : "8.18.0" + "revision" : "38f4f70d07117b9f958a76b1bff278c2f29ffe0e", + "version" : "8.21.0" } }, { "identity" : "swift-log", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-log.git", + "location" : "https://github.com/apple/swift-log", "state" : { - "revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed", - "version" : "1.5.3" + "revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5", + "version" : "1.5.4" } }, { @@ -77,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/weichsel/ZIPFoundation.git", "state" : { - "revision" : "a3f5c2bae0f04b0bce9ef3c4ba6bd1031a0564c4", - "version" : "0.9.17" + "revision" : "b979e8b52c7ae7f3f39fa0182e738e9e7257eb78", + "version" : "0.9.18" } } ], diff --git a/Package.swift b/Package.swift index 1ac21f0..285b587 100644 --- a/Package.swift +++ b/Package.swift @@ -22,7 +22,8 @@ let package = Package( .package(url: "https://github.com/getsentry/sentry-cocoa", .upToNextMajor(from: "8.18.0")), .package(url: "https://github.com/realm/realm-swift", .upToNextMajor(from: "10.45.0")), .package(url: "https://github.com/CocoaLumberjack/CocoaLumberjack", .upToNextMajor(from: "3.8.0")), - .package(url: "https://github.com/weichsel/ZIPFoundation.git", .upToNextMajor(from: "0.9.0")) + .package(url: "https://github.com/weichsel/ZIPFoundation.git", .upToNextMajor(from: "0.9.0")), + .package(url: "https://github.com/MarcoEidinger/OSInfo.git", .upToNextMajor(from: "1.0.0")) ], targets: [ .target( @@ -34,6 +35,7 @@ let package = Package( .product(name: "Sentry", package: "sentry-cocoa"), .product(name: "RealmSwift", package: "realm-swift"), .product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"), + .product(name: "OSInfo", package: "OSInfo"), ] ), .testTarget( diff --git a/Sources/InfomaniakCore/Platform/CorePlatform.swift b/Sources/InfomaniakCore/Platform/CorePlatform.swift new file mode 100644 index 0000000..eec2e84 --- /dev/null +++ b/Sources/InfomaniakCore/Platform/CorePlatform.swift @@ -0,0 +1,36 @@ +/* + Infomaniak Core - iOS + Copyright (C) 2024 Infomaniak Network SA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +import Foundation +import OSInfo + +public enum CorePlatform { + + /// Unified version descriptor for IK platform apps + public static func appVersionLabel(fallbackAppName: String) -> String { + let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String? ?? fallbackAppName + let release = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String? ?? "x.x" + let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String? ?? "x" + let betaRelease = Bundle.main.isRunningInTestFlight ? "beta" : "" + + // Returns "macOS" on unmodified iOS and catalyst apps running on macOS + let systemName = OS.current.name + + return "\(appName) \(systemName) version \(release)-\(betaRelease)\(build)" + } +} diff --git a/Sources/InfomaniakCore/Platform/PlatformDetectable.swift b/Sources/InfomaniakCore/Platform/PlatformDetectable.swift new file mode 100644 index 0000000..d4ac92e --- /dev/null +++ b/Sources/InfomaniakCore/Platform/PlatformDetectable.swift @@ -0,0 +1,72 @@ +/* + Infomaniak Core - iOS + Copyright (C) 2024 Infomaniak Network SA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +import Foundation + +/// Something to help with current running context +public protocol PlatformDetectable { + /// We are running in Mac Catalyst mode + var isMacCatalyst: Bool { get } + + /// We are running an iOS App on Mac + var isiOSAppOnMac: Bool { get } + + /// We are running on Mac + var isMac: Bool { get } + + /// We are running in extension mode + var isInExtension: Bool { get } + + /// We are running a debug build + var isDebug: Bool { get } +} + +@available(macOS 10.16, iOS 14.0, tvOS 14.0, watchOS 7.0, *) +public struct PlatformDetector: PlatformDetectable { + public init() {} + + public var isMacCatalyst: Bool = { + #if targetEnvironment(macCatalyst) + true + #else + false + #endif + }() + + public var isiOSAppOnMac: Bool = ProcessInfo().isiOSAppOnMac + + public var isMac: Bool { + isMacCatalyst || isiOSAppOnMac + } + + public var isInExtension: Bool = { + guard Bundle.main.bundlePath.hasSuffix(".appex") else { + return false + } + + return true + }() + + public var isDebug: Bool = { + #if DEBUG + true + #else + false + #endif + }() +} diff --git a/Tests/InfomaniakCoreTests/Platform/UTCorePlatform.swift b/Tests/InfomaniakCoreTests/Platform/UTCorePlatform.swift new file mode 100644 index 0000000..59ddba2 --- /dev/null +++ b/Tests/InfomaniakCoreTests/Platform/UTCorePlatform.swift @@ -0,0 +1,34 @@ +/* + Infomaniak Core - iOS + Copyright (C) 2024 Infomaniak Network SA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +import InfomaniakCore +import XCTest + +final class UTCorePlatform: XCTestCase { + + func testVersionLabel() { + // GIVEN + let expectedPrefix = "xctest macOS version" + + // WHEN + let versionLabel = CorePlatform.appVersionLabel(fallbackAppName: "xctest") + + // THEN + XCTAssertTrue(versionLabel.hasPrefix(expectedPrefix)) + } +}