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

Commit

Permalink
Fix #8317: Menu Update for VPN Status (#8325)
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel authored Oct 27, 2023
1 parent fe968b1 commit 22dc4d0
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit 22dc4d0

Please sign in to comment.