Extend styles for VPN status description
This commit is contained in:
parent
867b415b6b
commit
7095791428
|
@ -49,7 +49,15 @@ extension PassepartoutError {
|
|||
}
|
||||
|
||||
extension VPNManager.ObservableState {
|
||||
func localizedStatusDescription(withErrors: Bool, withDataCount: Bool) -> String {
|
||||
enum LocalizedStyle {
|
||||
case statusOnly
|
||||
|
||||
case dataCountOrStatus
|
||||
|
||||
case statusAndDataCount
|
||||
}
|
||||
|
||||
func localizedStatusDescription(withErrors: Bool, style: LocalizedStyle) -> String {
|
||||
guard isEnabled else {
|
||||
|
||||
// report application errors even if VPN is disabled
|
||||
|
@ -66,12 +74,25 @@ extension VPNManager.ObservableState {
|
|||
return errorDescription
|
||||
}
|
||||
}
|
||||
if withDataCount {
|
||||
if vpnStatus == .connected, let dataCount = dataCount {
|
||||
return dataCount.localizedDescription
|
||||
}
|
||||
let statusDescription = vpnStatus.localizedDescription
|
||||
var dataCountDescription: String?
|
||||
if vpnStatus == .connected, let dataCount = dataCount {
|
||||
dataCountDescription = dataCount.localizedDescription
|
||||
}
|
||||
switch style {
|
||||
case .statusOnly:
|
||||
return statusDescription
|
||||
|
||||
case .dataCountOrStatus:
|
||||
return dataCountDescription ?? statusDescription
|
||||
|
||||
case .statusAndDataCount:
|
||||
var comps: [String] = [statusDescription]
|
||||
if let dataCountDescription = dataCountDescription {
|
||||
comps.append(dataCountDescription)
|
||||
}
|
||||
return comps.joined(separator: " ")
|
||||
}
|
||||
return vpnStatus.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ extension ProfileView {
|
|||
Text(L10n.Profile.Items.ConnectionStatus.caption)
|
||||
.withTrailingText(currentVPNState.localizedStatusDescription(
|
||||
withErrors: true,
|
||||
withDataCount: true
|
||||
style: .dataCountOrStatus
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ struct VPNStatusText: View {
|
|||
private var statusDescription: String {
|
||||
return currentVPNState.localizedStatusDescription(
|
||||
withErrors: false,
|
||||
withDataCount: true
|
||||
style: .statusAndDataCount
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue