misc bug fixes related to default routes

This commit is contained in:
Grant Limberg 2016-06-26 18:18:59 -07:00
parent 1756e8b0f2
commit 3fc11e2278
6 changed files with 57 additions and 33 deletions

View File

@ -164,6 +164,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
networkName = "\(id) (\(net.name))"
}
if net.allowDefault && net.connected {
networkName += " [default]"
}
let item = NSMenuItem(title: networkName, action: #selector(AppDelegate.toggleNetwork(_:)), keyEquivalent: "")
if net.connected {

View File

@ -45,6 +45,10 @@ class JoinNetworkViewController: NSViewController, NSComboBoxDelegate, NSComboBo
override func viewWillAppear() {
super.viewWillAppear()
allowManagedCheckBox.state = NSOnState
allowGlobalCheckBox.state = NSOffState
allowDefaultCheckBox.state = NSOffState
let defaults = NSUserDefaults.standardUserDefaults()
let vals = defaults.stringArrayForKey(joinedNetworksKey)

View File

@ -62,7 +62,7 @@
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rz3-0a-oNA">
<rect key="frame" x="238" y="59" width="141" height="18"/>
<buttonCell key="cell" type="check" title="Allow Default Route" alternateTitle="Allow override of default route full tunnel'" bezelStyle="regularSquare" imagePosition="left" inset="2" id="Lkd-XI-Kcu">
<buttonCell key="cell" type="check" title="Allow Default Route" bezelStyle="regularSquare" imagePosition="left" inset="2" id="Lkd-XI-Kcu">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>

View File

@ -263,7 +263,7 @@ class Network: NSObject, NSCoding {
func defaultRouteExists(netList: [Network]) -> Bool {
for net in netList {
if net.allowDefault {
if net.allowDefault && net.connected {
return true
}
}

View File

@ -70,29 +70,33 @@ class NetworkMonitor: NSObject {
var networks = self.savedNetworks
for nw in receivedNetworks {
let index = findNetworkWithID(nw.nwid)
let index = findSavedNetworkWithID(nw.nwid)
if index != NSNotFound {
networks[index] = nw
}
networks.sortInPlace({ (left, right) -> Bool in
if left.nwid < right.nwid {
return true
}
return false
})
objc_sync_enter(allNetworks)
allNetworks = networks
objc_sync_exit(allNetworks)
saveNetworks()
let nc = NSNotificationCenter.defaultCenter()
nc.postNotificationName(networkUpdateKey, object: nil, userInfo: ["networks": networks])
else {
networks.append(nw)
}
}
networks.sortInPlace({ (left, right) -> Bool in
if left.nwid < right.nwid {
return true
}
return false
})
objc_sync_enter(allNetworks)
allNetworks = networks
objc_sync_exit(allNetworks)
saveNetworks()
let nc = NSNotificationCenter.defaultCenter()
nc.postNotificationName(networkUpdateKey, object: nil, userInfo: ["networks": networks])
}
private func findNetworkWithID(nwid: UInt64) -> Int {
@ -106,6 +110,17 @@ class NetworkMonitor: NSObject {
return NSNotFound
}
private func findSavedNetworkWithID(nwid: UInt64) -> Int {
for (index, element) in savedNetworks.enumerate() {
if element.nwid == nwid {
return index
}
}
return NSNotFound
}
private func saveNetworks() {
let file = dataFile()

View File

@ -76,6 +76,21 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable
cell.bridgingField.stringValue = network.bridge ? "ENABLED" : "DISABLED"
cell.deviceField.stringValue = network.portDeviceName
if network.connected {
cell.connectedCheckbox.state = NSOnState
cell.allowDefault.enabled = true
cell.allowGlobal.enabled = true
cell.allowManaged.enabled = true
}
else {
cell.connectedCheckbox.state = NSOffState
cell.allowDefault.enabled = false
cell.allowGlobal.enabled = false
cell.allowManaged.enabled = false
}
if network.allowDefault {
cell.allowDefault.state = NSOnState
@ -101,20 +116,7 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable
cell.addressesField.stringValue += "\n"
}
if network.connected {
cell.connectedCheckbox.state = NSOnState
cell.allowDefault.enabled = true
cell.allowGlobal.enabled = true
cell.allowManaged.enabled = true
}
else {
cell.connectedCheckbox.state = NSOffState
cell.allowDefault.enabled = false
cell.allowGlobal.enabled = false
cell.allowManaged.enabled = false
}
return cell
}