Skip to content
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
168 changes: 86 additions & 82 deletions netfox/Core/NFX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import Foundation
#if os(OSX)
import Cocoa
import Cocoa
#else
import UIKit
import UIKit
#endif

let nfxVersion = "1.8"
Expand All @@ -22,9 +22,9 @@ let nfxWillCloseNotification = "NFXWillCloseNotification"
open class NFX: NSObject
{
#if os(OSX)
var windowController: NFXWindowController?
let mainMenu: NSMenu? = NSApp.mainMenu?.items[1].submenu
var nfxMenuItem: NSMenuItem = NSMenuItem(title: "netfox", action: #selector(NFX.show), keyEquivalent: String.init(describing: (character: NSF9FunctionKey, length: 1)))
var windowController: NFXWindowController?
let mainMenu: NSMenu? = NSApp.mainMenu?.items[1].submenu
var nfxMenuItem: NSMenuItem = NSMenuItem(title: "netfox", action: #selector(NFX.show), keyEquivalent: String.init(describing: (character: NSF9FunctionKey, length: 1)))
#endif

// swiftSharedInstance is not accessible from ObjC
Expand Down Expand Up @@ -55,24 +55,24 @@ open class NFX: NSObject
fileprivate var selectedGesture: ENFXGesture = .shake
fileprivate var ignoredURLs = [String]()
fileprivate var filters = [Bool]()
fileprivate var lastVisitDate: Date = Date()
internal var lastVisitDate: Date = Date()
internal var cacheStoragePolicy = URLCache.StoragePolicy.notAllowed

@objc open func start()
{
guard !self.started else {
showMessage("Already started!")
return
}

self.started = true
register()
enable()
clearOldData()
showMessage("Started!")
#if os(OSX)
self.addNetfoxToMainMenu()
#endif
#if os(OSX)
self.addNetfoxToMainMenu()
#endif
}

@objc open func stop()
Expand All @@ -82,9 +82,9 @@ open class NFX: NSObject
clearOldData()
self.started = false
showMessage("Stopped!")
#if os(OSX)
self.removeNetfoxFromMainmenu()
#endif
#if os(OSX)
self.removeNetfoxFromMainmenu()
#endif
}

fileprivate func showMessage(_ msg: String) {
Expand Down Expand Up @@ -129,13 +129,13 @@ open class NFX: NSObject
@objc open func setGesture(_ gesture: ENFXGesture)
{
self.selectedGesture = gesture
#if os(OSX)
if gesture == .shake {
self.addNetfoxToMainMenu()
} else {
self.removeNetfoxFromMainmenu()
}
#endif
#if os(OSX)
if gesture == .shake {
self.addNetfoxToMainMenu()
} else {
self.removeNetfoxFromMainmenu()
}
#endif
}

@objc open func show()
Expand All @@ -144,12 +144,24 @@ open class NFX: NSObject
showNFX()
}

public func showManually() -> NFXViewController? {
guard self.started else { return nil }

#if os(OSX)
return NFXListController_OSX()
#elseif os(iOS)
return NFXListController_iOS()
#else
return nil
#endif
}

@objc open func hide()
{
guard self.started else { return }
hideNFX()
}

@objc open func toggle()
{
guard self.started else { return }
Expand All @@ -161,11 +173,6 @@ open class NFX: NSObject
self.ignoredURLs.append(url)
}

internal func getLastVisitDate() -> Date
{
return self.lastVisitDate
}

fileprivate func showNFX()
{
if self.presented {
Expand All @@ -174,7 +181,6 @@ open class NFX: NSObject

self.showNFXFollowingPlatform()
self.presented = true

}

fileprivate func hideNFX()
Expand All @@ -183,13 +189,11 @@ open class NFX: NSObject
return
}

NotificationCenter.default.post(name: Notification.Name.NFXDeactivateSearch, object: nil)
self.hideNFXFollowingPlatform { () -> Void in
self.presented = false
self.lastVisitDate = Date()
}
}

fileprivate func toggleNFX()
{
self.presented ? hideNFX() : showNFX()
Expand Down Expand Up @@ -261,64 +265,64 @@ extension NFX {

presentingViewController?.present(navigationController, animated: true, completion: nil)
}

fileprivate func hideNFXFollowingPlatform(_ completion: (() -> Void)?)
{
presentingViewController?.dismiss(animated: true, completion: { () -> Void in
if let notNilCompletion = completion {
notNilCompletion()
}
})
}
}

#elseif os(OSX)

extension NFX {

public func windowDidClose() {
self.presented = false

fileprivate func hideNFXFollowingPlatform(_ completion: (() -> Void)?)
{
presentingViewController?.dismiss(animated: true, completion: { () -> Void in
if let notNilCompletion = completion {
notNilCompletion()
}
})
}
}

private func setupNetfoxMenuItem() {
self.nfxMenuItem.target = self
self.nfxMenuItem.action = #selector(NFX.motionDetected)
self.nfxMenuItem.keyEquivalent = "n"
self.nfxMenuItem.keyEquivalentModifierMask = NSEvent.ModifierFlags(rawValue: UInt(Int(NSEvent.ModifierFlags.command.rawValue | NSEvent.ModifierFlags.shift.rawValue)))
}
#elseif os(OSX)

public func addNetfoxToMainMenu() {
self.setupNetfoxMenuItem()
if let menu = self.mainMenu {
menu.insertItem(self.nfxMenuItem, at: 0)
extension NFX {

public func windowDidClose() {
self.presented = false
}
}

public func removeNetfoxFromMainmenu() {
if let menu = self.mainMenu {
menu.removeItem(self.nfxMenuItem)

private func setupNetfoxMenuItem() {
self.nfxMenuItem.target = self
self.nfxMenuItem.action = #selector(NFX.motionDetected)
self.nfxMenuItem.keyEquivalent = "n"
self.nfxMenuItem.keyEquivalentModifierMask = NSEvent.ModifierFlags(rawValue: UInt(Int(NSEvent.ModifierFlags.command.rawValue | NSEvent.ModifierFlags.shift.rawValue)))
}
}

public func showNFXFollowingPlatform() {
if self.windowController == nil {
#if !swift(>=4.0)
self.windowController = NFXWindowController(windowNibName: "NetfoxWindow")
#else
self.windowController = NFXWindowController(windowNibName: NSNib.Name(rawValue: "NetfoxWindow"))
#endif

public func addNetfoxToMainMenu() {
self.setupNetfoxMenuItem()
if let menu = self.mainMenu {
menu.insertItem(self.nfxMenuItem, at: 0)
}
}
self.windowController?.showWindow(nil)
}

public func hideNFXFollowingPlatform(completion: (() -> Void)?)
{
self.windowController?.close()
if let notNilCompletion = completion {
notNilCompletion()

public func removeNetfoxFromMainmenu() {
if let menu = self.mainMenu {
menu.removeItem(self.nfxMenuItem)
}
}

public func showNFXFollowingPlatform() {
if self.windowController == nil {
#if !swift(>=4.0)
self.windowController = NFXWindowController(windowNibName: "NetfoxWindow")
#else
self.windowController = NFXWindowController(windowNibName: NSNib.Name(rawValue: "NetfoxWindow"))
#endif
}
self.windowController?.showWindow(nil)
}

public func hideNFXFollowingPlatform(completion: (() -> Void)?)
{
self.windowController?.close()
if let notNilCompletion = completion {
notNilCompletion()
}
}

}

}

#endif
4 changes: 2 additions & 2 deletions netfox/Core/NFXConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import UIKit
typealias NFXColor = UIColor
typealias NFXFont = UIFont
typealias NFXImage = UIImage
typealias NFXViewController = UIViewController
public typealias NFXViewController = UIViewController

#elseif os(OSX)
import Cocoa

typealias NFXColor = NSColor
typealias NFXFont = NSFont
typealias NFXImage = NSImage
typealias NFXViewController = NSViewController
public typealias NFXViewController = NSViewController
#endif
3 changes: 1 addition & 2 deletions netfox/Core/NFXHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ extension String
}

public extension NSNotification.Name {
static let NFXDeactivateSearch = Notification.Name("NFXDeactivateSearch")
static let NFXReloadData = Notification.Name("NFXReloadData")
public static let NFXReloadData = Notification.Name("NFXReloadData")
public static let NFXAddedModel = Notification.Name("NFXAddedModel")
public static let NFXClearedModels = Notification.Name("NFXClearedModels")
}
19 changes: 16 additions & 3 deletions netfox/Core/NFXListController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@
import Foundation

class NFXListController: NFXGenericController {

var tableData = [NFXHTTPModel]()
var filteredTableData = [NFXHTTPModel]()

override func viewDidLoad() {
super.viewDidLoad()
}

#if os(OSX)
override func viewDidDisappear() {
super.viewDidDisappear()
NFX.sharedInstance().lastVisitDate = Date()
}
#elseif os(iOS)
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
NFX.sharedInstance().lastVisitDate = Date()
}
#endif



func updateSearchResultsForSearchControllerWithString(_ searchString: String)
{
Expand All @@ -28,7 +41,7 @@ class NFXListController: NFXGenericController {
let array = (NFXHTTPModelManager.sharedInstance.getModels() as NSArray).filtered(using: searchPredicate)
self.filteredTableData = array as! [NFXHTTPModel]
}

@objc func reloadTableViewData()
{
}
Expand Down
2 changes: 1 addition & 1 deletion netfox/OSX/NFXListCell_OSX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class NFXListCell_OSX: NSTableCellView

func isNewBasedOnDate(responseDate: NSDate)
{
if responseDate.isGreaterThan(NFX.sharedInstance().getLastVisitDate()) {
if responseDate.isGreaterThan(NFX.sharedInstance().lastVisitDate) {
self.isNew()
} else {
self.isOld()
Expand Down
6 changes: 0 additions & 6 deletions netfox/OSX/NFXListController_OSX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class NFXListController_OSX: NFXListController, NSTableViewDelegate, NSTableView
searchField.delegate = self

NotificationCenter.default.addObserver(self, selector: #selector(NFXListController.reloadTableViewData), name: NSNotification.Name.NFXReloadData, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(NFXListController_OSX.deactivateSearchController), name: NSNotification.Name.NFXDeactivateSearch, object: nil)
}

// MARK: Notifications
Expand All @@ -44,11 +43,6 @@ class NFXListController_OSX: NFXListController, NSTableViewDelegate, NSTableView
}
}

@objc func deactivateSearchController()
{
self.isSearchControllerActive = false
}

// MARK: Search

func updateSearchResultsForSearchController()
Expand Down
2 changes: 1 addition & 1 deletion netfox/iOS/NFXListCell_iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class NFXListCell: UITableViewCell

func isNewBasedOnDate(_ responseDate: Date)
{
if responseDate.isGreaterThanDate(NFX.sharedInstance().getLastVisitDate()) {
if responseDate.isGreaterThanDate(NFX.sharedInstance().lastVisitDate) {
self.isNew()
} else {
self.isOld()
Expand Down
Loading