UI: macOS: Tunnel detail: Incorporate on-demand-ness in the status row
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
95e1409bfb
commit
274c4cd092
|
@ -58,6 +58,8 @@
|
||||||
|
|
||||||
"tunnelStatusAddendumOnDemand" = " (On Demand)";
|
"tunnelStatusAddendumOnDemand" = " (On Demand)";
|
||||||
"tunnelStatusOnDemandDisabled" = "On Demand Disabled";
|
"tunnelStatusOnDemandDisabled" = "On Demand Disabled";
|
||||||
|
"tunnelStatusAddendumOnDemandEnabled" = ", On Demand Enabled";
|
||||||
|
"tunnelStatusAddendumOnDemandDisabled" = ", On Demand Disabled";
|
||||||
|
|
||||||
"macToggleStatusButtonActivate" = "Activate";
|
"macToggleStatusButtonActivate" = "Activate";
|
||||||
"macToggleStatusButtonActivating" = "Activating…";
|
"macToggleStatusButtonActivating" = "Activating…";
|
||||||
|
|
|
@ -49,7 +49,9 @@ class EditableKeyValueRow: NSView {
|
||||||
set(value) { valueImageView?.image = value }
|
set(value) { valueImageView?.image = value }
|
||||||
}
|
}
|
||||||
|
|
||||||
var observationToken: AnyObject?
|
var statusObservationToken: AnyObject?
|
||||||
|
var isOnDemandEnabledObservationToken: AnyObject?
|
||||||
|
var hasOnDemandRulesObservationToken: AnyObject?
|
||||||
|
|
||||||
override var intrinsicContentSize: NSSize {
|
override var intrinsicContentSize: NSSize {
|
||||||
let height = max(keyLabel.intrinsicContentSize.height, valueLabel.intrinsicContentSize.height)
|
let height = max(keyLabel.intrinsicContentSize.height, valueLabel.intrinsicContentSize.height)
|
||||||
|
@ -108,7 +110,9 @@ class EditableKeyValueRow: NSView {
|
||||||
key = ""
|
key = ""
|
||||||
value = ""
|
value = ""
|
||||||
isKeyInBold = false
|
isKeyInBold = false
|
||||||
observationToken = nil
|
statusObservationToken = nil
|
||||||
|
isOnDemandEnabledObservationToken = nil
|
||||||
|
hasOnDemandRulesObservationToken = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -422,13 +422,16 @@ extension TunnelDetailTableViewController: NSTableViewDelegate {
|
||||||
func statusCell() -> NSView {
|
func statusCell() -> NSView {
|
||||||
let cell: KeyValueImageRow = tableView.dequeueReusableCell()
|
let cell: KeyValueImageRow = tableView.dequeueReusableCell()
|
||||||
cell.key = tr(format: "macFieldKey (%@)", tr("tunnelInterfaceStatus"))
|
cell.key = tr(format: "macFieldKey (%@)", tr("tunnelInterfaceStatus"))
|
||||||
cell.value = TunnelDetailTableViewController.localizedStatusDescription(forStatus: tunnel.status)
|
cell.value = TunnelDetailTableViewController.localizedStatusDescription(for: tunnel)
|
||||||
cell.valueImage = TunnelDetailTableViewController.image(forStatus: tunnel.status)
|
cell.valueImage = TunnelDetailTableViewController.image(for: tunnel)
|
||||||
cell.observationToken = tunnel.observe(\.status) { [weak cell] tunnel, _ in
|
let changeHandler: (TunnelContainer, Any) -> Void = { [weak cell] tunnel, _ in
|
||||||
guard let cell = cell else { return }
|
guard let cell = cell else { return }
|
||||||
cell.value = TunnelDetailTableViewController.localizedStatusDescription(forStatus: tunnel.status)
|
cell.value = TunnelDetailTableViewController.localizedStatusDescription(for: tunnel)
|
||||||
cell.valueImage = TunnelDetailTableViewController.image(forStatus: tunnel.status)
|
cell.valueImage = TunnelDetailTableViewController.image(for: tunnel)
|
||||||
}
|
}
|
||||||
|
cell.statusObservationToken = tunnel.observe(\.status, changeHandler: changeHandler)
|
||||||
|
cell.isOnDemandEnabledObservationToken = tunnel.observe(\.isActivateOnDemandEnabled, changeHandler: changeHandler)
|
||||||
|
cell.hasOnDemandRulesObservationToken = tunnel.observe(\.hasOnDemandRules, changeHandler: changeHandler)
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,34 +451,49 @@ extension TunnelDetailTableViewController: NSTableViewDelegate {
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func localizedStatusDescription(forStatus status: TunnelStatus) -> String {
|
private static func localizedStatusDescription(for tunnel: TunnelContainer) -> String {
|
||||||
|
let status = tunnel.status
|
||||||
|
let isOnDemandEngaged = tunnel.isActivateOnDemandEnabled
|
||||||
|
|
||||||
|
var text: String
|
||||||
switch status {
|
switch status {
|
||||||
case .inactive:
|
case .inactive:
|
||||||
return tr("tunnelStatusInactive")
|
text = tr("tunnelStatusInactive")
|
||||||
case .activating:
|
case .activating:
|
||||||
return tr("tunnelStatusActivating")
|
text = tr("tunnelStatusActivating")
|
||||||
case .active:
|
case .active:
|
||||||
return tr("tunnelStatusActive")
|
text = tr("tunnelStatusActive")
|
||||||
case .deactivating:
|
case .deactivating:
|
||||||
return tr("tunnelStatusDeactivating")
|
text = tr("tunnelStatusDeactivating")
|
||||||
case .reasserting:
|
case .reasserting:
|
||||||
return tr("tunnelStatusReasserting")
|
text = tr("tunnelStatusReasserting")
|
||||||
case .restarting:
|
case .restarting:
|
||||||
return tr("tunnelStatusRestarting")
|
text = tr("tunnelStatusRestarting")
|
||||||
case .waiting:
|
case .waiting:
|
||||||
return tr("tunnelStatusWaiting")
|
text = tr("tunnelStatusWaiting")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tunnel.hasOnDemandRules {
|
||||||
|
text += isOnDemandEngaged ?
|
||||||
|
tr("tunnelStatusAddendumOnDemandEnabled") : tr("tunnelStatusAddendumOnDemandDisabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func image(forStatus status: TunnelStatus?) -> NSImage? {
|
private static func image(for tunnel: TunnelContainer?) -> NSImage? {
|
||||||
guard let status = status else { return nil }
|
guard let tunnel = tunnel else { return nil }
|
||||||
switch status {
|
switch tunnel.status {
|
||||||
case .active, .restarting, .reasserting:
|
case .active, .restarting, .reasserting:
|
||||||
return NSImage(named: NSImage.statusAvailableName)
|
return NSImage(named: NSImage.statusAvailableName)
|
||||||
case .activating, .waiting, .deactivating:
|
case .activating, .waiting, .deactivating:
|
||||||
return NSImage(named: NSImage.statusPartiallyAvailableName)
|
return NSImage(named: NSImage.statusPartiallyAvailableName)
|
||||||
case .inactive:
|
case .inactive:
|
||||||
return NSImage(named: NSImage.statusNoneName)
|
if tunnel.isActivateOnDemandEnabled {
|
||||||
|
return NSImage(named: NSImage.Name.statusOnDemandEnabled)
|
||||||
|
} else {
|
||||||
|
return NSImage(named: NSImage.statusNoneName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue