diff --git a/ios/brave-ios/Sources/BraveVPN/Components/Region/BraveVPNRegionListView.swift b/ios/brave-ios/Sources/BraveVPN/Components/Region/BraveVPNRegionListView.swift index 1761044aa14..6e0ca309d4d 100644 --- a/ios/brave-ios/Sources/BraveVPN/Components/Region/BraveVPNRegionListView.swift +++ b/ios/brave-ios/Sources/BraveVPN/Components/Region/BraveVPNRegionListView.swift @@ -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") diff --git a/ios/brave-ios/Sources/BraveVPN/Components/Settings/BraveVPNSettingsViewController.swift b/ios/brave-ios/Sources/BraveVPN/Components/Settings/BraveVPNSettingsViewController.swift index 14b8ae67ddd..f52cbe00742 100644 --- a/ios/brave-ios/Sources/BraveVPN/Components/Settings/BraveVPNSettingsViewController.swift +++ b/ios/brave-ios/Sources/BraveVPN/Components/Settings/BraveVPNSettingsViewController.swift @@ -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 diff --git a/ios/brave-ios/Sources/BrowserMenu/BrowserMenu.swift b/ios/brave-ios/Sources/BrowserMenu/BrowserMenu.swift index 0d453867120..fc1241d154a 100644 --- a/ios/brave-ios/Sources/BrowserMenu/BrowserMenu.swift +++ b/ios/brave-ios/Sources/BrowserMenu/BrowserMenu.swift @@ -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) diff --git a/ios/brave-ios/Sources/BrowserMenu/BrowserMenuModel.swift b/ios/brave-ios/Sources/BrowserMenu/BrowserMenuModel.swift index a1829140b56..2c07ea2756a 100644 --- a/ios/brave-ios/Sources/BrowserMenu/BrowserMenuModel.swift +++ b/ios/brave-ios/Sources/BrowserMenu/BrowserMenuModel.swift @@ -144,7 +144,8 @@ extension BrowserMenuModel { countryCode: "CA", displayName: "Canada", smartProxySupported: false - ) + ), + isSmartProxyRoutingEnabled: false ) let vpnStatusPublisher = CurrentValueSubject(mockStatus) let model = BrowserMenuModel( diff --git a/ios/brave-ios/Sources/BrowserMenu/VPNStatus.swift b/ios/brave-ios/Sources/BrowserMenu/VPNStatus.swift index 644fb938f6f..7ab669a6528 100644 --- a/ios/brave-ios/Sources/BrowserMenu/VPNStatus.swift +++ b/ios/brave-ios/Sources/BrowserMenu/VPNStatus.swift @@ -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 } diff --git a/ios/brave-ios/Tests/BrowserMenuTests/BrowserMenuTests.swift b/ios/brave-ios/Tests/BrowserMenuTests/BrowserMenuTests.swift index 1b88c52e21d..3d7b5747d60 100644 --- a/ios/brave-ios/Tests/BrowserMenuTests/BrowserMenuTests.swift +++ b/ios/brave-ios/Tests/BrowserMenuTests/BrowserMenuTests.swift @@ -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") }