-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from mehdiimrz/master
Add http and grpc traffic monitor
- Loading branch information
Showing
49 changed files
with
2,471 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// Colors.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 7/3/21. | ||
// | ||
import UIKit | ||
|
||
struct Colors { | ||
|
||
struct UI{ | ||
static public let wordsInEvidence = UIColor(hexString: "#dadfe1") | ||
static public let wordFocus = UIColor(hexString: "#f7ca18") | ||
} | ||
|
||
struct Gray{ | ||
static public let darkestGray = UIColor(hexString: "#666666") | ||
static public let darkerGray = UIColor(hexString: "#888888") | ||
static public let darkGray = UIColor(hexString: "#999999") | ||
static public let midGray = UIColor(hexString: "#BBBBBB") | ||
static public let lightGray = UIColor(hexString: "#CCCCCC") | ||
static public let lighestGray = UIColor(hexString: "#E7E7E7") | ||
} | ||
|
||
struct HTTPCode{ | ||
static public let Success = UIColor(hexString: "#297E4C") //2xx | ||
static public let Redirect = UIColor(hexString: "#3D4140") //3xx | ||
static public let ClientError = UIColor(hexString: "#D97853") //4xx | ||
static public let ServerError = UIColor(hexString: "#D32C58") //5xx | ||
static public let Generic = UIColor(hexString: "#999999") //Others | ||
} | ||
} | ||
|
||
extension UIColor{ | ||
|
||
convenience init(hexString:String) { | ||
let hexString:String = hexString.trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines) as String | ||
let scanner = Scanner(string: hexString) | ||
if (hexString.hasPrefix("#")) { | ||
scanner.scanLocation = 1 | ||
} | ||
|
||
var color:UInt32 = 0 | ||
scanner.scanHexInt32(&color) | ||
|
||
let mask = 0x000000FF | ||
let r = Int(color >> 16) & mask | ||
let g = Int(color >> 8) & mask | ||
let b = Int(color) & mask | ||
|
||
let red = CGFloat(r) / 255.0 | ||
let green = CGFloat(g) / 255.0 | ||
let blue = CGFloat(b) / 255.0 | ||
self.init(red:red, green:green, blue:blue, alpha:1) | ||
} | ||
|
||
func toHexString() -> String { | ||
var r:CGFloat = 0 | ||
var g:CGFloat = 0 | ||
var b:CGFloat = 0 | ||
var a:CGFloat = 0 | ||
getRed(&r, green: &g, blue: &b, alpha: &a) | ||
let rgb:Int = (Int)(r*255)<<16 | (Int)(g*255)<<8 | (Int)(b*255)<<0 | ||
return NSString(format:"#%06x", rgb) as String | ||
} | ||
|
||
func randomGreyColor() -> String{ | ||
let value = arc4random_uniform(255) | ||
let grayscale = (value << 16) | (value << 8) | value; | ||
let color = "#" + String(grayscale, radix: 16); | ||
|
||
return color | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Config.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 6/9/21. | ||
// | ||
|
||
import Foundation | ||
|
||
//Notifications | ||
let fireWormholy = NSNotification.Name(rawValue: "wormholy_fire") | ||
let newRequestNotification = NSNotification.Name(rawValue: "wormholy_new_request") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Date+Extension.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 7/4/21. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Date{ | ||
func stringWithFormat(dateFormat: String, timezone: TimeZone? = nil) -> String?{ | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateFormat = dateFormat | ||
if timezone != nil{ | ||
dateFormatter.timeZone = timezone! | ||
} | ||
return dateFormatter.string(from: self) | ||
} | ||
} | ||
|
||
|
||
extension Bundle { | ||
static var NetShearsBundle: Bundle { | ||
let podBundle = Bundle(for: NetShears.classForCoder()) | ||
if let bundleURL = podBundle.url(forResource: "NetShears", withExtension: "bundle"){ | ||
if let bundle = Bundle(url: bundleURL) { | ||
return bundle | ||
} | ||
} | ||
|
||
return Bundle(for: NetShears.classForCoder()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// Double+Extension.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 6/9/21. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Double { | ||
func formattedMilliseconds() -> String{ | ||
|
||
let rounded = self | ||
if rounded < 1000 { | ||
return "\(Int(rounded))ms" | ||
} else if rounded < 1000 * 60 { | ||
let seconds = rounded / 1000 | ||
return "\(Int(seconds))s" | ||
} else if rounded < 1000 * 60 * 60 { | ||
let secondsTemp = rounded / 1000 | ||
let minutes = secondsTemp / 60 | ||
let seconds = (rounded - minutes * 60 * 1000) / 1000 | ||
return "\(Int(minutes))m \(Int(seconds))s" | ||
} else if self < 1000 * 60 * 60 * 24 { | ||
let minutesTemp = rounded / 1000 / 60 | ||
let hours = minutesTemp / 60 | ||
let minutes = (rounded - hours * 60 * 60 * 1000) / 1000 / 60 | ||
let seconds = (rounded - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000 | ||
return "\(Int(hours))h \(Int(minutes))m \(Int(seconds))s" | ||
} else { | ||
let hoursTemp = rounded / 1000 / 60 / 60 | ||
let days = hoursTemp / 24 | ||
let hours = (rounded - days * 24 * 60 * 60 * 1000) / 1000 / 60 / 60 | ||
let minutes = (rounded - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60 | ||
let seconds = (rounded - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000 | ||
return "\(Int(days))d \(Int(hours))h \(Int(minutes))m \(Int(seconds))s" | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Sources/NetShears/Extension/NSMutableAttributedString+Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// NSMutableAttributedString+Extension.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 6/9/21. | ||
// | ||
|
||
import UIKit | ||
|
||
extension NSMutableAttributedString { | ||
@discardableResult func bold(_ text: String) -> NSMutableAttributedString { | ||
let attrs: [NSAttributedString.Key: Any] = [.font: UIFont.boldSystemFont(ofSize: 15)] | ||
let boldString = NSMutableAttributedString(string:text, attributes: attrs) | ||
append(boldString) | ||
return self | ||
} | ||
|
||
@discardableResult func normal(_ text: String) -> NSMutableAttributedString { | ||
let attrs: [NSAttributedString.Key: Any] = [.font: UIFont.systemFont(ofSize: 14)] | ||
let normal = NSMutableAttributedString(string:text, attributes: attrs) | ||
append(normal) | ||
return self | ||
} | ||
|
||
func changeTextColor(to color: UIColor) -> NSMutableAttributedString { | ||
self.addAttribute(NSAttributedString.Key.foregroundColor, value: color , range: NSRange(location: 0,length: string.count)) | ||
return self | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Sources/NetShears/Extension/NSNotification+Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// NSNotification+Extension.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 6/9/21. | ||
// | ||
|
||
import Foundation | ||
|
||
extension NSNotification.Name { | ||
static let NewRequestNotification = NSNotification.Name(rawValue: "Name.NetShearsNewRequest") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// String+Extension.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 6/9/21. | ||
// | ||
|
||
import Foundation | ||
|
||
extension String { | ||
//substrings of equal length | ||
func characters(n: Int) -> String{ | ||
return String(prefix(n)) | ||
} | ||
|
||
var prettyPrintedJSON: String? { | ||
guard let stringData = self.data(using: .utf8), | ||
let object = try? JSONSerialization.jsonObject(with: stringData, options: []), | ||
let jsonData = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]), | ||
let formattedJSON = String(data: jsonData, encoding: .utf8) else { return nil } | ||
|
||
return formattedJSON.replacingOccurrences(of: "\\/", with: "/") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// UIApplication+Extension.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 7/1/21. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIApplication { | ||
// class func topViewController(controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? { | ||
// if let navigationController = controller as? UINavigationController { | ||
// return topViewController(controller: navigationController.visibleViewController) | ||
// } | ||
// if let tabController = controller as? UITabBarController { | ||
// if let selected = tabController.selectedViewController { | ||
// return topViewController(controller: selected) | ||
// } | ||
// } | ||
// if let presented = controller?.presentedViewController { | ||
// return topViewController(controller: presented) | ||
// } | ||
// return controller | ||
// } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// UIStoryBoard+Extension.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 6/9/21. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIStoryboard { | ||
static var NetShearsStoryBoard: UIStoryboard { | ||
return UIStoryboard(name: "Flow", bundle: Bundle.NetShearsBundle) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// UIView+Extension.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 6/9/21. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIView { | ||
@discardableResult | ||
func fillInSuperview(top: CGFloat = 0, trailing: CGFloat = 0, bottom: CGFloat = 0, leading: CGFloat = 0) -> Bool { | ||
guard let superview = superview else { | ||
return false | ||
} | ||
translatesAutoresizingMaskIntoConstraints = false | ||
topAnchor.constraint(equalTo: superview.topAnchor, constant: top).isActive = true | ||
bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: -bottom).isActive = true | ||
leftAnchor.constraint(equalTo: superview.leftAnchor, constant: leading).isActive = true | ||
rightAnchor.constraint(equalTo: superview.rightAnchor, constant: -trailing).isActive = true | ||
return true | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Sources/NetShears/Extension/UIViewController+Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// UIViewController+Extension.swift | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 6/9/21. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIViewController { | ||
|
||
static func currentViewController(_ viewController: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? { | ||
guard let viewController = viewController else { return nil } | ||
|
||
if let viewController = viewController as? UINavigationController { | ||
if let viewController = viewController.visibleViewController { | ||
return currentViewController(viewController) | ||
} else { | ||
return currentViewController(viewController.topViewController) | ||
} | ||
} else if let viewController = viewController as? UITabBarController { | ||
if let viewControllers = viewController.viewControllers, viewControllers.count > 5, viewController.selectedIndex >= 4 { | ||
return currentViewController(viewController.moreNavigationController) | ||
} else { | ||
return currentViewController(viewController.selectedViewController) | ||
} | ||
} else if let viewController = viewController.presentedViewController { | ||
return currentViewController(viewController) | ||
} else if viewController.children.count > 0 { | ||
return viewController.children[0] | ||
} else { | ||
return viewController | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// | ||
// URLRequest+Extension.swift | ||
// | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 6/9/21. | ||
// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// | ||
// URLRequestFactory.swift | ||
// | ||
// NetShears | ||
// | ||
// Created by Mehdi Mirzaie on 6/4/21. | ||
// | ||
|
Oops, something went wrong.