Commit c814f139 authored by Jose Blaya's avatar Jose Blaya
Browse files

Improve how the library remove and save profiles switching between the different protocols

parent 4ceb613b
......@@ -104,8 +104,15 @@ class DefaultVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess, Pref
callback?(error)
return
}
previousProfile?.remove(nil)
self.activeProfile = profile
if !((profile.vpnType == IPSecProfile.vpnType || profile.vpnType == IKEv2Profile.vpnType) &&
(previousProfile?.vpnType == IPSecProfile.vpnType || previousProfile?.vpnType == IKEv2Profile.vpnType)) {
//only remove the profile if is not Ipsec or IKEv2, if are one of them, override instead
previousProfile?.remove(nil)
} else {
self.connect(nil)
}
Macros.postNotification(.PIAVPNDidInstall)
callback?(nil)
}
......@@ -114,7 +121,10 @@ class DefaultVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess, Pref
if let previousProfile = previousProfile {
previousProfile.disconnect(installBlock)
} else {
installBlock(nil)
if newVPNType != activeProfile?.vpnType {
//only install if new
installBlock(nil)
}
}
}
......@@ -226,16 +236,19 @@ class DefaultVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess, Pref
@discardableResult private func activeProfileRemovingInactive() -> VPNProfile? {
let activeVPNType = accessedPreferences.vpnType
var activeProfile: VPNProfile?
let activeProfile: VPNProfile? = accessedConfiguration.profile(forVPNType: activeVPNType)
for vpnType in availableVPNTypes {
let profile = accessedConfiguration.profile(forVPNType: vpnType)!
guard (vpnType == activeVPNType) else {
profile.disconnect(nil)
profile.remove(nil)
if !((profile.vpnType == IPSecProfile.vpnType || profile.vpnType == IKEv2Profile.vpnType) &&
(activeProfile?.vpnType == IPSecProfile.vpnType || activeProfile?.vpnType == IKEv2Profile.vpnType)) {
//only remove the profile if is not Ipsec or IKEv2, if are one of them, override instead
profile.disconnect(nil)
profile.remove(nil)
}
continue
}
activeProfile = profile
}
return activeProfile
}
......
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