Skip to content

Commit

Permalink
chore: update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Sep 1, 2023
1 parent 80cbc0b commit 6fd272d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions MailCore/API/MailApiFetcher/MailApiFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import Sentry
import UIKit

// TODO: move to Core and share with kDrive
struct UserAgentBuilder {
func modelIdentifier() -> String {
/// Something to construct a standard Infomaniak User-Agent
public struct UserAgentBuilder {
func modelIdentifier() -> String? {
if let simulatorModelIdentifier = ProcessInfo()
.environment["SIMULATOR_MODEL_IDENTIFIER"] { return simulatorModelIdentifier }
var sysinfo = utsname()
uname(&sysinfo) // ignore return value
return String(bytes: Data(bytes: &sysinfo.machine,
count: Int(_SYS_NAMELEN)), encoding: .ascii)!
count: Int(_SYS_NAMELEN)), encoding: .ascii)?
.trimmingCharacters(in: .controlCharacters)
}

Expand All @@ -44,28 +45,30 @@ struct UserAgentBuilder {
return String(cString: archRaw)
}

var userAgent: String {
/// The standard infomaniak app user agent
public var userAgent: String {
let release = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "x.x.x"
let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "x"

let executableName = Bundle.main.bundleIdentifier ?? "com.infomaniak.x"
let appVersion = "\(release)-\(build)"
let hardwareDevice = modelIdentifier()
let hardwareDevice = modelIdentifier() ?? "unknownModel"

let processInfo = ProcessInfo.processInfo
let operatingSystemVersion = ProcessInfo.processInfo.operatingSystemVersion
let OSNameAndVersion =
"\(UIDevice.current.systemName) \(processInfo.operatingSystemVersion.majorVersion).\(processInfo.operatingSystemVersion.minorVersion).\(processInfo.operatingSystemVersion.patchVersion)"
"\(UIDevice.current.systemName) \(operatingSystemVersion.majorVersion).\(operatingSystemVersion.minorVersion).\(operatingSystemVersion.patchVersion)"

let cpuArchitecture = microarchitecture() ?? "unknownArch"

/// Something like:
/// `com.infomaniak.mail/1.0.5-1 (iPhone15,2; iOS16.4.0)`
/// `com.infomaniak.mail.ShareExtension/1.0.5-1 (iPhone15,2; iOS16.4.0)`
/// `com.infomaniak.mail/1.0.5-1 (iPhone15,2; iOS16.4.0; arm64e)`
/// `com.infomaniak.mail.ShareExtension/1.0.5-1 (iPhone15,2; iOS16.4.0; arm64e)`
let userAgent = "\(executableName)/\(appVersion) (\(hardwareDevice); \(OSNameAndVersion); \(cpuArchitecture))"
return userAgent
}
}

/// Something to set the user agent for AF requests
public class UserAgentAdapter: RequestAdapter {
public static let userAgentKey = "User-Agent"

Expand Down

0 comments on commit 6fd272d

Please sign in to comment.