[iOS] [VPN] Hide smart proxy indicator beside server/region when it is disabled (#32598)
This commit is contained in:
@@ -151,7 +151,8 @@ public struct BraveVPNRegionListView: View {
|
||||
isSelectedRegion
|
||||
? Color(braveSystemName: .iconInteractive) : Color(braveSystemName: .textPrimary)
|
||||
)
|
||||
if !region.smartRoutingProxyState.isEmpty,
|
||||
if BraveVPN.isSmartProxyRoutingEnabled,
|
||||
!region.smartRoutingProxyState.isEmpty,
|
||||
region.smartRoutingProxyState != kGRDRegionSmartRoutingProxyNone
|
||||
{
|
||||
Image(braveSystemName: "leo.smart.proxy-routing")
|
||||
|
||||
+34
-12
@@ -183,6 +183,20 @@ public class BraveVPNSettingsViewController: TableViewController {
|
||||
object: nil
|
||||
)
|
||||
|
||||
setUpSections()
|
||||
|
||||
Task { @MainActor in
|
||||
self.credentialSummary = await fetchCredentialSummary()
|
||||
self.updateSubscriptionStatus()
|
||||
self.updateSubscriptionExpiryDate()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
private func setUpSections() {
|
||||
let vpnEnabledToggleView = SwitchAccessoryView(
|
||||
initialValue: BraveVPN.isConnected,
|
||||
valueChange: { vpnOn in
|
||||
@@ -196,8 +210,9 @@ public class BraveVPNSettingsViewController: TableViewController {
|
||||
|
||||
let vpnSmartProxyToggleView = BraveVPNLinkSwitchView(
|
||||
isOn: { BraveVPN.isSmartProxyRoutingEnabled },
|
||||
valueChange: { isSmartProxyEnabled in
|
||||
valueChange: { [unowned self] isSmartProxyEnabled in
|
||||
BraveVPN.isSmartProxyRoutingEnabled = isSmartProxyEnabled
|
||||
self.updateSmartProxyRow()
|
||||
},
|
||||
openURL: openURL
|
||||
)
|
||||
@@ -309,7 +324,7 @@ public class BraveVPNSettingsViewController: TableViewController {
|
||||
&& (BraveVPN.activatedRegion?.smartRoutingProxyState != kGRDRegionSmartRoutingProxyNone)
|
||||
}
|
||||
let rowContext =
|
||||
smartProxyAvailable
|
||||
smartProxyAvailable && BraveVPN.isSmartProxyRoutingEnabled
|
||||
? [BraveVPNServerLocationCell.textAccessoryKey: "leo.smart.proxy-routing"] : nil
|
||||
let serverSection = Section(
|
||||
header: .title(Strings.VPN.settingsServerSection),
|
||||
@@ -374,16 +389,6 @@ public class BraveVPNSettingsViewController: TableViewController {
|
||||
serverSection,
|
||||
techSupportSection,
|
||||
]
|
||||
|
||||
Task { @MainActor in
|
||||
self.credentialSummary = await fetchCredentialSummary()
|
||||
self.updateSubscriptionStatus()
|
||||
self.updateSubscriptionExpiryDate()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
private var hostname: String {
|
||||
@@ -592,6 +597,23 @@ public class BraveVPNSettingsViewController: TableViewController {
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
private func updateSmartProxyRow() {
|
||||
guard
|
||||
let locationIndexPath =
|
||||
dataSource.indexPath(rowUUID: locationCellId, sectionUUID: serverSectionId)
|
||||
else { return }
|
||||
|
||||
let smartProxyAvailable =
|
||||
(BraveVPN.activatedRegion?.smartRoutingProxyState.isEmpty == false)
|
||||
&& (BraveVPN.activatedRegion?.smartRoutingProxyState != kGRDRegionSmartRoutingProxyNone)
|
||||
let newContext =
|
||||
smartProxyAvailable && BraveVPN.isSmartProxyRoutingEnabled
|
||||
? [BraveVPNServerLocationCell.textAccessoryKey: "leo.smart.proxy-routing"]
|
||||
: nil
|
||||
|
||||
dataSource.sections[locationIndexPath.section].rows[locationIndexPath.row].context = newContext
|
||||
}
|
||||
|
||||
@objc func vpnConfigChanged(_ notification: NSNotification) {
|
||||
guard let vpnConnection = notification.object as? NEVPNConnection else {
|
||||
return
|
||||
|
||||
@@ -108,7 +108,7 @@ public struct BrowserMenu: View {
|
||||
handleAction($action)
|
||||
}
|
||||
)
|
||||
if case .connected(let region) = model.vpnStatus {
|
||||
if case .connected(let region, let isSmartProxyEnabled) = model.vpnStatus {
|
||||
Button {
|
||||
handlePresentation(.vpnRegionPicker)
|
||||
} label: {
|
||||
@@ -118,7 +118,7 @@ public struct BrowserMenu: View {
|
||||
Spacer()
|
||||
Text(region.flag)
|
||||
Text(region.displayName)
|
||||
if region.smartProxySupported {
|
||||
if region.smartProxySupported && isSmartProxyEnabled {
|
||||
Image(braveSystemName: "leo.smart.proxy-routing")
|
||||
.resizable()
|
||||
.renderingMode(.template)
|
||||
|
||||
@@ -144,7 +144,8 @@ extension BrowserMenuModel {
|
||||
countryCode: "CA",
|
||||
displayName: "Canada",
|
||||
smartProxySupported: false
|
||||
)
|
||||
),
|
||||
isSmartProxyRoutingEnabled: false
|
||||
)
|
||||
let vpnStatusPublisher = CurrentValueSubject<VPNStatus, Never>(mockStatus)
|
||||
let model = BrowserMenuModel(
|
||||
|
||||
@@ -12,7 +12,7 @@ enum VPNStatus: Equatable {
|
||||
/// VPN is not connected
|
||||
case disconnected
|
||||
/// VPN is connected to a given region
|
||||
case connected(activeRegion: VPNRegion)
|
||||
case connected(activeRegion: VPNRegion, isSmartProxyRoutingEnabled: Bool)
|
||||
}
|
||||
|
||||
/// The VPN region details to show
|
||||
@@ -66,7 +66,10 @@ extension VPNRegion {
|
||||
extension VPNStatus {
|
||||
static var liveVPNStatus: VPNStatus {
|
||||
if BraveVPN.isConnected, let region = BraveVPN.activatedRegion.map(VPNRegion.init) {
|
||||
return .connected(activeRegion: region)
|
||||
return .connected(
|
||||
activeRegion: region,
|
||||
isSmartProxyRoutingEnabled: BraveVPN.isSmartProxyRoutingEnabled
|
||||
)
|
||||
}
|
||||
return .disconnected
|
||||
}
|
||||
|
||||
@@ -319,14 +319,16 @@ class BrowserMenuTests: XCTestCase {
|
||||
countryCode: "CA",
|
||||
displayName: "ca-east",
|
||||
smartProxySupported: false
|
||||
)
|
||||
),
|
||||
isSmartProxyRoutingEnabled: false
|
||||
)
|
||||
)
|
||||
await fulfillment(of: [e], timeout: 1)
|
||||
switch model.vpnStatus {
|
||||
case .connected(let region):
|
||||
case .connected(let region, let isSmartProxyEnabled):
|
||||
XCTAssertEqual(region.flag, "🇨🇦")
|
||||
XCTAssertEqual(region.displayName, "ca-east")
|
||||
XCTAssertFalse(isSmartProxyEnabled)
|
||||
case .disconnected:
|
||||
XCTFail("VPN Region is wrong")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user