Skip to content

Commit

Permalink
feat: UserAgentBuilder macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed Dec 5, 2023
1 parent 618a341 commit 5febafe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#if canImport(UIKit)

import Alamofire
import Foundation

Expand All @@ -41,5 +39,3 @@ public class UserAgentAdapter: RequestAdapter {
completion(.success(adaptedRequest))
}
}

#endif
13 changes: 8 additions & 5 deletions Sources/InfomaniakCore/Networking/UserAgentBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#if canImport(UIKit)

import Foundation
import MachO
#if canImport(UIKit)
import UIKit
#endif

/// Something to construct a standard Infomaniak User-Agent
public struct UserAgentBuilder {
Expand Down Expand Up @@ -56,8 +56,13 @@ public struct UserAgentBuilder {
let hardwareDevice = modelIdentifier() ?? "unknownModel"

let operatingSystemVersion = ProcessInfo.processInfo.operatingSystemVersion
#if canImport(UIKit)
let osName = UIDevice.current.systemName
#else
let osName = "macOS"
#endif
let operatingSystemNameAndVersion =
"\(UIDevice.current.systemName) \(operatingSystemVersion.majorVersion).\(operatingSystemVersion.minorVersion).\(operatingSystemVersion.patchVersion)"
"\(osName) \(operatingSystemVersion.majorVersion).\(operatingSystemVersion.minorVersion).\(operatingSystemVersion.patchVersion)"

let cpuArchitecture = microarchitecture() ?? "unknownArch"

Expand All @@ -67,5 +72,3 @@ public struct UserAgentBuilder {
return "\(executableName)/\(appVersion) (\(hardwareDevice); \(operatingSystemNameAndVersion); \(cpuArchitecture))"
}
}

#endif

0 comments on commit 5febafe

Please sign in to comment.