update
This commit is contained in:
327
Pods/CocoaDebug/Sources/Window/Bubble.swift
generated
Normal file
327
Pods/CocoaDebug/Sources/Window/Bubble.swift
generated
Normal file
@@ -0,0 +1,327 @@
|
||||
//
|
||||
// Example
|
||||
// man
|
||||
//
|
||||
// Created by man 11/11/2018.
|
||||
// Copyright © 2020 man. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import UIKit.UIGestureRecognizerSubclass
|
||||
|
||||
protocol BubbleDelegate: AnyObject {
|
||||
func didTapBubble()
|
||||
}
|
||||
|
||||
//https://httpcodes.co/status/
|
||||
private var _successStatusCodes = ["200","201","202","203","204","205","206","207","208","226"]
|
||||
private var _informationalStatusCodes = ["100","101","102","103","122"]
|
||||
private var _redirectionStatusCodes = ["300","301","302","303","304","305","306","307","308"]
|
||||
|
||||
private var _width: CGFloat = 25
|
||||
private var _height: CGFloat = 25
|
||||
|
||||
class Bubble: UIView {
|
||||
|
||||
weak var delegate: BubbleDelegate?
|
||||
|
||||
public var width: CGFloat = _width
|
||||
public var height: CGFloat = _height
|
||||
|
||||
private var numberLabel: UILabel? = {
|
||||
return UILabel.init()
|
||||
}()
|
||||
private var networkNumber: Int = 0
|
||||
|
||||
|
||||
static var originalPosition: CGPoint {
|
||||
if CocoaDebugSettings.shared.bubbleFrameX != 0 && CocoaDebugSettings.shared.bubbleFrameY != 0 {
|
||||
return CGPoint(x: CGFloat(CocoaDebugSettings.shared.bubbleFrameX), y: CGFloat(CocoaDebugSettings.shared.bubbleFrameY))
|
||||
}
|
||||
|
||||
var h = 0
|
||||
if #available(iOS 11.0, *) {
|
||||
if UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 0 > 24.0 {
|
||||
h = 16;
|
||||
}
|
||||
}
|
||||
return CGPoint(x: 1.875 + _width/2, y: UIScreen.main.bounds.size.height/2 - _height - CGFloat(h))
|
||||
}
|
||||
|
||||
static var size: CGSize {return CGSize(width: _width, height: _height)}
|
||||
|
||||
|
||||
//MARK: - tool
|
||||
fileprivate func initLabelEvent(_ content: String, _ foo: Bool) {
|
||||
if content == "🚀" || content == "❌"
|
||||
{
|
||||
//step 0
|
||||
let WH: CGFloat = 20
|
||||
//step 1
|
||||
let label = UILabel()
|
||||
label.text = content
|
||||
label.font = UIFont.boldSystemFont(ofSize: 14)
|
||||
|
||||
//step 2
|
||||
if foo == true {
|
||||
label.frame = CGRect(x: self.frame.size.width/2 - WH/2, y: self.frame.size.height/2 - WH/2, width: WH, height: WH)
|
||||
self.addSubview(label)
|
||||
} else {
|
||||
label.frame = CGRect(x: self.center.x - WH/2, y: self.center.y - WH/2, width: WH, height: WH)
|
||||
self.superview?.addSubview(label)
|
||||
}
|
||||
//step 3
|
||||
UIView.animate(withDuration: 0.8, animations: {
|
||||
label.frame.origin.y = foo ? -100 : (self.center.y - 100)
|
||||
label.alpha = 0
|
||||
}, completion: { _ in
|
||||
label.removeFromSuperview()
|
||||
})
|
||||
}
|
||||
else
|
||||
{
|
||||
//step 0
|
||||
let WH: CGFloat = 35
|
||||
//step 1
|
||||
let label = UILabel()
|
||||
label.text = content
|
||||
label.textAlignment = .center
|
||||
label.adjustsFontSizeToFitWidth = true
|
||||
label.font = UIFont.boldSystemFont(ofSize: 14)
|
||||
|
||||
if _informationalStatusCodes.contains(content) {
|
||||
label.textColor = "#4b8af7".hexColor
|
||||
}
|
||||
else if _redirectionStatusCodes.contains(content) {
|
||||
label.textColor = "#ff9800".hexColor
|
||||
}
|
||||
else {
|
||||
label.textColor = .red
|
||||
}
|
||||
|
||||
//step 3
|
||||
if foo == true {
|
||||
label.frame = CGRect(x: self.frame.size.width/2 - WH/2, y: self.frame.size.height/2 - WH/2, width: WH, height: WH)
|
||||
self.addSubview(label)
|
||||
} else {
|
||||
label.frame = CGRect(x: self.center.x - WH/2, y: self.center.y - WH/2, width: WH, height: WH)
|
||||
self.superview?.addSubview(label)
|
||||
}
|
||||
//step 4
|
||||
UIView.animate(withDuration: 0.8, animations: {
|
||||
label.frame.origin.y = foo ? -100 : (self.center.y - 100)
|
||||
label.alpha = 0
|
||||
}, completion: { _ in
|
||||
label.removeFromSuperview()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fileprivate func initLayer() {
|
||||
self.backgroundColor = .black
|
||||
self.layer.cornerRadius = _width/2
|
||||
self.sizeToFit()
|
||||
|
||||
if let numberLabel = numberLabel {
|
||||
numberLabel.text = String(networkNumber)
|
||||
numberLabel.textColor = .white
|
||||
numberLabel.textAlignment = .center
|
||||
numberLabel.adjustsFontSizeToFitWidth = true
|
||||
numberLabel.isHidden = true
|
||||
numberLabel.frame = CGRect(x:0, y:0, width:_width, height:_height)
|
||||
self.addSubview(numberLabel)
|
||||
}
|
||||
|
||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(Bubble.tap))
|
||||
self.addGestureRecognizer(tapGesture)
|
||||
|
||||
let longTap = UILongPressGestureRecognizer.init(target: self, action: #selector(Bubble.longTap))
|
||||
self.addGestureRecognizer(longTap)
|
||||
}
|
||||
|
||||
func changeSideDisplay() {
|
||||
UIView.animate(withDuration: 0.5, delay: 0.1, usingSpringWithDamping: 0.5,
|
||||
initialSpringVelocity: 5, options: .curveEaseInOut, animations: {
|
||||
}, completion: nil)
|
||||
}
|
||||
|
||||
func updateOrientation(newSize: CGSize) {
|
||||
let oldSize = CGSize(width: newSize.height, height: newSize.width)
|
||||
let percent = center.y / oldSize.height * 100
|
||||
let newOrigin = newSize.height * percent / 100
|
||||
let originX = frame.origin.x < newSize.height / 2 ? _width/8*4.25 : newSize.width - _width/8*4.25
|
||||
self.center = CGPoint(x: originX, y: newOrigin)
|
||||
}
|
||||
|
||||
//MARK: - init
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
initLayer()
|
||||
|
||||
//添加手势
|
||||
let selector = #selector(Bubble.panDidFire(panner:))
|
||||
let panGesture = UIPanGestureRecognizer(target: self, action: selector)
|
||||
self.addGestureRecognizer(panGesture)
|
||||
|
||||
//notification
|
||||
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "reloadHttp_CocoaDebug"), object: nil, queue: OperationQueue.main) { [weak self] notification in
|
||||
self?.reloadHttp_notification(notification)
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "deleteAllLogs_CocoaDebug"), object: nil, queue: OperationQueue.main) { [weak self] _ in
|
||||
self?.deleteAllLogs_notification()
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "SHOW_COCOADEBUG_FORCE"), object: nil, queue: OperationQueue.main) { [weak self] _ in
|
||||
self?.show_cocoadebug_force()
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
deinit {
|
||||
//notification
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
//MARK: - notification
|
||||
//网络通知
|
||||
@objc func reloadHttp_notification(_ notification: Notification) {
|
||||
|
||||
guard let userInfo = notification.userInfo else {return}
|
||||
let statusCode = userInfo["statusCode"] as? String
|
||||
|
||||
if _successStatusCodes.contains(statusCode ?? "") {
|
||||
self.initLabelEvent("🚀", true)
|
||||
}
|
||||
else if statusCode == "0" { //"0" means network unavailable
|
||||
self.initLabelEvent("❌", true)
|
||||
}
|
||||
else {
|
||||
guard let statusCode = statusCode else {return}
|
||||
self.initLabelEvent(statusCode, true)
|
||||
}
|
||||
|
||||
|
||||
self.networkNumber = (self.networkNumber ) + 1
|
||||
self.numberLabel?.text = String(networkNumber)
|
||||
|
||||
|
||||
if self.networkNumber == 0 {
|
||||
self.numberLabel?.isHidden = true
|
||||
} else {
|
||||
self.numberLabel?.isHidden = false
|
||||
}
|
||||
|
||||
if networkNumber >= 0 && networkNumber < 10 {
|
||||
self.numberLabel?.font = UIFont.boldSystemFont(ofSize: 11)
|
||||
} else if networkNumber >= 10 && networkNumber < 100 {
|
||||
self.numberLabel?.font = UIFont.boldSystemFont(ofSize: 11)
|
||||
} else if networkNumber >= 100 && networkNumber < 1000 {
|
||||
self.numberLabel?.font = UIFont.boldSystemFont(ofSize: 9)
|
||||
} else if networkNumber >= 1000 && networkNumber < 10000 {
|
||||
self.numberLabel?.font = UIFont.boldSystemFont(ofSize: 7.5)
|
||||
} else {
|
||||
self.numberLabel?.font = UIFont.boldSystemFont(ofSize: 7)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc func deleteAllLogs_notification() {
|
||||
self.networkNumber = 0
|
||||
|
||||
self.numberLabel?.text = String(networkNumber)
|
||||
|
||||
if self.networkNumber == 0 {
|
||||
self.numberLabel?.isHidden = true
|
||||
} else {
|
||||
self.numberLabel?.isHidden = false
|
||||
}
|
||||
}
|
||||
|
||||
@objc func show_cocoadebug_force() {
|
||||
CocoaDebugSettings.shared.showBubbleAndWindow = !CocoaDebugSettings.shared.showBubbleAndWindow
|
||||
CocoaDebugSettings.shared.showBubbleAndWindow = !CocoaDebugSettings.shared.showBubbleAndWindow
|
||||
}
|
||||
|
||||
|
||||
//MARK: - target action
|
||||
@objc func tap() {
|
||||
delegate?.didTapBubble()
|
||||
}
|
||||
|
||||
@objc func longTap() {
|
||||
_HttpDatasource.shared().reset()
|
||||
CocoaDebugSettings.shared.networkLastIndex = 0
|
||||
NotificationCenter.default.post(name: NSNotification.Name("deleteAllLogs_CocoaDebug"), object: nil, userInfo: nil)
|
||||
}
|
||||
|
||||
@objc func panDidFire(panner: UIPanGestureRecognizer) {
|
||||
if panner.state == .began {
|
||||
UIView.animate(withDuration: 0.5, delay: 0, options: .curveLinear, animations: { [weak self] in
|
||||
self?.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
|
||||
}, completion: nil)
|
||||
}
|
||||
|
||||
let offset = panner.translation(in: self.superview)
|
||||
panner.setTranslation(CGPoint.zero, in: self.superview)
|
||||
var center = self.center
|
||||
center.x += offset.x
|
||||
center.y += offset.y
|
||||
self.center = center
|
||||
|
||||
if panner.state == .ended || panner.state == .cancelled {
|
||||
|
||||
var frameInset: UIEdgeInsets
|
||||
|
||||
if #available(iOS 11.0, *) {
|
||||
frameInset = UIApplication.shared.keyWindow?.safeAreaInsets ?? UIEdgeInsets(top: UIApplication.shared.statusBarFrame.height, left: 0, bottom: 0, right: 0)
|
||||
} else {
|
||||
frameInset = UIDevice.current.orientation.isPortrait ? UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0) : .zero
|
||||
}
|
||||
|
||||
let location = panner.location(in: self.superview)
|
||||
let velocity = panner.velocity(in: self.superview)
|
||||
|
||||
var finalX: Double = Double(self.width/8*4.25)
|
||||
var finalY: Double = Double(location.y)
|
||||
|
||||
if location.x > UIScreen.main.bounds.size.width / 2 {
|
||||
finalX = Double(UIScreen.main.bounds.size.width) - Double(self.width/8*4.25)
|
||||
}
|
||||
|
||||
self.changeSideDisplay()
|
||||
|
||||
let horizentalVelocity = abs(velocity.x)
|
||||
let positionX = abs(finalX - Double(location.x))
|
||||
|
||||
let velocityForce = sqrt(pow(velocity.x, 2) * pow(velocity.y, 2))
|
||||
|
||||
let durationAnimation = (velocityForce > 1000.0) ? min(0.3, positionX / Double(horizentalVelocity)) : 0.3
|
||||
|
||||
if velocityForce > 1000.0 {
|
||||
finalY += Double(velocity.y) * durationAnimation
|
||||
}
|
||||
|
||||
if finalY > Double(UIScreen.main.bounds.size.height) - Double(self.height/8*4.25) {
|
||||
finalY = Double(UIScreen.main.bounds.size.height) - Double(frameInset.bottom) - Double(self.height/8*4.25)
|
||||
} else if finalY < Double(self.height/8*4.25) + Double(frameInset.top) {
|
||||
finalY = Double(self.height/8*4.25) + Double(frameInset.top)
|
||||
}
|
||||
|
||||
//
|
||||
CocoaDebugSettings.shared.bubbleFrameX = Float(finalX)
|
||||
CocoaDebugSettings.shared.bubbleFrameY = Float(finalY)
|
||||
|
||||
//
|
||||
UIView.animate(withDuration: durationAnimation * 5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 6, options: .allowUserInteraction, animations: { [weak self] in
|
||||
self?.center = CGPoint(x: finalX, y: finalY)
|
||||
self?.transform = CGAffineTransform.identity
|
||||
}, completion:nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
48
Pods/CocoaDebug/Sources/Window/CocoaDebugNavigationController.swift
generated
Normal file
48
Pods/CocoaDebug/Sources/Window/CocoaDebugNavigationController.swift
generated
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Example
|
||||
// man
|
||||
//
|
||||
// Created by man 11/11/2018.
|
||||
// Copyright © 2020 man. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class CocoaDebugNavigationController: UINavigationController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
navigationBar.isTranslucent = false //liman
|
||||
|
||||
navigationBar.tintColor = Color.mainGreen
|
||||
navigationBar.titleTextAttributes = [.font: UIFont.boldSystemFont(ofSize: 20),
|
||||
.foregroundColor: Color.mainGreen]
|
||||
|
||||
let selector = #selector(CocoaDebugNavigationController.exit)
|
||||
|
||||
let image = UIImage(named: "_icon_file_type_close", in: Bundle(for: CocoaDebugNavigationController.self), compatibleWith: nil)
|
||||
let leftItem = UIBarButtonItem(image: image,
|
||||
style: .done, target: self, action: selector)
|
||||
leftItem.tintColor = Color.mainGreen
|
||||
topViewController?.navigationItem.leftBarButtonItem = leftItem
|
||||
|
||||
//bugfix #issues-158
|
||||
if #available(iOS 13, *) {
|
||||
let appearance = UINavigationBarAppearance()
|
||||
appearance.configureWithOpaqueBackground()
|
||||
// self.navigationController?.navigationBar.isTranslucent = true // pass "true" for fixing iOS 15.0 black bg issue
|
||||
// self.navigationController?.navigationBar.tintColor = UIColor.white // We need to set tintcolor for iOS 15.0
|
||||
appearance.shadowColor = .clear //removing navigationbar 1 px bottom border.
|
||||
// UINavigationBar.appearance().standardAppearance = appearance
|
||||
// UINavigationBar.appearance().scrollEdgeAppearance = appearance
|
||||
self.navigationBar.standardAppearance = appearance
|
||||
self.navigationBar.scrollEdgeAppearance = appearance
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc func exit() {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
131
Pods/CocoaDebug/Sources/Window/CocoaDebugTabBarController.swift
generated
Normal file
131
Pods/CocoaDebug/Sources/Window/CocoaDebugTabBarController.swift
generated
Normal file
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// Example
|
||||
// man
|
||||
//
|
||||
// Created by man 11/11/2018.
|
||||
// Copyright © 2020 man. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class CocoaDebugTabBarController: UITabBarController {
|
||||
|
||||
//MARK: - init
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
UIApplication.shared.keyWindow?.endEditing(true)
|
||||
|
||||
setChildControllers()
|
||||
|
||||
self.selectedIndex = CocoaDebugSettings.shared.tabBarSelectItem
|
||||
self.tabBar.tintColor = Color.mainGreen
|
||||
|
||||
//bugfix #issues-158
|
||||
if #available(iOS 13, *) {
|
||||
let appearance = UITabBarAppearance()
|
||||
appearance.configureWithOpaqueBackground()
|
||||
appearance.shadowColor = .clear //removing navigationbar 1 px bottom border.
|
||||
// self.tabBar.appearance().standardAppearance = appearance
|
||||
// self.tabBar.appearance().scrollEdgeAppearance = appearance
|
||||
self.tabBar.standardAppearance = appearance
|
||||
if #available(iOS 15.0, *) {
|
||||
self.tabBar.scrollEdgeAppearance = appearance
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
CocoaDebugSettings.shared.visible = true
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
CocoaDebugSettings.shared.visible = false
|
||||
}
|
||||
override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
WindowHelper.shared.displayedList = false
|
||||
}
|
||||
|
||||
//MARK: - private
|
||||
func setChildControllers() {
|
||||
|
||||
//1.
|
||||
let logs = UIStoryboard(name: "Logs", bundle: Bundle(for: CocoaDebug.self)).instantiateViewController(withIdentifier: "Logs")
|
||||
let network = UIStoryboard(name: "Network", bundle: Bundle(for: CocoaDebug.self)).instantiateViewController(withIdentifier: "Network")
|
||||
let app = UIStoryboard(name: "App", bundle: Bundle(for: CocoaDebug.self)).instantiateViewController(withIdentifier: "App")
|
||||
|
||||
//2.
|
||||
_Sandboxer.shared.isSystemFilesHidden = false
|
||||
_Sandboxer.shared.isExtensionHidden = false
|
||||
_Sandboxer.shared.isShareable = true
|
||||
_Sandboxer.shared.isFileDeletable = true
|
||||
_Sandboxer.shared.isDirectoryDeletable = true
|
||||
guard let sandbox = _Sandboxer.shared.homeDirectoryNavigationController() else {return}
|
||||
sandbox.tabBarItem.title = "Sandbox"
|
||||
sandbox.tabBarItem.image = UIImage.init(named: "_icon_file_type_sandbox", in: Bundle.init(for: CocoaDebug.self), compatibleWith: nil)
|
||||
|
||||
//3.
|
||||
guard let additionalViewController = CocoaDebugSettings.shared.additionalViewController else {
|
||||
self.viewControllers = [network, logs, sandbox, app]
|
||||
return
|
||||
}
|
||||
|
||||
//4.Add additional controller
|
||||
var temp = [network, logs, sandbox, app]
|
||||
|
||||
let nav = UINavigationController.init(rootViewController: additionalViewController)
|
||||
nav.navigationBar.barTintColor = "#1f2124".hexColor
|
||||
nav.tabBarItem = UITabBarItem.init(tabBarSystemItem: .more, tag: 4)
|
||||
|
||||
//****** copy codes from LogNavigationViewController.swift ******
|
||||
nav.navigationBar.isTranslucent = false
|
||||
|
||||
nav.navigationBar.tintColor = Color.mainGreen
|
||||
nav.navigationBar.titleTextAttributes = [.font: UIFont.boldSystemFont(ofSize: 20),
|
||||
.foregroundColor: Color.mainGreen]
|
||||
|
||||
let selector = #selector(CocoaDebugNavigationController.exit)
|
||||
|
||||
|
||||
let image = UIImage(named: "_icon_file_type_close", in: Bundle(for: CocoaDebugNavigationController.self), compatibleWith: nil)
|
||||
let leftItem = UIBarButtonItem(image: image,
|
||||
style: .done, target: self, action: selector)
|
||||
leftItem.tintColor = Color.mainGreen
|
||||
nav.topViewController?.navigationItem.leftBarButtonItem = leftItem
|
||||
//****** copy codes from LogNavigationViewController.swift ******
|
||||
|
||||
temp.append(nav)
|
||||
|
||||
self.viewControllers = temp
|
||||
}
|
||||
|
||||
//MARK: - target action
|
||||
@objc func exit() {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
//MARK: - show more than 5 tabs by CocoaDebug
|
||||
// override var traitCollection: UITraitCollection {
|
||||
// var realTraits = super.traitCollection
|
||||
// var lieTrait = UITraitCollection.init(horizontalSizeClass: .regular)
|
||||
// return UITraitCollection(traitsFrom: [realTraits, lieTrait])
|
||||
// }
|
||||
}
|
||||
|
||||
//MARK: - UITabBarDelegate
|
||||
extension CocoaDebugTabBarController {
|
||||
|
||||
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
|
||||
guard let items = self.tabBar.items else {return}
|
||||
|
||||
for index in 0...items.count-1 {
|
||||
if item == items[index] {
|
||||
CocoaDebugSettings.shared.tabBarSelectItem = index
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
70
Pods/CocoaDebug/Sources/Window/CocoaDebugViewController.swift
generated
Normal file
70
Pods/CocoaDebug/Sources/Window/CocoaDebugViewController.swift
generated
Normal file
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// Example
|
||||
// man
|
||||
//
|
||||
// Created by man 11/11/2018.
|
||||
// Copyright © 2020 man. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class CocoaDebugViewController: UIViewController {
|
||||
|
||||
var bubble = Bubble(frame: CGRect(origin: .zero, size: Bubble.size))
|
||||
var uiBlockingBubble = UIBlockingBubble(frame: CGRect(origin: .zero, size: UIBlockingBubble.size))
|
||||
|
||||
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
||||
bubble.updateOrientation(newSize: size)
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
self.view.backgroundColor = .clear
|
||||
|
||||
bubble.center = Bubble.originalPosition
|
||||
bubble.delegate = self
|
||||
view.addSubview(bubble)
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
WindowHelper.shared.displayedList = false
|
||||
if CocoaDebugSettings.shared.enableUIBlockingMonitoring {
|
||||
view.addSubview(uiBlockingBubble)
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
if CocoaDebugSettings.shared.enableUIBlockingMonitoring {
|
||||
uiBlockingBubble.updateFrame()
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
if CocoaDebugSettings.shared.enableUIBlockingMonitoring {
|
||||
uiBlockingBubble.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
func shouldReceive(point: CGPoint) -> Bool {
|
||||
if WindowHelper.shared.displayedList {
|
||||
return true
|
||||
}
|
||||
return bubble.frame.contains(point)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - BubbleDelegate
|
||||
extension CocoaDebugViewController: BubbleDelegate {
|
||||
|
||||
func didTapBubble() {
|
||||
WindowHelper.shared.displayedList = true
|
||||
let storyboard = UIStoryboard(name: "Manager", bundle: Bundle(for: CocoaDebug.self))
|
||||
guard let vc = storyboard.instantiateInitialViewController() else {return}
|
||||
vc.view.backgroundColor = .white
|
||||
vc.modalPresentationStyle = .fullScreen
|
||||
self.present(vc, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
39
Pods/CocoaDebug/Sources/Window/CocoaDebugWindow.swift
generated
Normal file
39
Pods/CocoaDebug/Sources/Window/CocoaDebugWindow.swift
generated
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Example
|
||||
// man
|
||||
//
|
||||
// Created by man 11/11/2018.
|
||||
// Copyright © 2020 man. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
protocol WindowDelegate: AnyObject {
|
||||
func isPointEvent(point: CGPoint) -> Bool
|
||||
}
|
||||
|
||||
class CocoaDebugWindow: UIWindow {
|
||||
|
||||
weak var delegate: WindowDelegate?
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
self.backgroundColor = .clear
|
||||
self.windowLevel = UIWindow.Level(rawValue: UIWindow.Level.alert.rawValue - 1)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
return self.delegate?.isPointEvent(point: point) ?? false
|
||||
}
|
||||
}
|
||||
|
||||
extension WindowHelper: WindowDelegate {
|
||||
func isPointEvent(point: CGPoint) -> Bool {
|
||||
return self.vc.shouldReceive(point: point)
|
||||
}
|
||||
}
|
||||
21
Pods/CocoaDebug/Sources/Window/Color.swift
generated
Normal file
21
Pods/CocoaDebug/Sources/Window/Color.swift
generated
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Example
|
||||
// man
|
||||
//
|
||||
// Created by man 11/11/2018.
|
||||
// Copyright © 2020 man. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
struct Color {
|
||||
|
||||
static var colorGradientHead: [CGColor] {
|
||||
return [UIColor(red:0.25, green:0.25, blue:0.25, alpha:1.00).cgColor,
|
||||
UIColor(red:0.15, green:0.15, blue:0.15, alpha:1.00).cgColor]
|
||||
}
|
||||
|
||||
static var mainGreen: UIColor {
|
||||
return CocoaDebug.mainColor.hexColor
|
||||
}
|
||||
}
|
||||
86
Pods/CocoaDebug/Sources/Window/UIBlockingBubble.swift
generated
Normal file
86
Pods/CocoaDebug/Sources/Window/UIBlockingBubble.swift
generated
Normal file
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// Example
|
||||
// man
|
||||
//
|
||||
// Created by man 11/11/2018.
|
||||
// Copyright © 2020 man. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class UIBlockingBubble: UIView {
|
||||
|
||||
static var size: CGSize {return CGSize(width: 70, height: 20)}
|
||||
|
||||
private var uiBlockingLabel: UILabel? = {
|
||||
return UILabel(frame: CGRect(x:0, y:0, width:size.width, height:size.height))
|
||||
}()
|
||||
|
||||
fileprivate func initLayer() {
|
||||
self.backgroundColor = .black
|
||||
self.layer.cornerRadius = 4
|
||||
self.sizeToFit()
|
||||
|
||||
if let uiBlockingLabel = uiBlockingLabel {
|
||||
self.addSubview(uiBlockingLabel)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - init
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: CGRect(x: UIScreen.main.bounds.width/4.0, y:1, width: frame.width, height: frame.height))
|
||||
|
||||
initLayer()
|
||||
|
||||
// uiBlockingLabel?.attributedText = uiBlockingLabel?.uiBlockingAttributedString(with: 60)
|
||||
|
||||
// WindowHelper.shared.uiBlockingCallback = { [weak self] value in
|
||||
// self?.uiBlockingLabel?.update(withValue: Float(value))
|
||||
// }
|
||||
|
||||
uiBlockingLabel?.textAlignment = .center
|
||||
uiBlockingLabel?.adjustsFontSizeToFitWidth = true
|
||||
uiBlockingLabel?.text = "Normal"
|
||||
uiBlockingLabel?.textColor = .white
|
||||
|
||||
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "CocoaDebug_Detected_UI_Blocking"), object: nil, queue: OperationQueue.main) { [weak self] _ in
|
||||
self?.uiBlockingLabel?.text = "Blocking"
|
||||
self?.uiBlockingLabel?.textColor = .red
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {[weak self] in
|
||||
self?.uiBlockingLabel?.text = "Normal"
|
||||
self?.uiBlockingLabel?.textColor = .white
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updateFrame() {
|
||||
if #available(iOS 11.0, *) {
|
||||
let safeAreaInsetsTop = UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 0
|
||||
if safeAreaInsetsTop > 24 { //iPhoneX
|
||||
center.x = UIScreen.main.bounds.width/2.0
|
||||
center.y = 39
|
||||
|
||||
let string = CocoaDebugDeviceInfo.sharedInstance().getPlatformString
|
||||
if string == "iPhone 12 mini" {
|
||||
center.y = 43
|
||||
} else if string == "iPhone 12" {
|
||||
center.y = 41
|
||||
} else if string == "iPhone 12 Pro" {
|
||||
center.y = 41
|
||||
} else if string == "iPhone 12 Pro Max" {
|
||||
center.y = 41
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
deinit {
|
||||
//notification
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
}
|
||||
96
Pods/CocoaDebug/Sources/Window/WindowHelper.swift
generated
Normal file
96
Pods/CocoaDebug/Sources/Window/WindowHelper.swift
generated
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// Example
|
||||
// man
|
||||
//
|
||||
// Created by man 11/11/2018.
|
||||
// Copyright © 2020 man. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
public class WindowHelper: NSObject {
|
||||
public static let shared = WindowHelper()
|
||||
|
||||
var window: CocoaDebugWindow
|
||||
var displayedList = false
|
||||
lazy var vc = CocoaDebugViewController() //must lazy init, otherwise crash
|
||||
|
||||
//UIBlocking
|
||||
// fileprivate var uiBlockingCounter = UIBlockingCounter()
|
||||
// var uiBlockingCallback:((Int) -> Void)?
|
||||
|
||||
|
||||
private override init() {
|
||||
window = CocoaDebugWindow(frame: UIScreen.main.bounds)
|
||||
// This is for making the window not to effect the StatusBarStyle
|
||||
window.bounds.size.height = UIScreen.main.bounds.height.nextDown
|
||||
super.init()
|
||||
|
||||
// uiBlockingCounter.delegate = self
|
||||
}
|
||||
|
||||
|
||||
public func enable() {
|
||||
if window.rootViewController == vc {
|
||||
return
|
||||
}
|
||||
|
||||
window.rootViewController = vc
|
||||
window.delegate = self
|
||||
window.isHidden = false
|
||||
|
||||
if CocoaDebugSettings.shared.enableUIBlockingMonitoring == true {
|
||||
startUIBlockingMonitoring()
|
||||
}
|
||||
|
||||
|
||||
if #available(iOS 13.0, *) {
|
||||
var success: Bool = false
|
||||
|
||||
for i in 0...10 {
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + (0.1 * Double(i))) {[weak self] in
|
||||
if success == true {return}
|
||||
|
||||
for scene in UIApplication.shared.connectedScenes {
|
||||
if let windowScene = scene as? UIWindowScene {
|
||||
self?.window.windowScene = windowScene
|
||||
success = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func disable() {
|
||||
if window.rootViewController == nil {
|
||||
return
|
||||
}
|
||||
window.rootViewController = nil
|
||||
window.delegate = nil
|
||||
window.isHidden = true
|
||||
stopUIBlockingMonitoring()
|
||||
}
|
||||
|
||||
public func startUIBlockingMonitoring() {
|
||||
// uiBlockingCounter.startMonitoring()
|
||||
_RunloopMonitor.shared().begin()
|
||||
}
|
||||
|
||||
public func stopUIBlockingMonitoring() {
|
||||
// uiBlockingCounter.stopMonitoring()
|
||||
_RunloopMonitor.shared().end()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - UIBlockingCounterDelegate
|
||||
//extension WindowHelper: UIBlockingCounterDelegate {
|
||||
// @objc public func uiBlockingCounter(_ counter: UIBlockingCounter, didUpdateFramesPerSecond uiBlocking: Int) {
|
||||
// if let uiBlockingCallback = uiBlockingCallback {
|
||||
// uiBlockingCallback(uiBlocking)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user