Compare commits

..

30 Commits

Author SHA1 Message Date
Duraid Abdul b56d27ff26 Add OS Compile Date to System Report 2021-06-01 14:46:05 -07:00
Duraid Abdul c7fe1daf26 Update System Report
Reorganized system report code for readability. Added some more valued to the system report.
2021-06-01 14:17:25 -07:00
Duraid Abdul 6db60e25b2 Asynchronous System Report 2021-05-31 21:24:23 -07:00
Duraid Abdul 5094ddc710 Added System Report 2021-05-31 21:15:22 -07:00
Duraid Abdul 9b5e0d84ac Merge branch 'main' of https://github.com/duraidabdul/LocalConsole into main 2021-05-24 01:46:08 -07:00
Duraid Abdul 1620fad461 Update Demo_Resize.gif 2021-05-24 01:44:17 -07:00
Duraid Abdul 86d9e18613 Update README.md 2021-05-24 01:40:04 -07:00
Duraid Abdul 832f507ab1 Update README.md 2021-05-24 01:38:59 -07:00
Duraid Abdul 2406568789 Update README.md 2021-05-24 01:35:52 -07:00
Duraid Abdul f57800e8a4 Update Demos 2021-05-24 01:27:11 -07:00
Duraid Abdul e7bc5d221b Update LCManager.swift 2021-05-24 01:01:40 -07:00
Duraid Abdul 6e121fb39b Update LCManager.swift
Fix for early initialization.
2021-05-24 00:56:07 -07:00
Duraid Abdul 4c8a519c4f Update README.md 2021-05-23 16:58:53 -07:00
Duraid Abdul d3d12e2450 Update README.md 2021-05-23 16:44:38 -07:00
Duraid Abdul 062f74a429 Update README.md 2021-05-23 16:35:52 -07:00
Duraid Abdul c8468823c0 Merge branch 'main' of https://github.com/duraidabdul/LocalConsole into main 2021-05-23 16:12:40 -07:00
Duraid Abdul c19df26edc Update README.md 2021-05-23 16:11:54 -07:00
Duraid Abdul d1227ee522 Update Demo.gif 2021-05-23 16:11:12 -07:00
Duraid Abdul 97a6ae0899 Update Demo.gif 2021-05-23 15:53:20 -07:00
Duraid Abdul 4b0f9e149a Update Demo.gif 2021-05-23 15:35:04 -07:00
Duraid Abdul 20f88c739f Delete Demo_1.gif 2021-05-23 01:22:21 -07:00
Duraid Abdul 98a66af9b2 Add files via upload 2021-05-23 01:20:59 -07:00
Duraid Abdul 19f2302f13 Add files via upload 2021-05-23 01:18:22 -07:00
Duraid Abdul 308a25f6db Delete Demo.gif 2021-05-23 01:17:48 -07:00
Duraid Abdul 40614dffec Merge branch 'main' of https://github.com/duraidabdul/LocalConsole into main 2021-05-23 01:15:05 -07:00
Duraid Abdul 245d6f0310 Update Demo.gif 2021-05-23 01:14:22 -07:00
Duraid Abdul 349d7359eb Update README.md 2021-05-23 01:07:57 -07:00
Duraid Abdul 37e0ab6323 Update Demo.gif 2021-05-22 23:43:37 -07:00
Duraid Abdul 1ea0dc7026 Update Demo.gif 2021-05-22 23:36:08 -07:00
Duraid Abdul a9db186136 Update README.md 2021-05-22 14:51:35 -07:00
8 changed files with 198 additions and 38 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 10 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 MiB

After

Width:  |  Height:  |  Size: 11 MiB

+8 -4
View File
@@ -2,7 +2,10 @@
Welcome to LocalConsole! This Swift Package makes on-device debugging easy with a convenient PiP-style console that can display items in the same way ```print()``` will in Xcode. This tool can also dynamically display view frames and restart SpringBoard right from your live app.
<img src="https://github.com/duraidabdul/LocalConsole/blob/main/Demo.gif?raw=true" width="250">
<div>
<img src="https://github.com/duraidabdul/LocalConsole/blob/main/Additional%20Files/Demo_Pan.gif?raw=true" width="320">
<img src="https://github.com/duraidabdul/LocalConsole/blob/main/Additional%20Files/Demo_Resize.gif?raw=true" width="320">
</div>
## **Setup**
@@ -32,8 +35,11 @@ localConsoleManager.isVisible = false
// Print items to the console view.
localConsoleManager.print("Hello, world!")
// Clear text in the console view.
// Clear console text.
localConsoleManager.clear()
// Copy console text.
localConsoleManager.copy()
```
```swift
@@ -43,8 +49,6 @@ localConsoleManager.fontSize = 5
## **To-Do**
* Custom console view size
* Support for iOS 13
* Screen edge console hiding
* Custom pinch to resize gesture
* Make console view reactive to landscape/portrait switch
-4
View File
@@ -5,8 +5,6 @@
// Copyright © 2021 Duraid Abdul. All rights reserved.
//
#if canImport(UIKit)
import UIKit
/// This class handles enabling and disabling debug borders on a specified view.
@@ -64,5 +62,3 @@ class BorderManager {
}
}
}
#endif
-4
View File
@@ -5,8 +5,6 @@
// Copyright © 2021 Duraid Abdul. All rights reserved.
//
#if canImport(UIKit)
import UIKit
extension UIScreen {
@@ -59,5 +57,3 @@ extension UIView {
frame.origin.y = (round(frame.origin.y * UIScreen.main.scale)) / UIScreen.main.scale
}
}
#endif
@@ -5,8 +5,6 @@
// Copyright © 2021 Duraid Abdul. All rights reserved.
//
#if canImport(UIKit)
import UIKit
extension CGPoint {
@@ -80,5 +78,3 @@ func nearestTargetTo(_ point: CGPoint, possibleTargets: [CGPoint]) -> CGPoint {
}
return nearestEndpoint
}
#endif
+82 -22
View File
@@ -5,7 +5,7 @@
// Copyright © 2021 Duraid Abdul. All rights reserved.
//
#if canImport(UIKit)
//#if canImport(UIKit)
import UIKit
@@ -55,9 +55,9 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
let consoleTextView = UITextView()
/// Button that reveals menu.
var menuButton: UIButton!
lazy var menuButton = UIButton()
/// Tracks whether the PiP console is in text view scroll mode or pan mode.
/// Tracks whether the PiP console is in text view scroll mode or pan mode.
var scrollLocked = true
/// Feedback generator for the long press action.
@@ -90,21 +90,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
override init() {
super.init()
// Configure console window.
let windowScene = UIApplication.shared
.connectedScenes
.filter { $0.activationState == .foregroundActive }
.first
if let windowScene = windowScene as? UIWindowScene {
consoleWindow = ConsoleWindow(windowScene: windowScene)
consoleWindow?.frame = UIScreen.main.bounds
consoleWindow?.windowLevel = UIWindow.Level.statusBar
consoleWindow?.isHidden = false
consoleWindow?.addSubview(consoleView)
UIWindow.swizzleStatusBarAppearanceOverride
}
configureWindow()
consoleSize = CGSize(width: UserDefaults.standard.object(forKey: "LocalConsole_Width") as? CGFloat ?? consoleSize.width,
height: UserDefaults.standard.object(forKey: "LocalConsole_Height") as? CGFloat ?? consoleSize.height)
@@ -185,11 +171,58 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
menuButton.tintColor = UIColor(white: 1, alpha: 0.75)
menuButton.menu = makeMenu()
menuButton.showsMenuAsPrimaryAction = true
consoleView.addSubview(menuButton!)
consoleView.addSubview(menuButton)
UIView.swizzleDebugBehaviour
}
/// Adds a LocalConsole window to the app's main scene.
func configureWindow() {
var windowSceneFound = false
// Configure console window.
func fetchWindowScene() {
let windowScene = UIApplication.shared
.connectedScenes
.filter { $0.activationState == .foregroundActive }
.first
if let windowScene = windowScene as? UIWindowScene {
windowSceneFound = true
consoleWindow = ConsoleWindow(windowScene: windowScene)
consoleWindow?.frame = UIScreen.main.bounds
consoleWindow?.windowLevel = UIWindow.Level.statusBar
consoleWindow?.isHidden = false
consoleWindow?.addSubview(consoleView)
UIWindow.swizzleStatusBarAppearanceOverride
}
}
fetchWindowScene()
/// Ensures the window is configured (i.e. scene has been found). If not, delay and wait for a scene to prepare itself, then try again.
for i in 1...10 {
let delay = Double(i) / 10
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [self] in
guard !windowSceneFound else { return }
fetchWindowScene()
if isVisible {
isVisible = false
consoleView.layer.removeAllAnimations()
isVisible = true
}
}
}
}
// MARK: - Public
public var isVisible = false {
@@ -273,6 +306,28 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
}
}
func systemReport() {
DispatchQueue.main.async { [self] in
print("Screen Scale: \(UIScreen.main.scale)\n")
print("Screen Radius: \(UIScreen.main.value(forKey: "_displayCornerRadius") as! CGFloat)")
print("Screen Size: \(UIScreen.main.bounds.size)")
print("Max Frame Rate: \(UIScreen.main.maximumFramesPerSecond) Hz")
print("Low Power Mode: \(ProcessInfo.processInfo.isLowPowerModeEnabled)")
print("System Uptime: \(Int(ProcessInfo.processInfo.systemUptime))s")
print("Thermal State: \(SystemReport.shared.thermalState)")
print("Processor Cores: \(Int(ProcessInfo.processInfo.processorCount))")
print("Memory: \(round(100 * Double(ProcessInfo.processInfo.physicalMemory) * pow(10, -9)) / 100) GB")
print("OS Compile Date: \(SystemReport.shared.compileDate)")
print("System Version: \(SystemReport.shared.versionString)")
print("Kernel Version: \(SystemReport.shared.kernel) \(SystemReport.shared.kernelVersion)")
print("Firmware: \(SystemReport.shared.gestaltFirmwareVersion)")
print("Architecture: \(SystemReport.shared.gestaltArchitecture)")
print("Model Identifier: \(SystemReport.shared.gestaltModelIdentifier)")
print("Marketing Name: \(SystemReport.shared.gestaltMarketingName)")
}
}
@objc func toggleLock() {
scrollLocked.toggle()
}
@@ -336,7 +391,12 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
let viewFrames = UIAction(title: debugBordersEnabled ? "Hide View Frames" : "Show View Frames",
image: UIImage(systemName: "rectangle.3.offgrid"), handler: { _ in
self.debugBordersEnabled.toggle()
self.menuButton?.menu = self.makeMenu()
self.menuButton.menu = self.makeMenu()
})
let systemReport = UIAction(title: "System Report",
image: UIImage(systemName: "doc.badge.gearshape"), handler: { _ in
self.systemReport()
})
let respring = UIAction(title: "Restart SpringBoard",
@@ -357,7 +417,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
}
animator.startAnimation()
})
let debugActions = UIMenu(title: "", options: .displayInline, children: [viewFrames, respring])
let debugActions = UIMenu(title: "", options: .displayInline, children: [viewFrames, systemReport, respring])
var menuContent: [UIMenuElement] = []
@@ -557,4 +617,4 @@ extension UIWindow {
}
}
#endif
//#endif
+108
View File
@@ -0,0 +1,108 @@
//
// SystemReport.swift
// LocalConsole
//
// Created by Duraid Abdul on 2021-06-01.
//
import Foundation
import MachO
class SystemReport {
static let shared = SystemReport()
var versionString: String {
ProcessInfo.processInfo.operatingSystemVersionString
.replacingOccurrences(of: "Build ", with: "")
.replacingOccurrences(of: "Version ", with: "")
}
// Current device thermal state.
var thermalState: String {
let state = ProcessInfo.processInfo.thermalState
switch state {
case .nominal: return "Nominal"
case .fair : return "Fair"
case .serious : return "Serious"
case .critical : return "Critical"
default: return "Unknown"
}
}
// Retrieve device mobile gestalt cache.
lazy var gestaltCacheExtra: NSDictionary? = {
let url = URL(fileURLWithPath: "/private/var/containers/Shared/SystemGroup/systemgroup.com.apple.mobilegestaltcache/Library/Caches/com.apple.MobileGestalt.plist")
let dictionary = NSDictionary(contentsOf: url)
return dictionary?.value(forKey: "CacheExtra") as? NSDictionary
}()
// Device marketing name.
lazy var gestaltMarketingName: Any = gestaltCacheExtra?.value(forKey: "Z/dqyWS6OZTRy10UcmUAhw") ?? "Unknown"
// iBoot (second-stage loader) version.
lazy var gestaltFirmwareVersion: Any = gestaltCacheExtra?.value(forKey: "LeSRsiLoJCMhjn6nd6GWbQ") ?? "Unknown"
// CPU architecture.
lazy var gestaltArchitecture: Any = gestaltCacheExtra?.value(forKey: "k7QIBwZJJOVw+Sej/8h8VA") ?? deviceArchitecture
// Fallback in case gestaltArchitecture doesn't return a value.
var deviceArchitecture: String {
let info = NXGetLocalArchInfo()
return String(utf8String: (info?.pointee.description)!) ?? "Unknown"
}
lazy var gestaltModelIdentifier: Any = gestaltCacheExtra?.value(forKey: "h9jDsbgj7xIVeIQ8S3/X3Q") ?? modelIdentifier
// Fallback in case gestaltModelIdentifier doesn't return a value.
var 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)?.trimmingCharacters(in: .controlCharacters) ?? "Unknown"
}
var kernel: String {
var size = 0
sysctlbyname("kern.ostype", nil, &size, nil, 0)
var string = [CChar](repeating: 0, count: Int(size))
sysctlbyname("kern.ostype", &string, &size, nil, 0)
return String(cString: string)
}
var kernelVersion: String {
var size = 0
sysctlbyname("kern.osrelease", nil, &size, nil, 0)
var string = [CChar](repeating: 0, count: Int(size))
sysctlbyname("kern.osrelease", &string, &size, nil, 0)
return String(cString: string)
}
var compileDate: String {
var size = 0
sysctlbyname("kern.version", nil, &size, nil, 0)
var string = [CChar](repeating: 0, count: Int(size))
sysctlbyname("kern.version", &string, &size, nil, 0)
let fullString = String(cString: string) /// Ex: Darwin Kernel Version 20.6.0: Mon May 10 03:15:29 PDT 2021; root:xnu-7195.140.13.0.1~20/RELEASE_ARM64_T8101
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.date.rawValue)
if let matches = detector?.matches(in: fullString, options: [], range: NSRange(location: 0, length: fullString.utf16.count)) {
for match in matches {
if let date = match.date {
let dateformatter = DateFormatter()
dateformatter.dateStyle = .medium
return dateformatter.string(from: date)
}
}
}
return "Unknown"
}
}