Skip to content

Commit

Permalink
Create CopyCellType and replace usages of CopyCellView with it (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
twodayslate authored Jan 3, 2023
1 parent 81105ac commit 721d2d1
Show file tree
Hide file tree
Showing 35 changed files with 784 additions and 464 deletions.
76 changes: 72 additions & 4 deletions ec3730.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions ec3730/Extensions/Encodable+dictionary.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Encodable.swift
// ec3730
//
// Created by Zachary Gorak on 12/29/22.
// Copyright © 2022 Zachary Gorak. All rights reserved.
//

import Foundation

extension Encodable {
var dictionary: [String: Any]? {
guard let data = try? JSONEncoder().encode(self) else { return nil }
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? [String: Any] }
}
}
31 changes: 31 additions & 0 deletions ec3730/Extensions/UIImage+Codable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import UIKit

enum UIImageDecodingError: Error {
case unableToCreateImage
case unableToGetImageData
}

public extension Decodable where Self: UIImage {
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let data = try container.decode(Data.self)
if let image = Self(data: data) {
self = image
}
throw UIImageDecodingError.unableToCreateImage
}
}

public extension Encodable where Self: UIImage {
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
if let data = pngData() {
try container.encode(data)
} else if let data = jpegData(compressionQuality: 1.0) {
try container.encode(data)
}
throw UIImageDecodingError.unableToGetImageData
}
}

extension UIImage: Codable {}
2 changes: 1 addition & 1 deletion ec3730/Models/Device/DeviceInfoSectionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI
class DeviceInfoSectionModel: ObservableObject, Identifiable {
var title: String = ""
@MainActor @Published var enabled: Bool = false
@MainActor @Published var rows = [CopyCellView]()
@MainActor @Published var rows = [CopyCellType]()

@MainActor func reload() {}
}
16 changes: 8 additions & 8 deletions ec3730/Models/Device/Sections/CarrierInfoModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ class CarrierInfoModel: DeviceInfoSectionModel {
}

if let value = networkInfo.dataServiceIdentifier {
rows.append(CopyCellView(title: "Data Service Identifier", content: value))
rows.append(.row(title: "Data Service Identifier", content: value))
}

if let value = networkInfo.serviceCurrentRadioAccessTechnology {
for item in value {
rows.append(CopyCellView(title: "Data Service \(item.key) Radio Access Technology", content: item.value))
rows.append(.row(title: "Data Service \(item.key) Radio Access Technology", content: item.value))
}
}

for (i, carrier) in providers.enumerated() {
if let name = carrier.value.carrierName {
rows.append(CopyCellView(title: "Provider \(i) Carrier Name", content: name))
rows.append(.row(title: "Provider \(i) Carrier Name", content: name))
}
rows.append(CopyCellView(title: "Provider \(i) Service", content: carrier.key))
rows.append(CopyCellView(title: "Provider \(i) Allows VOIP", content: carrier.value.allowsVOIP ? "Yes" : "No"))
rows.append(.row(title: "Provider \(i) Service", content: carrier.key))
rows.append(.row(title: "Provider \(i) Allows VOIP", content: carrier.value.allowsVOIP ? "Yes" : "No"))
if let value = carrier.value.isoCountryCode {
rows.append(CopyCellView(title: "Provider \(i) ISO Country Code", content: value))
rows.append(.row(title: "Provider \(i) ISO Country Code", content: value))
}
if let value = carrier.value.mobileCountryCode {
rows.append(CopyCellView(title: "Provider \(i) Mobile Country Code", content: value))
rows.append(.row(title: "Provider \(i) Mobile Country Code", content: value))
}
if let value = carrier.value.mobileNetworkCode {
rows.append(CopyCellView(title: "Provider \(i) Mobile Network Code", content: value))
rows.append(.row(title: "Provider \(i) Mobile Network Code", content: value))
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions ec3730/Models/Device/Sections/DataUsageInfoModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ class DataUsageInfoModel: DeviceInfoSectionModel {
enabled = true
SystemDataUsage.reload()
rows.removeAll()
rows.append(CopyCellView(title: "Wifi", rows: [CopyCellRow(title: "Sent", content: SystemDataUsage.wifiSent), CopyCellRow(title: "Received", content: SystemDataUsage.wifiReceived), CopyCellRow(title: "Total", content: SystemDataUsage.wifiTotal)]))
rows.append(CopyCellView(title: "Cellular", rows: [CopyCellRow(title: "Sent", content: SystemDataUsage.wwanSent), CopyCellRow(title: "Received", content: SystemDataUsage.wwanReceived), CopyCellRow(title: "Total", content: SystemDataUsage.wwanTotal)]))
rows.append(.multiple(title: "Wifi", contents: [
.row(title: "Sent", content: SystemDataUsage.wifiSent, style: .expandable),
.row(title: "Received", content: SystemDataUsage.wifiReceived, style: .expandable),
.row(title: "Total", content: SystemDataUsage.wifiTotal, style: .expandable),
]))
rows.append(.multiple(title: "Cellular", contents: [
.row(title: "Sent", content: SystemDataUsage.wwanSent, style: .expandable),
.row(title: "Received", content: SystemDataUsage.wwanReceived, style: .expandable),
.row(title: "Total", content: SystemDataUsage.wwanTotal, style: .expandable),
]))
}
}
2 changes: 1 addition & 1 deletion ec3730/Models/Device/Sections/FingerprintInfoModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FingerprintInfoModel: DeviceInfoSectionModel {
rows.removeAll()

for (i, model) in models.enumerated() {
rows.append(CopyCellView(title: "Fingerprint \(i)", content: model.fingerprint ?? "-"))
rows.append(.row(title: "Fingerprint \(i)", content: model.fingerprint ?? "-"))
}
}
}
28 changes: 14 additions & 14 deletions ec3730/Models/Device/Sections/JavaScriptInfoModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,59 +21,59 @@ class JavaScriptInfoModel: DeviceInfoSectionModel {
}

if let pi = context.evaluateScript("Math.PI"), pi.isNumber {
rows.append(CopyCellView(title: "PI", content: "\(pi.toDouble())"))
rows.append(.row(title: "PI", content: "\(pi.toDouble())"))
}

if let value = context.evaluateScript("Math.E"), value.isNumber {
rows.append(CopyCellView(title: "Euler's constant", content: "\(value.toDouble())"))
rows.append(.row(title: "Euler's constant", content: "\(value.toDouble())"))
}

if let value = context.evaluateScript("Math.random()"), value.isNumber {
rows.append(CopyCellView(title: "Random", content: "\(value.toDouble())"))
rows.append(.row(title: "Random", content: "\(value.toDouble())"))
}

if let value = context.evaluateScript("Math.log(2)"), value.isNumber {
rows.append(CopyCellView(title: "Natural log of 2", content: "\(value.toDouble())"))
rows.append(.row(title: "Natural log of 2", content: "\(value.toDouble())"))
}

if let value = context.evaluateScript("Math.log(10)"), value.isNumber {
rows.append(CopyCellView(title: "Natural log of 10", content: "\(value.toDouble())"))
rows.append(.row(title: "Natural log of 10", content: "\(value.toDouble())"))
}

if let value = context.evaluateScript("Math.log2(10)"), value.isNumber {
rows.append(CopyCellView(title: "Base 2 logarithm of 10", content: "\(value.toDouble())"))
rows.append(.row(title: "Base 2 logarithm of 10", content: "\(value.toDouble())"))
}

if let value = context.evaluateScript("Math.log2(Math.E)"), value.isNumber {
rows.append(CopyCellView(title: "Base 2 logarithm of E", content: "\(value.toDouble())"))
rows.append(.row(title: "Base 2 logarithm of E", content: "\(value.toDouble())"))
}

if let value = context.evaluateScript("Math.sqrt(2)"), value.isNumber {
rows.append(CopyCellView(title: "Square root of 2", content: "\(value.toDouble())"))
rows.append(.row(title: "Square root of 2", content: "\(value.toDouble())"))
}

if let value = context.evaluateScript("Math.sqrt(1/2)"), value.isNumber {
rows.append(CopyCellView(title: "Square root of 1/2", content: "\(value.toDouble())"))
rows.append(.row(title: "Square root of 1/2", content: "\(value.toDouble())"))
}

if let value = context.evaluateScript("Number.MAX_SAFE_INTEGER"), value.isNumber, let str = value.toNumber()?.stringValue {
rows.append(CopyCellView(title: "Maxmimum Safe Integer", content: str))
rows.append(.row(title: "Maxmimum Safe Integer", content: str))
}

if let value = context.evaluateScript("Number.MIN_SAFE_INTEGER"), value.isNumber, let str = value.toNumber()?.stringValue {
rows.append(CopyCellView(title: "Minimum Safe Integer", content: str))
rows.append(.row(title: "Minimum Safe Integer", content: str))
}

if let value = context.evaluateScript("Number.EPSILON"), value.isNumber, let str = value.toNumber()?.stringValue {
rows.append(CopyCellView(title: "Epsilon", content: str))
rows.append(.row(title: "Epsilon", content: str))
}

if let value = context.evaluateScript("Number.MAX_VALUE"), value.isNumber {
rows.append(CopyCellView(title: "Maximum Value", content: "\(value.toDouble())"))
rows.append(.row(title: "Maximum Value", content: "\(value.toDouble())"))
}

if let value = context.evaluateScript("Number.MIN_VALUE"), value.isNumber {
rows.append(CopyCellView(title: "Minimum Value", content: "\(value.toDouble())"))
rows.append(.row(title: "Minimum Value", content: "\(value.toDouble())"))
}
}
}
6 changes: 3 additions & 3 deletions ec3730/Models/Device/Sections/MemoryInfoModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ class MemoryInfoModel: DeviceInfoSectionModel {
enabled = true
rows.removeAll()

rows.append(CopyCellView(title: "Memory Footprint", content: formattedMemoryFootprint()))
rows.append(.row(title: "Memory Footprint", content: formattedMemoryFootprint()))

let (kern_result, page_size) = ggsdf()
if kern_result == KERN_SUCCESS {
rows.append(CopyCellView(title: "Page Size", content: "\(page_size) bytes"))
rows.append(.row(title: "Page Size", content: "\(page_size) bytes"))
}
let stats = vm_stat()

for key in tags {
if let val = stats[key] {
rows.append(CopyCellView(title: key, content: String(format: "%d MB", val)))
rows.append(.row(title: key, content: String(format: "%d MB", val)))
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions ec3730/Models/Device/Sections/ProcessInfoModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ class ProcessInfoModel: DeviceInfoSectionModel {

let info = ProcessInfo.processInfo

rows.append(CopyCellView(title: "Proces Name", content: info.processName))
rows.append(CopyCellView(title: "Active Processors", content: "\(info.activeProcessorCount)"))
rows.append(CopyCellView(title: "Hostname", content: "\(info.hostName)"))
rows.append(CopyCellView(title: "Process Arguments", content: "\(info.arguments.joined(separator: " "))"))
rows.append(CopyCellView(title: "Low Power Mode", content: info.isLowPowerModeEnabled ? "Enabled" : "Disabled"))
rows.append(CopyCellView(title: "Physical Memory", contents: [
rows.append(.row(title: "Proces Name", content: info.processName))
rows.append(.row(title: "Active Processors", content: "\(info.activeProcessorCount)"))
rows.append(.row(title: "Hostname", content: "\(info.hostName)"))
rows.append(.row(title: "Process Arguments", content: "\(info.arguments.joined(separator: " "))"))
rows.append(.row(title: "Low Power Mode", content: info.isLowPowerModeEnabled ? "Enabled" : "Disabled"))
rows.append(.toggleableRow(title: "Physical Memory", contents: [
"\(info.physicalMemory) bytes",
"\(String(format: "%0.1f", Double(info.physicalMemory) / 1024.0)) kiB",
"\(String(format: "%0.1f", Double(info.physicalMemory) / 1024.0 / 1024.0)) MiB",
"\(String(format: "%0.1f", Double(info.physicalMemory) / 1024.0 / 1024.0 / 1024.0)) GiB",
]))
rows.append(CopyCellView(title: "Globally Unique String", content: "\(info.globallyUniqueString)"))
rows.append(CopyCellView(title: "OS Version", content: info.operatingSystemVersionString))
rows.append(CopyCellView(title: "System Uptime", content: "\(info.systemUptime)"))
rows.append(CopyCellView(title: "Is Mac Catalyst App", content: info.isMacCatalystApp ? "Yes" : "No"))
rows.append(CopyCellView(title: "Is iOS App on Mac", content: info.isiOSAppOnMac ? "Yes" : "No"))
rows.append(CopyCellView(title: "Prcoess Identifier (PID)", content: "\(info.processIdentifier)"))
rows.append(CopyCellView(title: "Thermal State", content: info.thermalState.description))
rows.append(.row(title: "Globally Unique String", content: "\(info.globallyUniqueString)"))
rows.append(.row(title: "OS Version", content: info.operatingSystemVersionString))
rows.append(.row(title: "System Uptime", content: "\(info.systemUptime)"))
rows.append(.row(title: "Is Mac Catalyst App", content: info.isMacCatalystApp ? "Yes" : "No"))
rows.append(.row(title: "Is iOS App on Mac", content: info.isiOSAppOnMac ? "Yes" : "No"))
rows.append(.row(title: "Prcoess Identifier (PID)", content: "\(info.processIdentifier)"))
rows.append(.row(title: "Thermal State", content: info.thermalState.description))

func getArchitecture() -> NSString {
let info = NXGetLocalArchInfo()
return NSString(utf8String: (info?.pointee.description)!)!
}
rows.append(CopyCellView(title: "Architecture", content: getArchitecture() as String))
rows.append(.row(title: "Architecture", content: getArchitecture() as String))
}
}
Loading

0 comments on commit 721d2d1

Please sign in to comment.