Factored network updates into its own class. Delivered via notification

This commit is contained in:
Grant Limberg 2016-06-16 20:53:55 -07:00
commit c8f85ffec9
6 changed files with 145 additions and 81 deletions

View file

@ -21,8 +21,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var transientMonitor: AnyObject? = nil
func applicationDidFinishLaunching(aNotification: NSNotification) {
let monitor = NetworkMonitor()
func applicationDidFinishLaunching(aNotification: NSNotification) {
let nc = NSNotificationCenter.defaultCenter()
nc.addObserver(self, selector: #selector(onNetworkListUpdated(_:)), name: networkUpdateKey, object: nil)
statusItem.image = NSImage(named: "MenuBarIconMac")
@ -50,6 +53,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
let nc = NSNotificationCenter.defaultCenter()
nc.removeObserver(self)
}
@ -89,5 +94,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func quit() {
NSApp.performSelector(#selector(NSApp.terminate(_:)), withObject: nil, afterDelay: 0.0)
}
func onNetworkListUpdated(note: NSNotification) {
let netList = note.userInfo!["networks"] as! [Network]
(networkListPopover.contentViewController as! ShowNetworksViewController).setNetworks(netList)
}
}