Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b28605e52e | |||
| 35a5350f17 | |||
| b319499056 | |||
| 17d30ad554 | |||
| b56d27ff26 | |||
| c7fe1daf26 | |||
| 6db60e25b2 | |||
| 5094ddc710 | |||
| 9b5e0d84ac | |||
| 1620fad461 | |||
| 86d9e18613 | |||
| 832f507ab1 | |||
| 2406568789 | |||
| f57800e8a4 | |||
| e7bc5d221b | |||
| 6e121fb39b | |||
| 4c8a519c4f | |||
| d3d12e2450 | |||
| 062f74a429 | |||
| c8468823c0 | |||
| c19df26edc | |||
| d1227ee522 | |||
| 97a6ae0899 | |||
| 4b0f9e149a | |||
| 20f88c739f | |||
| 98a66af9b2 | |||
| 19f2302f13 | |||
| 308a25f6db | |||
| 40614dffec | |||
| 245d6f0310 | |||
| 349d7359eb | |||
| 37e0ab6323 | |||
| 1ea0dc7026 | |||
| a9db186136 |
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 |
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
@@ -74,14 +74,14 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
CGPoint(x: UIScreen.portraitSize.width - consoleSize.width / 2 - 12,
|
||||
y: (UIScreen.hasRoundedCorners ? 44 : 16) + consoleSize.height / 2 + 12),
|
||||
CGPoint(x: consoleSize.width / 2 + 12,
|
||||
y: UIScreen.portraitSize.height - consoleSize.height / 2 - (consoleWindow?.safeAreaInsets.bottom ?? 0) - 12),
|
||||
y: UIScreen.portraitSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow?.safeAreaInsets.bottom ?? 0) - 12),
|
||||
CGPoint(x: UIScreen.portraitSize.width - consoleSize.width / 2 - 12,
|
||||
y: UIScreen.portraitSize.height - consoleSize.height / 2 - (consoleWindow?.safeAreaInsets.bottom ?? 0) - 12)]
|
||||
y: UIScreen.portraitSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow?.safeAreaInsets.bottom ?? 0) - 12)]
|
||||
} else {
|
||||
return [CGPoint(x: UIScreen.portraitSize.width / 2,
|
||||
y: (UIScreen.hasRoundedCorners ? 44 : 16) + consoleSize.height / 2 + 12),
|
||||
CGPoint(x: UIScreen.portraitSize.width / 2,
|
||||
y: UIScreen.portraitSize.height - consoleSize.height / 2 - (consoleWindow?.safeAreaInsets.bottom ?? 0) - 12)]
|
||||
y: UIScreen.portraitSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow?.safeAreaInsets.bottom ?? 0) - 12)]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,9 +171,59 @@ 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
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||
}
|
||||
|
||||
/// 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
|
||||
@@ -245,6 +281,32 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
|
||||
// MARK: Handle keyboard show/hide.
|
||||
private var keyboardHeight: CGFloat? = nil {
|
||||
didSet {
|
||||
|
||||
if consoleView.center != possibleEndpoints[0] && consoleView.center != possibleEndpoints[1] {
|
||||
let nearestTargetPosition = nearestTargetTo(consoleView.center, possibleTargets: possibleEndpoints.suffix(2))
|
||||
|
||||
UIViewPropertyAnimator(duration: 0.55, dampingRatio: 1) {
|
||||
self.consoleView.center = nearestTargetPosition
|
||||
}.startAnimation()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func keyboardWillShow(_ notification: Notification) {
|
||||
if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
|
||||
let keyboardRectangle = keyboardFrame.cgRectValue
|
||||
self.keyboardHeight = keyboardRectangle.height
|
||||
}
|
||||
}
|
||||
|
||||
@objc func keyboardWillHide() {
|
||||
keyboardHeight = nil
|
||||
}
|
||||
|
||||
private var debugBordersEnabled = false {
|
||||
didSet {
|
||||
GLOBAL_DEBUG_BORDERS = debugBordersEnabled
|
||||
@@ -273,6 +335,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 +420,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 +446,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 +646,4 @@ extension UIWindow {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
@@ -408,7 +408,7 @@ class PlatterView: UIView {
|
||||
|
||||
lazy var doneButton: UIButton = {
|
||||
let button = UIButton(type: .custom)
|
||||
button.backgroundColor = .systemBlue.resolvedColor(with: UITraitCollection(userInterfaceStyle: .dark))
|
||||
button.backgroundColor = UIColor.systemBlue.resolvedColor(with: UITraitCollection(userInterfaceStyle: .dark))
|
||||
button.setTitle("Done", for: .normal)
|
||||
button.setTitleColor(.white, for: .normal)
|
||||
button.titleLabel?.font = .systemFont(ofSize: 17, weight: .medium)
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user