Check provider requirements before connecting (#896)
E.g. interactive login must be presented afterwards.
This commit is contained in:
parent
d8545a01b4
commit
74ed93a966
|
@ -41,7 +41,7 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
|
||||
"state" : {
|
||||
"revision" : "db02de5247d0231ff06fb3c4d166645a434255be"
|
||||
"revision" : "d11036e59b65601b617120471dc9a469567388f5"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -44,7 +44,7 @@ let package = Package(
|
|||
],
|
||||
dependencies: [
|
||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.11.0"),
|
||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "db02de5247d0231ff06fb3c4d166645a434255be"),
|
||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "d11036e59b65601b617120471dc9a469567388f5"),
|
||||
// .package(path: "../../../passepartoutkit-source"),
|
||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
|
||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),
|
||||
|
|
|
@ -83,6 +83,9 @@ extension PassepartoutError: @retroactive LocalizedError {
|
|||
.compactMap { $0 }
|
||||
.joined(separator: " ")
|
||||
|
||||
case .missingProviderEntity:
|
||||
return Strings.Errors.App.Passepartout.missingProviderEntity
|
||||
|
||||
case .noActiveModules:
|
||||
return Strings.Errors.App.Passepartout.noActiveModules
|
||||
|
||||
|
|
|
@ -110,16 +110,40 @@ private extension TunnelToggleButton {
|
|||
nextProfileId = nil
|
||||
}
|
||||
}
|
||||
if canConnect && profile.isInteractive {
|
||||
do {
|
||||
try iapManager.verify(profile)
|
||||
pp_log(.app, .notice, "Present interactive login")
|
||||
interactiveManager.present(with: profile) {
|
||||
await perform(with: $0)
|
||||
if canConnect {
|
||||
|
||||
// provider module -> check requirements
|
||||
if let providerModule = profile.firstProviderModule,
|
||||
providerModule.isProviderRequired {
|
||||
|
||||
// missing required provider -> show error
|
||||
guard let provider = providerModule.provider else {
|
||||
errorHandler.handle(
|
||||
PassepartoutError(.providerRequired),
|
||||
title: Strings.Global.connection
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// missing provider entity -> show selector
|
||||
guard provider.entity != nil else {
|
||||
onProviderEntityRequired(profile)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// interactive login -> show interactive view
|
||||
if profile.isInteractive {
|
||||
do {
|
||||
try iapManager.verify(profile)
|
||||
pp_log(.app, .notice, "Present interactive login")
|
||||
interactiveManager.present(with: profile) {
|
||||
await perform(with: $0)
|
||||
}
|
||||
return
|
||||
} catch {
|
||||
pp_log(.app, .error, "Verification failed for profile \(profile.id), suppress interactive login: \(error)")
|
||||
}
|
||||
return
|
||||
} catch {
|
||||
pp_log(.app, .notice, "Ineligible, suppress interactive login")
|
||||
}
|
||||
}
|
||||
await perform(with: profile)
|
||||
|
@ -142,21 +166,6 @@ private extension TunnelToggleButton {
|
|||
} catch is CancellationError {
|
||||
//
|
||||
} catch {
|
||||
switch (error as? PassepartoutError)?.code {
|
||||
case .missingProviderEntity:
|
||||
onProviderEntityRequired(profile)
|
||||
return
|
||||
|
||||
case .providerRequired:
|
||||
errorHandler.handle(
|
||||
error,
|
||||
title: Strings.Global.connection
|
||||
)
|
||||
return
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
errorHandler.handle(
|
||||
error,
|
||||
title: Strings.Global.connection,
|
||||
|
|
Loading…
Reference in New Issue