From 84a565736e733e21ebe843b4cc4e30fdc7851136 Mon Sep 17 00:00:00 2001 From: Soner YUKSEL Date: Fri, 27 Oct 2023 10:52:44 -0400 Subject: [PATCH] Fix brave/brave-ios#8317: Menu Update for VPN Status (brave/brave-ios#8325) --- .../Settings/SettingsViewController.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sources/Brave/Frontend/Settings/SettingsViewController.swift b/Sources/Brave/Frontend/Settings/SettingsViewController.swift index 7a50d2762a7b..2e2e84b3bfd6 100644 --- a/Sources/Brave/Frontend/Settings/SettingsViewController.swift +++ b/Sources/Brave/Frontend/Settings/SettingsViewController.swift @@ -18,6 +18,7 @@ import BraveUI import BraveVPN import BraveNews import Growth +import NetworkExtension extension TabBarVisibility: RepresentableOptionType { public var displayString: String { @@ -95,6 +96,8 @@ class SettingsViewController: TableViewController { deinit { keyringStore?.tearDown() cryptoStore?.tearDown() + + NotificationCenter.default.removeObserver(self) } @available(*, unavailable) @@ -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() { @@ -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] {