Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
liberty
tunnel
liberty-tunnel-client-library-apple
Commits
504bc9d3
Unverified
Commit
504bc9d3
authored
Jun 11, 2018
by
Davide De Rosa
Committed by
GitHub
Jun 11, 2018
Browse files
Merge pull request #2 from pia-foss/add-preference-to-disconnect-on-sleep
Add preference to disconnect VPN on sleep
parents
0cd28c07
e97c0c53
Changes
5
Hide whitespace changes
Inline
Side-by-side
PIALibrary/Sources/Core/Persistence/PlainStore.swift
View file @
504bc9d3
...
...
@@ -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
...
...
PIALibrary/Sources/Library/Client+Preferences.swift
View file @
504bc9d3
...
...
@@ -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
())
}
...
...
PIALibrary/Sources/Library/Persistence/UserDefaultsStore.swift
View file @
504bc9d3
...
...
@@ -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
]]
...
...
PIALibrary/Sources/Library/VPN/DefaultVPNProvider.swift
View file @
504bc9d3
...
...
@@ -262,7 +262,7 @@ class DefaultVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess, Pref
server
:
accessedProviders
.
serverProvider
.
targetServer
,
port
:
port
,
isOnDemand
:
accessedPreferences
.
isPersistentConnection
,
disconnectsOnSleep
:
false
,
disconnectsOnSleep
:
accessedPreferences
.
vpnDisconnectsOnSleep
,
customConfiguration
:
customConfiguration
)
}
...
...
PIALibraryTests/VPNTests.swift
View file @
504bc9d3
...
...
@@ -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
()
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment