Connect on provider server selection (#941)

Unless profile is current and active, in which case AppContext does it
under the hood.
This commit is contained in:
Davide 2024-11-26 10:30:30 +01:00 committed by GitHub
parent 1c1d2502c3
commit 8ec6f90077
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 11 additions and 6 deletions

View File

@ -41,7 +41,7 @@
"kind" : "remoteSourceControl",
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
"state" : {
"revision" : "0d7f912460ca5365740d7196fe5db5a38e23d3e1"
"revision" : "7b43f2a7f4d1955b0e7a2a029cce629264ee2a69"
}
},
{

View File

@ -48,7 +48,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: "0d7f912460ca5365740d7196fe5db5a38e23d3e1"),
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "7b43f2a7f4d1955b0e7a2a029cce629264ee2a69"),
// .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"),

View File

@ -60,7 +60,6 @@ struct ProviderEntitySelector: View {
private extension ProviderEntitySelector {
func onSelect(_ entity: any ProviderEntity & Encodable) async throws {
pp_log(.app, .info, "Select new provider entity: \(entity)")
do {
guard var moduleBuilder = module.providerModuleBuilder() else {
assertionFailure("Module is not a ProviderModuleBuilder?")
@ -73,9 +72,14 @@ private extension ProviderEntitySelector {
builder.saveModule(newModule)
let newProfile = try builder.tryBuild()
let wasConnected = newProfile.id == tunnel.currentProfile?.id && tunnel.status == .active
try await profileManager.save(newProfile, isLocal: true)
// will reconnect via AppContext observation
if !wasConnected {
pp_log(.app, .info, "Profile \(newProfile.id) was not connected, will connect to new provider entity")
try await tunnel.connect(with: newProfile)
} else {
pp_log(.app, .info, "Profile \(newProfile.id) was connected, will reconnect to new provider entity via AppContext observation")
}
} catch {
pp_log(.app, .error, "Unable to save new provider entity: \(error)")
throw error

View File

@ -50,6 +50,7 @@ struct VPNProviderServerCoordinator<Configuration>: View where Configuration: Pr
configurationType: Configuration.self,
selectedEntity: selectedEntity,
filtersWithSelection: false,
selectTitle: Strings.Global.Actions.connect,
onSelect: onSelect
)
.themeNavigationStack(closable: true)

View File

@ -71,7 +71,7 @@ public final class NEProfileRepository: ProfileRepository {
}
public func saveProfile(_ profile: Profile) async throws {
try await repository.save(profile, forConnecting: false, title: title)
try await repository.save(profile, forConnecting: false, options: nil, title: title)
if let index = profilesSubject.value.firstIndex(where: { $0.id == profile.id }) {
profilesSubject.value[index] = profile
} else {