Commit 3174f4ec authored by Jose Blaya's avatar Jose Blaya
Browse files

New parameter to force the installation of the VPN profile

parent b8ff4e29
......@@ -36,8 +36,9 @@ public protocol VPNProvider: class {
Installs the profile as per `currentVPNType`.
- Parameter callback: Returns `nil` on success.
- Parameter forceInstall: Force the install of the profile.
*/
func install(_ callback: SuccessLibraryCallback?)
func install(force forceInstall: Bool, _ callback: SuccessLibraryCallback?)
/**
Disables the current profile.
......
......@@ -79,11 +79,11 @@ class DefaultVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess, Pref
#endif
activeProfile = profile
if accessedProviders.accountProvider.isLoggedIn {
install(nil)
install(force: false, nil)
}
}
func install(_ callback: SuccessLibraryCallback?) {
func install(force forceInstall: Bool, _ callback: SuccessLibraryCallback?) {
guard accessedProviders.accountProvider.isLoggedIn else {
preconditionFailure()
}
......@@ -97,9 +97,9 @@ class DefaultVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess, Pref
previousProfile = activeProfile
}
let force = DefaultVPNProvider.forcedStatuses.contains(accessedDatabase.transient.vpnStatus)
let forcedStatuses = DefaultVPNProvider.forcedStatuses.contains(accessedDatabase.transient.vpnStatus)
let installBlock: SuccessLibraryCallback = { (error) in
profile.save(withConfiguration: self.vpnClientConfiguration(for: profile), force: force) { (error) in
profile.save(withConfiguration: self.vpnClientConfiguration(for: profile), force: forcedStatuses) { (error) in
if let error = error {
callback?(error)
return
......@@ -121,7 +121,7 @@ class DefaultVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess, Pref
if let previousProfile = previousProfile {
previousProfile.disconnect(installBlock)
} else {
if newVPNType != activeProfile?.vpnType || !force {
if newVPNType != activeProfile?.vpnType || !forcedStatuses || forceInstall {
//only install if new
installBlock(nil)
}
......
......@@ -48,13 +48,13 @@ class VPNActionReinstall: VPNAction, ProvidersAccess {
func execute(_ callback: SuccessLibraryCallback?) {
let vpn = accessedProviders.vpnProvider
vpn.install { (error) in
vpn.install(force: true, { (error) in
if let _ = error {
callback?(error)
return
}
callback?(nil)
}
})
}
}
......@@ -65,7 +65,7 @@ class VPNActionDisconnectAndReinstall: VPNAction, ProvidersAccess {
func execute(_ callback: SuccessLibraryCallback?) {
let vpn = accessedProviders.vpnProvider
vpn.install { (error) in
vpn.install(force: true, { (error) in
if let _ = error {
callback?(error)
return
......@@ -75,6 +75,6 @@ class VPNActionDisconnectAndReinstall: VPNAction, ProvidersAccess {
return
}
vpn.reconnect(after: nil, callback)
}
})
}
}
......@@ -57,7 +57,7 @@ public class MockVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess {
}
/// :nodoc:
public func install(_ callback: SuccessLibraryCallback?) {
public func install(force forceInstall: Bool, _ callback: SuccessLibraryCallback?) {
Macros.postNotification(.PIAVPNDidInstall)
callback?(nil)
}
......
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