From 50f08295a4b460f65286d1d04b32ac9c5e0715c9 Mon Sep 17 00:00:00 2001 From: Jeormy Fu Date: Sat, 8 Oct 2022 22:41:56 -0700 Subject: [PATCH] check release info based on arch --- LomoAgent/LomoUpgrade.swift | 8 +++++++- LomoAgent/utils.swift | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/LomoAgent/LomoUpgrade.swift b/LomoAgent/LomoUpgrade.swift index a26147f..ac852b5 100644 --- a/LomoAgent/LomoUpgrade.swift +++ b/LomoAgent/LomoUpgrade.swift @@ -207,7 +207,13 @@ class LomoUpgrade { if httpresp.statusCode == 200, let jsonResult = try? JSONSerialization.jsonObject(with: data) as? [String: Any] { DDLogInfo("needUpdateLomoupgAndLomoAgent, json response: \(jsonResult!)") - if let osxConf = jsonResult?["darwin"] as? [String: Any] { + let hardwareType = GetMachineHardwareName() + var configName = "darwin" + if hardwareType == "arm64" { + configName += "-m1" + } + + if let osxConf = jsonResult?[configName] as? [String: Any] { guard let agentSha256 = osxConf["SHA256"] as? String, let agentVer = osxConf["Version"] as? String, diff --git a/LomoAgent/utils.swift b/LomoAgent/utils.swift index 41ae85b..e066907 100644 --- a/LomoAgent/utils.swift +++ b/LomoAgent/utils.swift @@ -342,3 +342,12 @@ func isPortOpen(port: in_port_t) -> Bool { Darwin.close(socketFileDescriptor) return isOpen } + +func GetMachineHardwareName() -> String? { + var sysInfo = utsname() + let retVal = uname(&sysInfo) + + guard retVal == EXIT_SUCCESS else { return nil } + + return String(cString: &sysInfo.machine.0, encoding: .utf8) +}