Skip to content

Commit

Permalink
Merge branch 'deployment-target-macos-13' into deployment-target-maco…
Browse files Browse the repository at this point in the history
…s-14
  • Loading branch information
F1248 committed Dec 31, 2024
2 parents bb2cfe4 + ff29746 commit c91003d
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Genius/Extensions/Foundation/Pipe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import Foundation
extension Pipe {

func read() -> String? {
String(try? fileHandleForReading.readToEnd())
try? String(fileHandleForReading.readToEnd())
}
}
25 changes: 13 additions & 12 deletions Genius/Extensions/Swift/Bool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@ extension Bool: DataInitializable {
}
}

init?(_ string: Any?) {
guard let string = (string as? String)?.lowercased() else { return nil }
if string.contains(any: [
"no",
"false",
"disabled",
"spfirewall_globalstate_allow_all",
]) {
self = false
} else if string.contains(any: [
init?(_ string: String?) {
guard
let string = string.map({ $0[($0.range(of: ":", options: .backwards)?.upperBound ?? $0.startIndex)...] })?.lowercased()
else { return nil }
if string.contains(anyWholeWord: [
"yes",
"on",
"true",
"enabled",
"spfirewall_globalstate_limit_connections",
"spfirewall_globalstate_block_all",
]) {
self = true
} else if string.contains(anyWholeWord: [
"no",
"off",
"false",
"disabled",
]) {
self = false
} else { return nil }
}
}
Expand Down
8 changes: 6 additions & 2 deletions Genius/Extensions/Swift/StringProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ extension StringProtocol {
self.init(data)
}

func contains(any strings: [some StringProtocol]) -> Bool {
strings.contains(where: contains)
func contains(anyWholeWord strings: [String]) -> Bool {
strings.contains { contains(wholeWord: $0) }
}

func contains(wholeWord: String) -> Bool {
components(separatedBy: .alphanumerics.inverted).contains(wholeWord)
}

func remove(_ string: some StringProtocol) -> String {
Expand Down
1 change: 0 additions & 1 deletion Genius/Models/Helpers/SystemProfiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Foundation

enum SystemProfiler {

static let firewall = get("Firewall")
static let hardware = get("Hardware")
static let software = get("Software")

Expand Down
2 changes: 1 addition & 1 deletion Genius/Models/SystemInformation/Hardware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ extension SystemInformation {
static let hardwareUUID =
SystemInformationData<String?>(IORegistry(class: "IOPlatformExpertDevice").read(kIOPlatformUUIDKey))
static let provisioningUDID = SystemInformationData<String?>(
{ SystemProfiler.hardware?["provisioning_UDID"] ?? (CPU.type.value == .intel ? hardwareUUID : nil) },
{ SystemProfiler.hardware?["provisioning_UDID"] as? String ?? (CPU.type.value == .intel ? hardwareUUID.value : nil) },
applicable: Software.OS.bootMode.value !=? .recovery ||? CPU.type.value == .intel
)
}
Expand Down
8 changes: 4 additions & 4 deletions Genius/Models/SystemInformation/MaintenanceChecks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension SystemInformation {

static let activationLock = SystemInformationData<Bool?>(
{ IORegistry(class: "IODTNVRAMVariables").keyExists("fmm-mobileme-token-FMM") },
applicable: Hardware.securityChip.value >=? .t2
applicable: Hardware.securityChip.value >=? .t2 &&? !?Hardware.Model.isVirtualMachine.value
)
static let firmwarePassword = SystemInformationData<Bool?>(
{ Bool(Process("/usr/sbin/firmwarepasswd", ["-check"], requiresRoot: true)?.runSafe()) },
Expand All @@ -27,19 +27,19 @@ extension SystemInformation {
enum DataSecurity {

static let fileVault = SystemInformationData<Bool?>(
{ Bool(Process("/usr/bin/fdesetup", ["isactive"])?.runSafe()) },
{ Bool(Process("/usr/bin/fdesetup", ["status"])?.runSafe()) },
applicable: Software.OS.bootMode.value !=? .recovery
)
}

enum MalwareProtection {

static let systemIntegrityProtection = SystemInformationData<Bool?>(
{ Bool(SystemProfiler.software?["system_integrity"]) },
{ Bool(Process("/usr/bin/csrutil", ["status"])?.runSafe()) },
applicable: Software.OS.bootMode.value !=? .recovery
)
static let firewall = SystemInformationData<Bool?>(
{ Bool(SystemProfiler.firewall?["spfirewall_globalstate"]) },
{ Bool(Process("/usr/libexec/ApplicationFirewall/socketfilterfw", ["--getglobalstate"])?.runSafe()) },
applicable: Software.OS.bootMode.value !=? .recovery
)
static let gatekeeper = SystemInformationData<Bool?>(Bool(Process("/usr/sbin/spctl", ["--status"])?.runSafe()))
Expand Down
19 changes: 12 additions & 7 deletions Genius/Models/SystemInformation/Software.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ extension SystemInformation {
enum SMC {

static let version = SystemInformationData<String?>(
{ SystemProfiler.hardware?["SMC_version_system"] },
{ SystemProfiler.hardware?["SMC_version_system"] as? String },
applicable: Hardware.securityChip.value <=? .t1 &&? OS.bootMode.value !=? .recovery
)
}

enum Firmware {

static let version = SystemInformationData<String?>(
{ SystemProfiler.hardware?["boot_rom_version"] },
{ SystemProfiler.hardware?["boot_rom_version"] as? String },
applicable: OS.bootMode.value !=? .recovery
)
}
Expand Down Expand Up @@ -55,15 +55,20 @@ extension SystemInformation {
safe ? .safe : .normal
} else { nil }
}())
static let bootVolume =
SystemInformationData<String?>({ SystemProfiler.software?["boot_volume"] }, applicable: bootMode.value !=? .recovery)
static let loaderVersion =
SystemInformationData<String?>({ SystemProfiler.hardware?["os_loader_version"] }, applicable: bootMode.value !=? .recovery)
static let bootVolume = SystemInformationData<String?>(
{ SystemProfiler.software?["boot_volume"] as? String },
applicable: bootMode.value !=? .recovery
)
static let loaderVersion = SystemInformationData<String?>(
{ SystemProfiler.hardware?["os_loader_version"] as? String },
applicable: bootMode.value !=? .recovery
)
}

enum Computer {

static let name = SystemInformationData<String?>(SystemProfiler.software?["local_host_name"] ?? Host.current().localizedName)
static let name =
SystemInformationData<String?>(SystemProfiler.software?["local_host_name"] as? String ?? Host.current().localizedName)
static let hostName = SystemInformationData<String?>(Sysctl.read("kern.hostname"))
}

Expand Down
9 changes: 0 additions & 9 deletions Genius/Models/SystemInformation/SystemInformationData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@ struct SystemInformationData<T: Sendable>: SystemInformationDataProtocol {
self.applicable = true
}

init<W>(_ value: Any?) where T == W? {
self.init(value as? W)
}

init<W>(_ value: () -> T, applicable: Bool?) where T == W? {
self.applicable = applicable
self.value = applicable ?? true ? value() : nil
}

init<W>(_ value: () -> Any?, applicable: Bool?) where T == W? {
self.applicable = applicable
self.value = applicable ?? true ? value() as? W : nil
}
}
2 changes: 1 addition & 1 deletion Genius/Views/Maintenance/MaintenanceDataView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct MaintenanceDataView: View {
}
.frame(width: 512)
}
.padding(.bottom)
.padding()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct SystemInformationTabView: View {
}
.frame(width: 512)
}
.padding(.bottom)
.padding()
}
}
}

0 comments on commit c91003d

Please sign in to comment.