macOS: Networks should show allowedIPs and disappear when inactive
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
f63c9fd598
commit
811714e21a
|
@ -63,6 +63,7 @@ class StatusMenu: NSMenu {
|
||||||
addItem(statusMenuItem)
|
addItem(statusMenuItem)
|
||||||
let networksMenuItem = NSMenuItem(title: tr("macMenuNetworksInactive"), action: #selector(manageTunnelsClicked), keyEquivalent: "")
|
let networksMenuItem = NSMenuItem(title: tr("macMenuNetworksInactive"), action: #selector(manageTunnelsClicked), keyEquivalent: "")
|
||||||
networksMenuItem.isEnabled = false
|
networksMenuItem.isEnabled = false
|
||||||
|
networksMenuItem.isHidden = true
|
||||||
addItem(networksMenuItem)
|
addItem(networksMenuItem)
|
||||||
self.statusMenuItem = statusMenuItem
|
self.statusMenuItem = statusMenuItem
|
||||||
self.networksMenuItem = networksMenuItem
|
self.networksMenuItem = networksMenuItem
|
||||||
|
@ -98,14 +99,15 @@ class StatusMenu: NSMenu {
|
||||||
|
|
||||||
if tunnel.status == .inactive {
|
if tunnel.status == .inactive {
|
||||||
networksMenuItem.title = tr("macMenuNetworksInactive")
|
networksMenuItem.title = tr("macMenuNetworksInactive")
|
||||||
|
networksMenuItem.isHidden = true
|
||||||
} else {
|
} else {
|
||||||
let addresses = tunnel.tunnelConfiguration?.interface.addresses ?? []
|
let allowedIPs = tunnel.tunnelConfiguration?.peers.flatMap { $0.allowedIPs }.map { $0.stringRepresentation }.joined(separator: ", ") ?? ""
|
||||||
let addressesString = addresses.map { $0.stringRepresentation }.joined(separator: ", ")
|
if !allowedIPs.isEmpty {
|
||||||
if addressesString.isEmpty {
|
networksMenuItem.title = tr(format: "macMenuNetworks (%@)", allowedIPs)
|
||||||
networksMenuItem.title = tr("macMenuNetworksNone")
|
|
||||||
} else {
|
} else {
|
||||||
networksMenuItem.title = tr(format: "macMenuNetworks (%@)", addressesString)
|
networksMenuItem.title = tr("macMenuNetworksNone")
|
||||||
}
|
}
|
||||||
|
networksMenuItem.isHidden = false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue