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

Commit

Permalink
Fix #7412: VPN Region Selector related changes (#7431)
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel authored May 10, 2023
1 parent bb503f1 commit 6c03710
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/GuardianFirewall/GuardianConnect",
"state" : {
"revision" : "5a00da66f1368e5c325489676fe9281ec98c3a8f",
"version" : "1.8.4-dev-2"
"revision" : "cf99f1babca17a3d94ea20e2fc56cc48dfd65575",
"version" : "1.8.4"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var package = Package(
.package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0"),
.package(url: "https://github.com/devxoul/Then", from: "2.7.0"),
.package(url: "https://github.com/mkrd/Swift-BigInt", from: "2.0.0"),
.package(url: "https://github.com/GuardianFirewall/GuardianConnect", exact: "1.8.4-dev-2"),
.package(url: "https://github.com/GuardianFirewall/GuardianConnect", exact: "1.8.4"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.6.0"),
.package(name: "Static", path: "ThirdParty/Static"),
],
Expand Down
6 changes: 5 additions & 1 deletion Sources/BraveVPN/BraveVPN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ public class BraveVPN {
/// Return the region last activated with the details
/// It will give region details for automatic
public static var activatedRegion: GRDRegion? {
helper.selectedRegion ?? lastKnownRegion
guard let isoCode = helper.selectedRegion?.countryISOCode, isoCode.isEmpty else {
return helper.selectedRegion
}

return lastKnownRegion
}

/// Switched to use an automatic region, region closest to user location.
Expand Down
43 changes: 23 additions & 20 deletions Sources/BraveVPN/BraveVPNPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,39 @@ import GuardianConnect

public class BraveVPNPickerViewController: UIViewController {

private var overlayView: UIView?
let tableView: UITableView = .init(frame: .zero, style: .insetGrouped)

deinit {
NotificationCenter.default.removeObserver(self)
private lazy var overlayView = UIView().then {
$0.backgroundColor = UIColor.black.withAlphaComponent(0.5)

let activityIndicator = UIActivityIndicatorView().then {
$0.style = .large
$0.color = .white
$0.autoresizingMask = [.flexibleWidth, .flexibleHeight]
$0.startAnimating()
}

$0.addSubview(activityIndicator)
}

var isLoading: Bool = false {
didSet {
overlayView?.removeFromSuperview()

navigationItem.hidesBackButton = isLoading

// Prevent dismissing the modal by swipe when the VPN is being configured
navigationController?.isModalInPresentation = isLoading

if !isLoading { return }

let overlay = UIView().then {
$0.backgroundColor = UIColor.black.withAlphaComponent(0.5)
let activityIndicator = UIActivityIndicatorView().then { indicator in
indicator.startAnimating()
indicator.autoresizingMask = [.flexibleWidth, .flexibleHeight]
if isLoading {
view.addSubview(overlayView)
overlayView.snp.makeConstraints {
$0.edges.equalToSuperview()
}
} else {
if overlayView.isDescendant(of: view) {
overlayView.removeFromSuperview()
}

$0.addSubview(activityIndicator)
}

view.addSubview(overlay)
overlay.snp.makeConstraints {
$0.edges.equalToSuperview()
}

overlayView = overlay
}
}

Expand Down Expand Up @@ -73,6 +72,10 @@ public class BraveVPNPickerViewController: UIViewController {
tableView.reloadData()
}

deinit {
NotificationCenter.default.removeObserver(self)
}

@objc func vpnConfigChanged(notification: NSNotification) { }

func showSuccessAlert(text: String) {
Expand Down
8 changes: 5 additions & 3 deletions Sources/BraveVPN/BraveVPNSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ public class BraveVPNSettingsViewController: TableViewController {

let overlay = UIView().then {
$0.backgroundColor = UIColor.black.withAlphaComponent(0.5)
let activityIndicator = UIActivityIndicatorView().then { indicator in
indicator.startAnimating()
indicator.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let activityIndicator = UIActivityIndicatorView().then {
$0.style = .large
$0.color = .white
$0.startAnimating()
$0.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}

$0.addSubview(activityIndicator)
Expand Down
4 changes: 4 additions & 0 deletions Sources/BraveVPN/VPNRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ extension GRDRegion {
}
}

if unicodeScalarView.isEmpty {
return nil
}

return Image(uiImage: unicodeScalarView.image())
}
}

0 comments on commit 6c03710

Please sign in to comment.