Compare commits

...

12 Commits

Author SHA1 Message Date
Duraid Abdul ab79c1200f Update LCManager.swift
Fix for some potential issues that could be caused by initializing LCManager off the main queue, and improved the console text view's ability to stick to the bottom if it is scrolled to the bottom.
2021-08-16 11:40:35 -07:00
Duraid Abdul 0ae97b8162 Update LCManager.swift 2021-08-02 12:39:49 -07:00
Duraid Abdul 4b79e2744d Update LCManager.swift 2021-08-01 20:30:11 -07:00
Duraid Abdul 641e20bb01 Update LCManager.swift 2021-08-01 20:19:15 -07:00
Duraid Abdul bc6c4a91ba Merge branch 'main' of https://github.com/duraidabdul/LocalConsole into main 2021-08-01 20:14:08 -07:00
Duraid Abdul 82605fcfbb Improve systemReport() 2021-08-01 20:14:05 -07:00
Duraid Abdul 27876dfba9 Update README.md 2021-07-27 01:05:06 -07:00
Duraid Abdul 1a2da892ac Merge pull request #6 from NoahFetz/main
Fix Xcode 13 beta 3 extension error
2021-07-27 00:57:51 -07:00
Noah Fetz c9bfed3373 Merge pull request #1 from NoahFetz/fix
[Fix] Xcode 13B3 Extension unavailable
2021-07-26 08:57:06 +02:00
Noah Fetz 3f732f5054 [Fix] Xcode 13B3 Extension unavailable 2021-07-26 08:49:51 +02:00
Duraid Abdul 33de7eb54a Merge pull request #5 from duraidabdul/add-license-1
Create LICENSE
2021-07-24 18:17:45 -07:00
Duraid Abdul bad02ce90b Create LICENSE 2021-07-24 18:17:27 -07:00
5 changed files with 91 additions and 23 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Duraid Abdul
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+7 -8
View File
@@ -17,7 +17,7 @@ Welcome to LocalConsole! This Swift Package makes on-device debugging easy with
```swift
import LocalConsole
let localConsoleManager = LCManager.shared
let consoleManager = LCManager.shared
```
## **Usage**
@@ -25,30 +25,29 @@ Once prepared, the localConsole can be used throughout your project.
```swift
// Show the console view.
localConsoleManager.isVisible = true
consoleManager.isVisible = true
// Hide the console view.
localConsoleManager.isVisible = false
consoleManager.isVisible = false
```
```swift
// Print items to the console view.
localConsoleManager.print("Hello, world!")
consoleManager.print("Hello, world!")
// Clear console text.
localConsoleManager.clear()
consoleManager.clear()
// Copy console text.
localConsoleManager.copy()
consoleManager.copy()
```
```swift
// Change the console view font size.
localConsoleManager.fontSize = 5
consoleManager.fontSize = 5
```
## **To-Do**
* Support for iOS 13
* Screen edge console hiding
* Make console view reactive to landscape/portrait switch
+1
View File
@@ -22,6 +22,7 @@ extension UIScreen {
static var hasRoundedCorners = UIScreen.main.value(forKey: "_" + "display" + "Corner" + "Radius") as! CGFloat > 0
}
@available(iOSApplicationExtension, unavailable)
extension UIApplication {
var statusBarHeight: CGFloat {
if let window = UIApplication.shared.windows.first {
+60 -15
View File
@@ -12,6 +12,7 @@ import SwiftUI
var GLOBAL_BORDER_TRACKERS: [BorderManager] = []
@available(iOSApplicationExtension, unavailable)
public class LCManager: NSObject, UIGestureRecognizerDelegate {
public static let shared = LCManager()
@@ -85,11 +86,11 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
var consoleWindow: ConsoleWindow?
// The console needs a parent view controller in order to display context menus.
let viewController = UIViewController()
lazy var viewController = UIViewController()
lazy var consoleView = viewController.view!
/// Text view that displays printed items.
let consoleTextView = InvertedTextView()
lazy var consoleTextView = InvertedTextView()
/// Button that reveals menu.
lazy var menuButton = UIButton()
@@ -98,7 +99,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
var scrollLocked = true
/// Feedback generator for the long press action.
let feedbackGenerator = UISelectionFeedbackGenerator()
lazy var feedbackGenerator = UISelectionFeedbackGenerator()
lazy var panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(consolePiPPanner(recognizer:)))
lazy var longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(recognizer:)))
@@ -302,8 +303,6 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
}
}
private var _hasRelayedOffsetChange = false
/// Print items to the console view.
public func print(_ items: Any) {
if currentText == "" {
@@ -381,12 +380,46 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
}
}
var dynamicReportTimer: Timer? {
willSet { dynamicReportTimer?.invalidate() }
}
func systemReport() {
DispatchQueue.main.async { [self] in
if currentText != "" { print("\n") }
dynamicReportTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in
var _currentText = currentText
// To optimize performance, only scan the last 2500 characters of text for system report changes.
let range: NSRange = {
if _currentText.count <= 2500 {
return NSMakeRange(0, _currentText.count)
}
return NSMakeRange(_currentText.count - 2500, 2500)
}()
let regex0 = try! NSRegularExpression(pattern: "Thermal State: .*", options: NSRegularExpression.Options.caseInsensitive)
_currentText = regex0.stringByReplacingMatches(in: _currentText, options: [], range: range, withTemplate: "Thermal State: \(SystemReport.shared.thermalState)")
let regex1 = try! NSRegularExpression(pattern: "System Uptime: .*", options: NSRegularExpression.Options.caseInsensitive)
_currentText = regex1.stringByReplacingMatches(in: _currentText, options: [], range: range, withTemplate: "System Uptime: \(ProcessInfo.processInfo.systemUptime.formattedString!)")
let regex2 = try! NSRegularExpression(pattern: "Low Power Mode: .*", options: NSRegularExpression.Options.caseInsensitive)
_currentText = regex2.stringByReplacingMatches(in: _currentText, options: [], range: range, withTemplate: "Low Power Mode: \(ProcessInfo.processInfo.isLowPowerModeEnabled)")
if currentText != _currentText {
currentText = _currentText
} else {
// Invalidate the timer if there is no longer anything to update.
timer.invalidate()
}
}
print(
"""
\n
Model Name: \(SystemReport.shared.gestaltMarketingName)
Model Identifier: \(SystemReport.shared.gestaltModelIdentifier)
Architecture: \(SystemReport.shared.gestaltArchitecture)
@@ -397,20 +430,20 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
Memory: \(round(100 * Double(ProcessInfo.processInfo.physicalMemory) * pow(10, -9)) / 100) GB
Processor Cores: \(Int(ProcessInfo.processInfo.processorCount))
Thermal State: \(SystemReport.shared.thermalState)
System Uptime: \(Int(ProcessInfo.processInfo.systemUptime))s
System Uptime: \(ProcessInfo.processInfo.systemUptime.formattedString!)
Low Power Mode: \(ProcessInfo.processInfo.isLowPowerModeEnabled)
"""
)
}
}
func displayReport() {
DispatchQueue.main.async { [self] in
if currentText != "" { print("\n") }
print(
"""
\n
Screen Size: \(UIScreen.main.bounds.size)
Screen Corner Radius: \(UIScreen.main.value(forKey: "_displ" + "ayCorn" + "erRa" + "dius") as! CGFloat)
Screen Scale: \(UIScreen.main.scale)
@@ -427,15 +460,15 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
func commitTextChanges(requestMenuUpdate menuUpdateRequested: Bool) {
if consoleTextView.contentOffset.y > consoleTextView.contentSize.height - 20 - consoleTextView.bounds.size.height ||
_hasRelayedOffsetChange == false {
consoleTextView.pendingOffsetChange = true
if consoleTextView.contentOffset.y > consoleTextView.contentSize.height - consoleTextView.bounds.size.height - 20 {
_hasRelayedOffsetChange = true
// Weird, weird fix that makes the scroll view bottom pinning system work.
consoleTextView.isScrollEnabled.toggle()
consoleTextView.isScrollEnabled.toggle()
consoleTextView.pendingOffsetChange = true
}
consoleTextView.text = currentText
setAttributedText(currentText)
if menuUpdateRequested {
@@ -771,3 +804,15 @@ class InvertedTextView: UITextView {
}
}
}
extension TimeInterval {
var formattedString: String? {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour, .minute, .second]
return formatter.string(from: self)
}
}
fileprivate func _debugPrint(_ items: Any) {
print(items)
}
@@ -7,6 +7,7 @@
import UIKit
@available(iOSApplicationExtension, unavailable)
class ResizeController {
public static let shared = ResizeController()
@@ -329,6 +330,7 @@ class ResizeController {
}
}
@available(iOSApplicationExtension, unavailable)
class PlatterView: UIView {
override init(frame: CGRect) {