Skip to content

Commit

Permalink
Improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
F1248 committed Dec 30, 2024
1 parent f4f5ca5 commit 1be55ac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
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.value : 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
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 @@ -61,15 +61,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.value = applicable ?? true ? value() : nil
self.applicable = applicable
}

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

0 comments on commit 1be55ac

Please sign in to comment.