Commit ba270630 authored by Jose Blaya's avatar Jose Blaya

Merge branch '307-option-to-not-ask-for-disconnecting-using-nmt' into 'release/3.0.1'

Resolve "Option to not ask for disconnecting using NMT"

See merge request ios/vpn-ios!417
parents a0d5f2ea a52c8a9c
......@@ -17,6 +17,7 @@ private let log = SwiftyBeaver.self
class AppPreferences {
private struct Entries {
static let version = "Version"
static let launched = "Launched" // discard 2.2 key and invert logic
......@@ -44,6 +45,8 @@ class AppPreferences {
static let todayWidgetVpnStatus = "vpn.status"
static let todayWidgetButtonTitle = "vpn.button.description"
static let optOutAskDisconnectVPNUsingNMT = "OptOutAskDisconnectVPNUsingNMT"
}
static let shared = AppPreferences()
......@@ -180,6 +183,15 @@ class AppPreferences {
}
}
var optOutAskDisconnectVPNUsingNMT: Bool{
get {
return defaults.bool(forKey: Entries.optOutAskDisconnectVPNUsingNMT)
}
set {
defaults.set(newValue, forKey: Entries.optOutAskDisconnectVPNUsingNMT)
}
}
@available(iOS 12.0, *)
var connectShortcut: INVoiceShortcut? {
get {
......@@ -229,6 +241,7 @@ class AppPreferences {
Entries.themeCode: ThemeCode.light.rawValue,
Entries.useConnectSiriShortcuts: false,
Entries.useDisconnectSiriShortcuts: false,
Entries.optOutAskDisconnectVPNUsingNMT: false,
Entries.todayWidgetButtonTitle: L10n.Today.Widget.login
])
}
......@@ -318,6 +331,7 @@ class AppPreferences {
func reset() {
piaSocketType = nil
favoriteServerIdentifiers = []
optOutAskDisconnectVPNUsingNMT = false
useConnectSiriShortcuts = false
useDisconnectSiriShortcuts = false
if #available(iOS 12.0, *) {
......@@ -329,6 +343,7 @@ class AppPreferences {
func clean() {
favoriteServerIdentifiers = []
optOutAskDisconnectVPNUsingNMT = false
useConnectSiriShortcuts = false
useDisconnectSiriShortcuts = false
if #available(iOS 12.0, *) {
......
......@@ -284,7 +284,7 @@ class DashboardViewController: AutolayoutViewController {
}
}
if !Client.preferences.nmtRulesEnabled { //if NMT disabled...
if !Client.preferences.nmtRulesEnabled || AppPreferences.shared.optOutAskDisconnectVPNUsingNMT { //if NMT disabled...
showAlert = false
}
......
......@@ -505,6 +505,16 @@ internal enum L10n {
/// The VPN kill switch is currently disabled. In order to ensure that the Network Management Tool is functioning, and that you are able to reconnect when switching networks, please enable the VPN kill switch in your settings.
internal static let disabled = L10n.tr("Localizable", "settings.nmt.killswitch.disabled")
}
internal enum Optout {
internal enum Disconnect {
/// Opt-out disconnect confirmation alert
internal static let alerts = L10n.tr("Localizable", "settings.nmt.optout.disconnect.alerts")
internal enum Alerts {
/// Disables the warning alert when disconnecting from the VPN.
internal static let description = L10n.tr("Localizable", "settings.nmt.optout.disconnect.alerts.description")
}
}
}
}
internal enum Reset {
/// This will reset all of the above settings to default.
......
......@@ -20,6 +20,7 @@ class TrustedNetworksViewController: AutolayoutViewController {
private lazy var switchAutoJoinAllNetworks = UISwitch()
private lazy var switchCellularData = UISwitch()
private lazy var switchRules = UISwitch()
private lazy var switchAskForDisconnect = UISwitch()
var shouldReconnectAutomatically = false
var hasUpdatedPreferences = false
var persistentConnectionValue = false
......@@ -27,6 +28,7 @@ class TrustedNetworksViewController: AutolayoutViewController {
private enum Sections: Int, EnumsBuilder {
case rules = 0
case optOutAlerts
case cellularData
case useVpnWifiProtection
case autoConnectAllNetworksSettings
......@@ -47,6 +49,7 @@ class TrustedNetworksViewController: AutolayoutViewController {
self.switchWiFiProtection.addTarget(self, action: #selector(toggleUseWiFiProtection(_:)), for: .valueChanged)
self.switchCellularData.addTarget(self, action: #selector(toggleCellularData(_:)), for: .valueChanged)
self.switchRules.addTarget(self, action: #selector(toggleRules(_:)), for: .valueChanged)
self.switchAskForDisconnect.addTarget(self, action: #selector(toggleAskForDisconnect(_:)), for: .valueChanged)
NotificationCenter.default.addObserver(self, selector: #selector(filterAvailableNetworks), name: UIApplication.didBecomeActiveNotification, object: nil)
......@@ -131,7 +134,11 @@ class TrustedNetworksViewController: AutolayoutViewController {
tableView.reloadData()
}
@objc private func toggleAskForDisconnect(_ sender: UISwitch) {
AppPreferences.shared.optOutAskDisconnectVPNUsingNMT = sender.isOn
tableView.reloadData()
}
// MARK: Private Methods
private func presentKillSwitchAlert() {
let alert = Macros.alert(nil, L10n.Settings.Nmt.Killswitch.disabled)
......@@ -221,6 +228,8 @@ extension TrustedNetworksViewController: UITableViewDelegate, UITableViewDataSou
L10n.Settings.Hotspothelper.Available.Add.help
case .rules:
return L10n.Settings.Trusted.Networks.Sections.Trusted.Rule.description
case .optOutAlerts:
return L10n.Settings.Nmt.Optout.Disconnect.Alerts.description
default:
return nil
}
......@@ -255,6 +264,12 @@ extension TrustedNetworksViewController: UITableViewDelegate, UITableViewDataSou
cell.accessoryView = switchRules
cell.selectionStyle = .none
switchRules.isOn = Client.preferences.nmtRulesEnabled
case .optOutAlerts:
cell.imageView?.image = nil
cell.textLabel?.text = L10n.Settings.Nmt.Optout.Disconnect.alerts
cell.accessoryView = switchAskForDisconnect
cell.selectionStyle = .none
switchAskForDisconnect.isOn = AppPreferences.shared.optOutAskDisconnectVPNUsingNMT
case .current:
if let ssid = hotspotHelper.currentWiFiNetwork() {
if trustedNetworks.contains(ssid) {
......
......@@ -222,6 +222,8 @@
"settings.trusted.networks.sections.trusted.rule.action"= "Disconnect from PIA VPN";
"tiles.quicksetting.nmt.title" = "Network Management";
"settings.nmt.killswitch.disabled" = "The VPN kill switch is currently disabled. In order to ensure that the Network Management Tool is functioning, and that you are able to reconnect when switching networks, please enable the VPN kill switch in your settings.";
"settings.nmt.optout.disconnect.alerts" = "Opt-out disconnect confirmation alert";
"settings.nmt.optout.disconnect.alerts.description" = "Disables the warning alert when disconnecting from the VPN.";
// REGION
......
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