Split VPN status and data count
This commit is contained in:
parent
1083941eeb
commit
ad1539023e
|
@ -49,15 +49,7 @@ extension PassepartoutError {
|
|||
}
|
||||
|
||||
extension VPNManager.ObservableState {
|
||||
enum LocalizedStyle {
|
||||
case statusOnly
|
||||
|
||||
case dataCountOrStatus
|
||||
|
||||
case statusAndDataCount
|
||||
}
|
||||
|
||||
func localizedStatusDescription(withErrors: Bool, style: LocalizedStyle) -> String {
|
||||
func localizedStatusDescription(withErrors: Bool, dataCountIfAvailable: Bool) -> String {
|
||||
guard isEnabled else {
|
||||
|
||||
// report application errors even if VPN is disabled
|
||||
|
@ -74,25 +66,10 @@ extension VPNManager.ObservableState {
|
|||
return errorDescription
|
||||
}
|
||||
}
|
||||
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: " ")
|
||||
if dataCountIfAvailable, vpnStatus == .connected, let dataCount = dataCount {
|
||||
return dataCount.localizedDescription
|
||||
}
|
||||
return vpnStatus.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ extension ProfileView {
|
|||
Text(L10n.Profile.Items.ConnectionStatus.caption)
|
||||
.withTrailingText(currentVPNState.localizedStatusDescription(
|
||||
withErrors: true,
|
||||
style: .dataCountOrStatus
|
||||
dataCountIfAvailable: true
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,13 +35,19 @@ struct VPNStatusText: View {
|
|||
|
||||
var body: some View {
|
||||
debugChanges()
|
||||
return Text(statusDescription)
|
||||
return HStack {
|
||||
Text(statusDescription)
|
||||
Spacer()
|
||||
currentVPNState.dataCount.map {
|
||||
Text($0.localizedDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var statusDescription: String {
|
||||
return currentVPNState.localizedStatusDescription(
|
||||
currentVPNState.localizedStatusDescription(
|
||||
withErrors: false,
|
||||
style: .statusAndDataCount
|
||||
dataCountIfAvailable: false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue