Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #8317: Menu Update for VPN Status #8325

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Sources/Brave/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import BraveUI
import BraveVPN
import BraveNews
import Growth
import NetworkExtension

extension TabBarVisibility: RepresentableOptionType {
public var displayString: String {
Expand Down Expand Up @@ -95,6 +96,8 @@ class SettingsViewController: TableViewController {
deinit {
keyringStore?.tearDown()
cryptoStore?.tearDown()

NotificationCenter.default.removeObserver(self)
}

@available(*, unavailable)
Expand All @@ -114,6 +117,11 @@ class SettingsViewController: TableViewController {
view.backgroundColor = .braveGroupedBackground
view.tintColor = .braveBlurpleTint
navigationController?.view.backgroundColor = .braveGroupedBackground

NotificationCenter.default.addObserver(
self,
selector: #selector(vpnConfigChanged(notification:)),
name: .NEVPNStatusDidChange, object: nil)
}

private func displayRewardsDebugMenu() {
Expand All @@ -133,6 +141,17 @@ class SettingsViewController: TableViewController {

navigationController?.pushViewController(hostingController, animated: true)
}

/// The function for refreshing VPN status for menu
/// - Parameter notification: NEVPNStatusDidChange
@objc private func vpnConfigChanged(notification: NSNotification) {
guard let connection = notification.object as? NEVPNConnection else { return }

if connection.status == .connected || connection.status == .disconnected {
setUpSections()
tableView.reloadData()
}
}

// Do not use `sections` directly to access sections/rows. Use DataSource.sections instead.
private func makeSections() -> [Static.Section] {
Expand Down