Commit 8ddfc12f authored by Davide De Rosa's avatar Davide De Rosa
Browse files

Add preference for VPN disconnectsOnSleep

Default to formerly hardcoded false to maintain compatibility.
parent 0cd28c07
......@@ -38,6 +38,8 @@ protocol PlainStore: class {
var vpnType: String? { get set }
var vpnDisconnectsOnSleep: Bool { get set }
var vpnCustomConfigurationMaps: [String: [String: Any]]? { get set }
// MARK: Preferences
......
......@@ -22,6 +22,8 @@ private protocol PreferencesStore: class {
var vpnType: String { get set }
var vpnDisconnectsOnSleep: Bool { get set }
var vpnCustomConfigurations: [String: VPNCustomConfiguration] { get set }
func vpnCustomConfiguration(for vpnType: String) -> VPNCustomConfiguration?
......@@ -40,6 +42,7 @@ private extension PreferencesStore {
isPersistentConnection = source.isPersistentConnection
mace = source.mace
vpnType = source.vpnType
vpnDisconnectsOnSleep = source.vpnDisconnectsOnSleep
vpnCustomConfigurations = source.vpnCustomConfigurations
}
}
......@@ -119,6 +122,16 @@ extension Client {
}
}
/// When device sleeps, disconnects from the VPN if `true`.
public fileprivate(set) var vpnDisconnectsOnSleep: Bool {
get {
return accessedDatabase.plain.vpnDisconnectsOnSleep
}
set {
accessedDatabase.plain.vpnDisconnectsOnSleep = newValue
}
}
/// A dictionary of custom VPN configurations, mapped by `VPNProfile.vpnType`.
public fileprivate(set) var vpnCustomConfigurations: [String: VPNCustomConfiguration] {
get {
......@@ -186,6 +199,7 @@ extension Client.Preferences {
isPersistentConnection = true
mace = false
vpnType = IPSecProfile.vpnType
vpnDisconnectsOnSleep = false
vpnCustomConfigurations = [:]
}
......@@ -227,6 +241,9 @@ extension Client.Preferences {
/// :nodoc:
public var vpnType: String
/// :nodoc:
public var vpnDisconnectsOnSleep: Bool
/// :nodoc:
public var vpnCustomConfigurations: [String: VPNCustomConfiguration]
......@@ -255,6 +272,9 @@ extension Client.Preferences {
if (isPersistentConnection != target.isPersistentConnection) {
queue.append(VPNActionReinstall())
}
if (vpnDisconnectsOnSleep != target.vpnDisconnectsOnSleep) {
queue.append(VPNActionReinstall())
}
if (mace != target.mace) {
queue.append(VPNActionReconnect())
}
......
......@@ -32,6 +32,8 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
static let vpnType = "VPNType"
static let vpnDisconnectsOnSleep = "VPNDisconnectsOnSleep"
static let vpnCustomConfigurationMaps = "VPNCustomConfigurationMaps"
static let persistentConnection = "PersistentConnection" // legacy
......@@ -186,6 +188,15 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
}
}
var vpnDisconnectsOnSleep: Bool {
get {
return backend.bool(forKey: Entries.vpnDisconnectsOnSleep)
}
set {
backend.set(newValue, forKey: Entries.vpnDisconnectsOnSleep)
}
}
var vpnCustomConfigurationMaps: [String: [String : Any]]? {
get {
return backend.dictionary(forKey: Entries.vpnCustomConfigurationMaps) as? [String: [String: Any]]
......
......@@ -17,6 +17,7 @@ class VPNTests: XCTestCase {
Client.database = Client.Database(group: "group.com.privateinternetaccess")
Client.providers.vpnProvider = MockVPNProvider()
Client.preferences.vpnDisconnectsOnSleep = true
Client.bootstrap()
}
......
Supports Markdown
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