Commit 6edc5911 authored by Jose Blaya's avatar Jose Blaya
Browse files

Ask the user to connect the VPN when VPN WiFi Protection is enabled

parent 01acace1
......@@ -499,6 +499,10 @@ internal enum L10n {
internal enum Networks {
/// PIA won't automatically connect on these networks.
internal static let message = L10n.tr("Localizable", "settings.trusted.networks.message")
internal enum Connect {
/// Protect this network by connecting to VPN?
internal static let message = L10n.tr("Localizable", "settings.trusted.networks.connect.message")
}
internal enum Sections {
/// Available networks
internal static let available = L10n.tr("Localizable", "settings.trusted.networks.sections.available")
......
......@@ -74,6 +74,12 @@ class TrustedNetworksViewController: AutolayoutViewController {
preferences.useWiFiProtection = sender.isOn
preferences.commit()
filterAvailableNetworks()
if sender.isOn, //If toggle is ON
let ssid = UIDevice.current.WiFiSSID, //And we are connected to the WiFi
Client.providers.vpnProvider.vpnStatus == .disconnected, //And we are disconnected
!Client.preferences.trustedNetworks.contains(ssid) { // And the network is not one of the trustedNetworks
requestPermissionToConnectVPN() // Show alert to connect the VPN
}
}
// MARK: Private Methods
......@@ -92,6 +98,18 @@ class TrustedNetworksViewController: AutolayoutViewController {
self.tableView.reloadData()
}
private func requestPermissionToConnectVPN() {
let alert = Macros.alert(L10n.Settings.Hotspothelper.title,
L10n.Settings.Trusted.Networks.Connect.message)
alert.addCancelAction(L10n.Global.close)
alert.addDefaultAction(L10n.Global.ok, handler: {
Macros.dispatch(after: .milliseconds(200)) {
Client.providers.vpnProvider.connect(nil)
}
})
present(alert, animated: true, completion: nil)
}
}
extension TrustedNetworksViewController: UITableViewDelegate, UITableViewDataSource {
......
......@@ -212,6 +212,7 @@
"settings.trusted.networks.sections.available" = "Available networks";
"settings.trusted.networks.sections.trusted" = "Trusted networks";
"settings.trusted.networks.message" = "PIA won't automatically connect on these networks.";
"settings.trusted.networks.connect.message" = "Protect this network by connecting to VPN?";
"hotspothelper.display.name" = "🔒 Activate VPN WiFi Protection in PIA Settings to secure this connection.";
"hotspothelper.display.protected.name" = "🔒 PIA VPN WiFi Protection Enabled - We got your back.";
"settings.hotspothelper.cellular.title" = "Trust cellular networks";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment