mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-18 18:56:24 +00:00
add a timer to retrieve the network list every second.
This commit is contained in:
parent
c8750e5812
commit
bae0060552
@ -14,6 +14,9 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable
|
|||||||
|
|
||||||
var networkList: [Network] = [Network]()
|
var networkList: [Network] = [Network]()
|
||||||
|
|
||||||
|
|
||||||
|
var timer: NSTimer? = nil
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
// Do view setup here.
|
// Do view setup here.
|
||||||
@ -45,10 +48,36 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable
|
|||||||
override func viewWillAppear() {
|
override func viewWillAppear() {
|
||||||
super.viewWillAppear()
|
super.viewWillAppear()
|
||||||
|
|
||||||
|
updateNetworkInfo()
|
||||||
|
|
||||||
|
self.timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(updateNetworkInfo), userInfo: nil, repeats: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillDisappear() {
|
||||||
|
super.viewWillDisappear()
|
||||||
|
|
||||||
|
self.timer?.invalidate()
|
||||||
|
|
||||||
let filePath = dataFile()
|
let filePath = dataFile()
|
||||||
|
NSKeyedArchiver.archiveRootObject(self.networkList, toFile: filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteNetworkFromList(nwid: String) {
|
||||||
|
if let nwid = UInt64(nwid, radix: 16) {
|
||||||
|
let index = findNetworkWithID(nwid)
|
||||||
|
|
||||||
|
if index != NSNotFound {
|
||||||
|
networkList.removeAtIndex(index)
|
||||||
|
tableView.reloadData()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateNetworkInfo() {
|
||||||
|
let filePath = self.dataFile()
|
||||||
|
|
||||||
if NSFileManager.defaultManager().fileExistsAtPath(filePath) {
|
if NSFileManager.defaultManager().fileExistsAtPath(filePath) {
|
||||||
networkList = NSKeyedUnarchiver.unarchiveObjectWithFile(filePath) as! [Network]
|
self.networkList = NSKeyedUnarchiver.unarchiveObjectWithFile(filePath) as! [Network]
|
||||||
|
|
||||||
ServiceCom.getNetworkList() { (networkList) -> Void in
|
ServiceCom.getNetworkList() { (networkList) -> Void in
|
||||||
|
|
||||||
@ -93,24 +122,6 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillDisappear() {
|
|
||||||
super.viewWillDisappear()
|
|
||||||
|
|
||||||
let filePath = dataFile()
|
|
||||||
NSKeyedArchiver.archiveRootObject(self.networkList, toFile: filePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func deleteNetworkFromList(nwid: String) {
|
|
||||||
if let nwid = UInt64(nwid, radix: 16) {
|
|
||||||
let index = findNetworkWithID(nwid)
|
|
||||||
|
|
||||||
if index != NSNotFound {
|
|
||||||
networkList.removeAtIndex(index)
|
|
||||||
tableView.reloadData()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NSTableViewDataSource
|
// NSTableViewDataSource
|
||||||
|
|
||||||
func numberOfRowsInTableView(tableView: NSTableView) -> Int {
|
func numberOfRowsInTableView(tableView: NSTableView) -> Int {
|
||||||
|
Loading…
Reference in New Issue
Block a user