macOS: Networks should show allowedIPs and disappear when inactive

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2019-01-15 22:35:30 +01:00
parent f63c9fd598
commit 811714e21a
1 changed files with 7 additions and 5 deletions

View File

@ -63,6 +63,7 @@ class StatusMenu: NSMenu {
addItem(statusMenuItem)
let networksMenuItem = NSMenuItem(title: tr("macMenuNetworksInactive"), action: #selector(manageTunnelsClicked), keyEquivalent: "")
networksMenuItem.isEnabled = false
networksMenuItem.isHidden = true
addItem(networksMenuItem)
self.statusMenuItem = statusMenuItem
self.networksMenuItem = networksMenuItem
@ -98,14 +99,15 @@ class StatusMenu: NSMenu {
if tunnel.status == .inactive {
networksMenuItem.title = tr("macMenuNetworksInactive")
networksMenuItem.isHidden = true
} else {
let allowedIPs = tunnel.tunnelConfiguration?.peers.flatMap { $0.allowedIPs }.map { $0.stringRepresentation }.joined(separator: ", ") ?? ""
if !allowedIPs.isEmpty {
networksMenuItem.title = tr(format: "macMenuNetworks (%@)", allowedIPs)
} else {
let addresses = tunnel.tunnelConfiguration?.interface.addresses ?? []
let addressesString = addresses.map { $0.stringRepresentation }.joined(separator: ", ")
if addressesString.isEmpty {
networksMenuItem.title = tr("macMenuNetworksNone")
} else {
networksMenuItem.title = tr(format: "macMenuNetworks (%@)", addressesString)
}
networksMenuItem.isHidden = false
}
return true
}