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))" networkName = "\(id) (\(net.name))"
} }
if net.allowDefault && net.connected {
networkName += " [default]"
}
let item = NSMenuItem(title: networkName, action: #selector(AppDelegate.toggleNetwork(_:)), keyEquivalent: "") let item = NSMenuItem(title: networkName, action: #selector(AppDelegate.toggleNetwork(_:)), keyEquivalent: "")
if net.connected { if net.connected {

View file

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

View file

@ -62,7 +62,7 @@
</button> </button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rz3-0a-oNA"> <button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rz3-0a-oNA">
<rect key="frame" x="238" y="59" width="141" height="18"/> <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"/> <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
</buttonCell> </buttonCell>

View file

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

View file

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

View file

@ -76,6 +76,21 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable
cell.bridgingField.stringValue = network.bridge ? "ENABLED" : "DISABLED" cell.bridgingField.stringValue = network.bridge ? "ENABLED" : "DISABLED"
cell.deviceField.stringValue = network.portDeviceName 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 { if network.allowDefault {
cell.allowDefault.state = NSOnState cell.allowDefault.state = NSOnState
@ -101,20 +116,7 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable
cell.addressesField.stringValue += "\n" 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 return cell
} }