Multi-configuration providers (#756)

This commit is contained in:
Davide 2024-10-25 10:54:28 +02:00 committed by GitHub
parent bbcd245bad
commit 2c2b3f063a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 25 additions and 24 deletions

View File

@ -41,7 +41,7 @@
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source", "location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
"state" : { "state" : {
"revision" : "4fffdbde18ddaa5ab0fdfa9ee417a0f5015f59c6" "revision" : "7b3f68b30d2c3ac434c5aaa10853bd3709c5c308"
} }
}, },
{ {

View File

@ -28,7 +28,7 @@ let package = Package(
], ],
dependencies: [ dependencies: [
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.9.0"), // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.9.0"),
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "4fffdbde18ddaa5ab0fdfa9ee417a0f5015f59c6"), .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "7b3f68b30d2c3ac434c5aaa10853bd3709c5c308"),
// .package(path: "../../../passepartoutkit-source"), // .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", from: "0.9.1"),
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"), // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),

View File

@ -35,3 +35,22 @@ protocol ProviderEntityViewProviding {
onSelect: @escaping (any ProviderEntity & Encodable) async throws -> Void onSelect: @escaping (any ProviderEntity & Encodable) async throws -> Void
) -> EntityContent ) -> EntityContent
} }
extension ProviderEntityViewProviding where Self: ProviderCompatibleModule, EntityType.Configuration: ProviderConfigurationIdentifiable & Codable {
func vpnProviderEntityView(
with provider: ModuleMetadata.Provider,
onSelect: @escaping (any ProviderEntity & Encodable) async throws -> Void
) -> some View {
let selectedEntity = try? provider
.entity
.map {
try providerEntity(from: $0)
} as? VPNEntity<EntityType.Configuration>
return VPNProviderServerCoordinator(
providerId: provider.id,
selectedEntity: selectedEntity,
onSelect: onSelect
)
}
}

View File

@ -49,16 +49,6 @@ extension OpenVPNModule: ProviderEntityViewProviding {
with provider: ModuleMetadata.Provider, with provider: ModuleMetadata.Provider,
onSelect: @escaping (any ProviderEntity & Encodable) async throws -> Void onSelect: @escaping (any ProviderEntity & Encodable) async throws -> Void
) -> some View { ) -> some View {
let selectedEntity: VPNEntity<OpenVPN.Configuration>? = try? provider vpnProviderEntityView(with: provider, onSelect: onSelect)
.entity
.map {
try providerEntity(from: $0)
}
return VPNProviderServerCoordinator(
providerId: provider.id,
selectedEntity: selectedEntity,
onSelect: onSelect
)
} }
} }

View File

@ -133,10 +133,7 @@ private extension ProviderContentModifier {
guard let providerId else { guard let providerId else {
return nil return nil
} }
return providerManager.lastUpdated( return providerManager.lastUpdated(for: providerId)
for: providerId,
configurationType: Entity.Configuration.self
)
} }
var lastUpdatedString: String? { var lastUpdatedString: String? {
@ -171,11 +168,7 @@ private extension ProviderContentModifier {
@discardableResult @discardableResult
func refreshInfrastructure(for providerId: ProviderID) async -> Bool { func refreshInfrastructure(for providerId: ProviderID) async -> Bool {
do { do {
try await providerManager.fetchVPNInfrastructure( try await providerManager.fetchVPNInfrastructure(from: apis, for: providerId)
from: apis,
for: providerId,
ofType: Entity.Configuration.self
)
return true return true
} catch { } catch {
pp_log(.app, .error, "Unable to refresh infrastructure: \(error)") pp_log(.app, .error, "Unable to refresh infrastructure: \(error)")

View File

@ -73,8 +73,7 @@ struct VPNProviderServerView<Configuration>: View where Configuration: ProviderC
do { do {
manager.repository = try await providerManager.vpnRepository( manager.repository = try await providerManager.vpnRepository(
from: apis, from: apis,
for: providerId, for: providerId
configurationType: Configuration.self
) )
if let selectedEntity, filtersWithSelection { if let selectedEntity, filtersWithSelection {
filters = VPNFilters(with: selectedEntity.server.provider) filters = VPNFilters(with: selectedEntity.server.provider)