Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Feature/make bubble head optional #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion Example/ExampleDotzu/ExampleDotzu/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

// Customize Dotzu programmatically using LogSettings.
// Some of the LogSettings options are also available inside Dotzu Settings user interface.
//
// Following example shows how to use Dotzu without bubble head.
// Example uses shake gesture to launch Dotzu Manager
/*
// Set up LogSettings before enabling Dotzu
LogsSettings.shared.showBubbleHead = false
*/
Dotzu.sharedManager.enable()

return true
}
}

// One of the way to show Dotzu Manager
#if DEBUG
extension UIWindow {

override open func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
if motion == .motionShake {
if let controller = Dotzu.sharedManager.viewController() {
self.rootViewController?.present(controller, animated: true, completion: nil)
}
}
}
}
#endif
31 changes: 21 additions & 10 deletions Framework/Dotzu/Dotzu/DotzuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import UIKit

public class Dotzu: NSObject {
public static let sharedManager = Dotzu()
private var window: ManagerWindow
fileprivate let controller = ManagerViewController()
private var window: ManagerWindow?
fileprivate var controller: ManagerViewController?
private let cache = NSCache<AnyObject, AnyObject>()
private let userDefault = UserDefaults.standard
var displayedList = false
Expand All @@ -24,19 +24,26 @@ public class Dotzu: NSObject {
}

public func enable() {

initLogsManager()
self.window.rootViewController = self.controller
self.window.makeKeyAndVisible()
self.window.delegate = self

if LogsSettings.shared.showBubbleHead {
self.window = ManagerWindow(frame: UIScreen.main.bounds)
self.controller = ManagerViewController()
}
self.window?.rootViewController = self.controller
self.window?.makeKeyAndVisible()
self.window?.delegate = self

LoggerNetwork.shared.enable = LogsSettings.shared.network
Logger.shared.enable = true
LoggerCrash.shared.enable = true
}

public func disable() {
self.window.rootViewController = nil
self.window.resignKey()
self.window.removeFromSuperview()
self.window?.rootViewController = nil
self.window?.resignKey()
self.window?.removeFromSuperview()
Logger.shared.enable = false
LoggerCrash.shared.enable = false
LoggerNetwork.shared.enable = false
Expand All @@ -46,14 +53,18 @@ public class Dotzu: NSObject {
session.protocolClasses?.insert(LoggerNetwork.self, at: 0)
}

public func viewController () -> UIViewController? {
let storyboard = UIStoryboard(name: "Manager", bundle: Bundle(for: ManagerViewController.self))
return storyboard.instantiateInitialViewController()
}

override init() {
self.window = ManagerWindow(frame: UIScreen.main.bounds)
super.init()
}
}

extension Dotzu: ManagerWindowDelegate {
func isPointEvent(point: CGPoint) -> Bool {
return self.controller.shouldReceive(point: point)
return self.controller?.shouldReceive(point: point) ?? false
}
}
20 changes: 13 additions & 7 deletions Framework/Dotzu/Dotzu/LogsSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,47 @@

import Foundation

class LogsSettings {
public class LogsSettings {

static let shared = LogsSettings()
public static let shared = LogsSettings()

var overridePrint: Bool {
public var overridePrint: Bool {
didSet {
UserDefaults.standard.set(overridePrint, forKey: "enableOverridePrint")
}
}
var resetLogsStart: Bool {
public var resetLogsStart: Bool {
didSet {
UserDefaults.standard.set(resetLogsStart, forKey: "resetLogsStart")
}
}
var fileInfo: Bool {
public var fileInfo: Bool {
didSet {
UserDefaults.standard.set(fileInfo, forKey: "fileInfoDsisplayed")
}
}
var date: Bool {
public var date: Bool {
didSet {
UserDefaults.standard.set(fileInfo, forKey: "dateDisplayed")
}
}
var network: Bool {
public var network: Bool {
didSet {
UserDefaults.standard.set(fileInfo, forKey: "networkLoggerEnabled")
}
}
public var showBubbleHead: Bool {
didSet {
UserDefaults.standard.set(showBubbleHead, forKey: "showBubbleHead")
}
}

init() {
overridePrint = UserDefaults.standard.bool2(forKey: "enableOverridePrint")
resetLogsStart = UserDefaults.standard.bool2(forKey: "resetLogsStart", defaultValue: false)
fileInfo = UserDefaults.standard.bool2(forKey: "fileInfoDisplayed")
date = UserDefaults.standard.bool2(forKey: "dateDisplayed")
network = UserDefaults.standard.bool2(forKey: "networkLoggerEnabled")
showBubbleHead = UserDefaults.standard.bool2(forKey: "showBubbleHead")
}
}