macOS: Tunnel detail: Show the status in the list view
This commit is contained in:
parent
62b03272ee
commit
9b05678bdd
|
@ -57,6 +57,7 @@
|
||||||
"tunnelInterfaceListenPort" = "Listen port";
|
"tunnelInterfaceListenPort" = "Listen port";
|
||||||
"tunnelInterfaceMTU" = "MTU";
|
"tunnelInterfaceMTU" = "MTU";
|
||||||
"tunnelInterfaceDNS" = "DNS servers";
|
"tunnelInterfaceDNS" = "DNS servers";
|
||||||
|
"tunnelInterfaceStatus" = "Status";
|
||||||
|
|
||||||
"tunnelSectionTitlePeer" = "Peer";
|
"tunnelSectionTitlePeer" = "Peer";
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ class TunnelViewModel {
|
||||||
case listenPort
|
case listenPort
|
||||||
case mtu
|
case mtu
|
||||||
case dns
|
case dns
|
||||||
|
case status
|
||||||
|
|
||||||
var localizedUIString: String {
|
var localizedUIString: String {
|
||||||
switch self {
|
switch self {
|
||||||
|
@ -25,6 +26,7 @@ class TunnelViewModel {
|
||||||
case .listenPort: return tr("tunnelInterfaceListenPort")
|
case .listenPort: return tr("tunnelInterfaceListenPort")
|
||||||
case .mtu: return tr("tunnelInterfaceMTU")
|
case .mtu: return tr("tunnelInterfaceMTU")
|
||||||
case .dns: return tr("tunnelInterfaceDNS")
|
case .dns: return tr("tunnelInterfaceDNS")
|
||||||
|
case .status: return tr("tunnelInterfaceStatus")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class TunnelDetailTableViewController: NSViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
static let interfaceFields: [TunnelViewModel.InterfaceField] = [
|
static let interfaceFields: [TunnelViewModel.InterfaceField] = [
|
||||||
.name, .publicKey, .addresses,
|
.name, .status, .publicKey, .addresses,
|
||||||
.listenPort, .mtu, .dns
|
.listenPort, .mtu, .dns
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -175,7 +175,9 @@ class TunnelDetailTableViewController: NSViewController {
|
||||||
|
|
||||||
var interfaceSection = [(isVisible: Bool, modelRow: TableViewModelRow)]()
|
var interfaceSection = [(isVisible: Bool, modelRow: TableViewModelRow)]()
|
||||||
for field in TunnelDetailTableViewController.interfaceFields {
|
for field in TunnelDetailTableViewController.interfaceFields {
|
||||||
interfaceSection.append((isVisible: !tunnelViewModel.interfaceData[field].isEmpty, modelRow: .interfaceFieldRow(field)))
|
let isStatus = field == .status
|
||||||
|
let isEmpty = tunnelViewModel.interfaceData[field].isEmpty
|
||||||
|
interfaceSection.append((isVisible: isStatus || !isEmpty, modelRow: .interfaceFieldRow(field)))
|
||||||
}
|
}
|
||||||
interfaceSection.append((isVisible: true, modelRow: .spacerRow))
|
interfaceSection.append((isVisible: true, modelRow: .spacerRow))
|
||||||
modelRowsBySection.append(interfaceSection)
|
modelRowsBySection.append(interfaceSection)
|
||||||
|
@ -398,12 +400,16 @@ extension TunnelDetailTableViewController: NSTableViewDelegate {
|
||||||
let modelRow = tableViewModelRows[row]
|
let modelRow = tableViewModelRows[row]
|
||||||
switch modelRow {
|
switch modelRow {
|
||||||
case .interfaceFieldRow(let field):
|
case .interfaceFieldRow(let field):
|
||||||
|
if field == .status {
|
||||||
|
return statusCell()
|
||||||
|
} else {
|
||||||
let cell: KeyValueRow = tableView.dequeueReusableCell()
|
let cell: KeyValueRow = tableView.dequeueReusableCell()
|
||||||
let localizedKeyString = modelRow.isTitleRow() ? modelRow.localizedSectionKeyString() : field.localizedUIString
|
let localizedKeyString = modelRow.isTitleRow() ? modelRow.localizedSectionKeyString() : field.localizedUIString
|
||||||
cell.key = tr(format: "macFieldKey (%@)", localizedKeyString)
|
cell.key = tr(format: "macFieldKey (%@)", localizedKeyString)
|
||||||
cell.value = tunnelViewModel.interfaceData[field]
|
cell.value = tunnelViewModel.interfaceData[field]
|
||||||
cell.isKeyInBold = modelRow.isTitleRow()
|
cell.isKeyInBold = modelRow.isTitleRow()
|
||||||
return cell
|
return cell
|
||||||
|
}
|
||||||
case .peerFieldRow(let peerData, let field):
|
case .peerFieldRow(let peerData, let field):
|
||||||
let cell: KeyValueRow = tableView.dequeueReusableCell()
|
let cell: KeyValueRow = tableView.dequeueReusableCell()
|
||||||
let localizedKeyString = modelRow.isTitleRow() ? modelRow.localizedSectionKeyString() : field.localizedUIString
|
let localizedKeyString = modelRow.isTitleRow() ? modelRow.localizedSectionKeyString() : field.localizedUIString
|
||||||
|
@ -427,6 +433,50 @@ extension TunnelDetailTableViewController: NSTableViewDelegate {
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func statusCell() -> NSView {
|
||||||
|
let cell: KeyValueImageRow = tableView.dequeueReusableCell()
|
||||||
|
cell.key = tr(format: "macFieldKey (%@)", tr("tunnelInterfaceStatus"))
|
||||||
|
cell.value = TunnelDetailTableViewController.localizedStatusDescription(forStatus: tunnel.status)
|
||||||
|
cell.valueImage = TunnelDetailTableViewController.image(forStatus: tunnel.status)
|
||||||
|
cell.observationToken = tunnel.observe(\.status) { [weak cell] tunnel, _ in
|
||||||
|
guard let cell = cell else { return }
|
||||||
|
cell.value = TunnelDetailTableViewController.localizedStatusDescription(forStatus: tunnel.status)
|
||||||
|
cell.valueImage = TunnelDetailTableViewController.image(forStatus: tunnel.status)
|
||||||
|
}
|
||||||
|
return cell
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func localizedStatusDescription(forStatus status: TunnelStatus) -> String {
|
||||||
|
switch status {
|
||||||
|
case .inactive:
|
||||||
|
return tr("tunnelStatusInactive")
|
||||||
|
case .activating:
|
||||||
|
return tr("tunnelStatusActivating")
|
||||||
|
case .active:
|
||||||
|
return tr("tunnelStatusActive")
|
||||||
|
case .deactivating:
|
||||||
|
return tr("tunnelStatusDeactivating")
|
||||||
|
case .reasserting:
|
||||||
|
return tr("tunnelStatusReasserting")
|
||||||
|
case .restarting:
|
||||||
|
return tr("tunnelStatusRestarting")
|
||||||
|
case .waiting:
|
||||||
|
return tr("tunnelStatusWaiting")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func image(forStatus status: TunnelStatus?) -> NSImage? {
|
||||||
|
guard let status = status else { return nil }
|
||||||
|
switch status {
|
||||||
|
case .active, .restarting, .reasserting:
|
||||||
|
return NSImage(named: NSImage.statusAvailableName)
|
||||||
|
case .activating, .waiting, .deactivating:
|
||||||
|
return NSImage(named: NSImage.statusPartiallyAvailableName)
|
||||||
|
case .inactive:
|
||||||
|
return NSImage(named: NSImage.statusNoneName)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TunnelDetailTableViewController: TunnelEditViewControllerDelegate {
|
extension TunnelDetailTableViewController: TunnelEditViewControllerDelegate {
|
||||||
|
|
Loading…
Reference in New Issue